private void ConvertString(ABC object)
{
String head = "";
String tail="string_tail";
if(!tail.isEmpty())
{
String converter = new StringConvert();
head = converter.convert(tail, TYPE1);
setHeadToTail(head,object);
}
}
private void setHeadToTail(String head, ABC object)
{
List<Mixture> values=object.getValues();
if (values!=null)
{
for (Mixture Values1 : values)
{
if (Values1 instanceof NumMixture)
{
((NumMixture) Values1 ).setTail(head);
}
}
}
}
I want to write unit test for ConvertString
method to check weather the value 'head' converted is equal to the value 'head' being passed in setHeadToTail()
.
Can anyone help in this?
@Test
public void test_ConvertedValue() throws Exception {
ABC obj1=methodToSetSomeValues();
Method method=Project.class.getDeclaredMethod("ConvertString", ABC.class);
method.setAccessible(true);
method.invoke(new Project(), obj1);
String expectedVal= "1234";
ArgumentCaptor<String> argumentCaptor=ArgumentCaptor.forClass(String.class);
verifyPrivate(new Project()).invoke("setHeadToTail", argumentCaptor.capture(), obj1);
assertEquals(expectedVal,argumentCaptor.getValue());
}
In this test case I want to check the value of 'head' converted is equal to parameter passed in setHeadToTail()
i.e. head but this is not working.