Skip to content

Instantly share code, notes, and snippets.

Created October 21, 2013 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/cb7fa1592c270159f516 to your computer and use it in GitHub Desktop.
Save anonymous/cb7fa1592c270159f516 to your computer and use it in GitHub Desktop.
public class HasPropertyOfCertainValueMatcherTest {
private InnerClassToBeTested instance;
@Test
public void test(){
instance = mock(InnerClassToBeTested.class);
InternalClassContainingProp classWithProp = new InternalClassContainingProp("somePropValue", null);
instance.callMethodRequiringSomeClassWithSomeProp(classWithProp);
// test that the first property of our class was called with an argument that has its properties set accordingly
verify(instance,times(1)).callMethodRequiringSomeClassWithSomeProp(hasPropertyOfCertainValue("someProp", "somePropValue", InternalClassContainingProp.class));
}
@Test
public void test2(){
instance = mock(InnerClassToBeTested.class);
InternalClassContainingProp classWithProp = new InternalClassContainingProp("somePropValue", null);
instance.callMethodRequiringSomeClassWithSomeProp(classWithProp);
// test that the first property of our class was called with an argument that has its properties set accordingly
verify(instance,never()).callMethodRequiringSomeClassWithSomeProp(hasPropertyOfCertainValue("someProp", "someOther", InternalClassContainingProp.class));
}
@Test
public void test3(){
instance = mock(InnerClassToBeTested.class);
InternalClassContainingProp classWithProp = new InternalClassContainingProp("somePropValue", new Point(5,6));
instance.callMethodRequiringSomeClassWithSomeProp(classWithProp);
// test that the first property of our class was called with an argument that has its properties set accordingly
verify(instance,times(1)).callMethodRequiringSomeClassWithSomeProp(hasPropertyOfCertainValue("someProp", "somePropValue", InternalClassContainingProp.class));
verify(instance,times(1)).callMethodRequiringSomeClassWithSomeProp(hasPropertyOfCertainValue("someOtherProp", new Point(5,6), InternalClassContainingProp.class));
}
// a simple class that has a method containing a single argument. We want to check if that argument had the appropriate properties set at moment of calling
class InnerClassToBeTested {
public void callMethodRequiringSomeClassWithSomeProp(InternalClassContainingProp classWithProp) {
}
}// a class that would be used as an argument of the InnerClassToBeTested. This class has two properites, for which it can be tested
class InternalClassContainingProp {
private String someProp;
private Point someOtherProp;
public InternalClassContainingProp(String someProp, Point someOtherProp){
this.someProp = someProp;
this.someOtherProp = someOtherProp;
}
public Point getSomeOtherProp() {
return someOtherProp;
}
public String getSomeProp() {
return someProp;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment