Say I have the following code:
public class ClassToTest
{
AnotherClass anotherClass;
public void methodToTest( int x, int y )
{
int z = x + y
anotherClass.receiveSomething( z );
}
}
public class AnotherClass
{
public void receiveSomething( int z ) {.. do something.. }
}
I want to make assertion on the value of the variable z. How do I do this without refactoring? Variables x, y, and z could be some other Java class types, and I just used “int” for simplicity.
You can write the following. Of course dependency injection and test method might change depending on your current implementation and/or your test scenarios.
Written with Mockito 1.9.5-rc1 in mind.
Also instead of using the
eqmatcher you can instead use anArgumentCaptor, which will capture values or value references (in case of objects). You’ll be able to perform additional assertions on the captured value(s). For example using Truth or FEST-Assert.This could look like :
Cheers,