Copy Code code as follows:
Mockery.checking (new Expectations () {
{
One (new Object ()). ToString ();
Would (ReturnValue (""));
}
});
Here's an example of writing a simple class demo
Copy Code code as follows:
public class Test {
int i = 1;
{
int j = 1;
System.out.println (j);
}
Public Test () {
i = 2;
}
static{
}
}
Previously used static{} code quickly, you can directly write {} code block
By analyzing Java bytecode, you find that the code is executed in the following order:
1 First executes the constructor method of the object, creates an empty object, and then assigns the default value to the object's field I. Which is to execute i = 0 first (this one should be atomic)
2 then the field is assigned, in our case, there is only one field I, so execute i = 1, this is the field initialization process
4 the {} statement block of the class is executed after the initialization of the field, and if there are more than one {} statement block, executed sequentially in the order of the Code
3 {} The execution of the constructor method i = 2 after execution of the statement is completed