Expect in Easymock calls the method actually, why is it so? - junit

System.out.println("Check1");
expect(mockobject.function(parameters)).andReturn("hello";
System.out.println("check2***************************");
replay(mockobject);
While executing the test, the mockobject.function(parameters) executes and call goes to the method.Debugging using the system out, it checks inside the function is also displayed in console.
Why is it so? The expect() doesn't allow the call to be made to the desired function?

Assuming mockobject is a mock created with mock() or createMock() and not partialMockBuilder(), this can't happen unless function is final.

Related

Google Apps Script order of execution: why do functions get invoked merely by being defined?

In Javascript, the following code will execute only once, but in Google Apps Script it executes twice (obviously the body and script tags would be omitted):
<body>
<script>
hi();
function hi() {
alert('hi')
}
</script>
</body>
In other words, in GoogleApps script merely defining a function invokes it. The following in Code.gs executes with undefined arguments passed to it.
function createQuery(keywords, dateRange) {
}
How can I define functions without them being called? Pointers to the docs would be helpful. I have scoured them without success.
In GAS, you save and test functions using the toolbar at the top. By virtue of telling the function to run using the toolbar, you are calling the function. Any triggers that you have will also call it to run without 'calling' inside the code.
You can more minutely determine how and when a function runs by calling it later in the code. This can be done in nested functions or inside of other functions. Regardless of where you are defining the function, eventually you will have to either create a trigger or use the toolbar to run the function.
I'm not sure how you are experiencing a double call seeing as your reference code is not very in-depth. Keep in mind that to execute the script at all, you would have had to either set a trigger or run it yourself in which you are adding in an execution. If you execute code that tells itself to execute that same code, you would incur an infinite loop.
Users will be able to more accurately understand your question and issue and thus answer them should you provide more data and references. You may also want to read the references and guides on the basics of GAS and its use of Javascript.

Achieve Do after and before using ES6 Proxy

I've a View and Utility classes and wanted to hook-in the Utility method once View's job is done. So wanted to call the utility method (to add behavior to the view) once View's render call is done.
Using ES6 Proxy API, Is there a way to execute a method before / after executing the main method ? (aka method interceptions)
Similar to YUI3 Do API.
http://yuilibrary.com/yui/docs/api/classes/Do.html
Yes there is a way. Actually I'm trying to build the same thing and as long as you use a synchronous context I already got it working. Have a look at the code examples in the issue I created for my problem: stack overflow when returning an ES6 proxy through a promise
What you need to do to intercept the call is to use the ES6 proxy to get notified of the get-call that takes place to retrieve the function before the method is actually called.
In my example you can see that you get all the information about the call like what method was called with which parameters and also who called it and on which target it was originally called.

Elixir check if a function has been called from a ExUnit test?

Is there a way to check if a function has been called from a ExUnit test case? I have a function that calls IO.puts and I would like to test and verify that something is being outputted to STDOUT via a test case.
I saw this: http://erlang.org/pipermail/erlang-questions/2005-July/016259.html. But I was hoping there might be a simpler way of doing this with ExUnit.
Is there a way to check and see if my function calls IO.puts? Or at least check and see if something has been sent to STDOUT?
If you just want to test the STDOUT via a test case, I think CaptureIO can be used.
The following has the spec and sample code.
https://hexdocs.pm/ex_unit/master/ExUnit.CaptureIO.html
You could mock the method calls using some mocking libraries, but for STDOUT, the above one would be simpler approach.
https://github.com/jjh42/mock
https://github.com/josephwilk/amrita

How to wait for MySQL To Update in VB.NET?

I have been working on something that checks an MySQL Database to check something - however the program stops responding because it is constantly checking the database. Is it possible to have it wait a few seconds to recheck the database? I have tried sleep() but it is giving a strange error:
A call to PInvoke function
'Game!WindowsApplication1.Form1::Sleep' has unbalanced the
stack. This is likely because the managed PInvoke signature
does not match the
unmanaged target signature. Check that the calling convention
and parameters of the
PInvoke signature match the target unmanaged signature.
I have been looking into this for quite a while and i am in a predicament. I do need the MySQL databases to be checked very often. I tried making a web browser refresh before checking it again - but it started to lag the application.
Code:
function updateit()
' SQL Code goes here, it succeeds.
updateit() ' Update it again.
return true
end
updateit()
Your code example shows a recursive function with no base case. The result of that is always a stack overflow (an uncatchable exception in .Net).
Don't call your updateit() function from within the function itself. Instead, just write a loop to call it over and over.
Try doing your checks from a separate thread. Try dragging a BackgroundWorker onto your form and putting your check in that to make your program more responsive. I've never seen that error before though. Is it System.Threading.Thread.Sleep() or something specific to VB?
Looking at your code it looks like you've got infinite recursion. That will cause a stackoverflow... try
while(true)
'SQL code
end

Difference between Callback function and normal function

i have googled a lot to find out the difference between normal function and callback function. Unfortunatley I could not understand. if we have to call a function inside another function, what is usefulness of passing it as a parameter to the function by using function pointers?
Is it possible to call the function passed as a parameter in the form of function pointers somewhere outside the function, in which it is passed as parameter? if yes, please give me a rough idea of its implementation.
Thanks
Say you have a function that does some prolonged operation, like send email. You don't want to wait for it to finish, so you give it a callback function that will invoke once it's done. That's a major use of callbacks - notification of asynchronous operations. There are other uses.