I am new to Mockito, I am trying to verify the attributes of an object which gets created inside a method.
pseudo code below:
class A{
...
public String methodToTest(){
Parameter params = new Parameter(); //param is basically like a hashmap
params.add("action", "submit");
return process(params);
}
...
public String process(Parameter params){
//do some work based on params
return "done";
}
}
I want to test 2 things:
when I called
methodToTest
,process()
method is calledprocess()
method is called with the correct params containing action"submit"
I was able to verify that process()
is eventually called easily using Mockito.verify()
.
However trying to check that params contains action "submit"
is very difficult so far.
I have tried the following but it doesn't work :(
BaseMatcher<Parameter> paramIsCorrect = new BaseMatcher<Parameter>(){
@Overrides
public boolean matches(Object param){
return ("submit".equals((Parameter)param.get("action")));
}
//@Overrides description but do nothing
}
A mockA = mock(A);
A realA = new A();
realA.methodToTest();
verify(mockA).process(argThat(paramIsCorrect))
Any suggestion ?