I came across a situation I don't really know how to solve. I've just created a class Foo that contains a static factory method to create class Bar using some arguments so Foo is kind of a factory class. Now I want to test this method but the problem is, these arguments are modified internally to create the variables needed to call constructor on Bar. As part of the test, I can test I get the final object of Bar but I don't know how to verify the arguments passed to the constructor.
public class Foo {
public Bar createBarOf(String argumentOne, String argumentTwo) {
String argumentForBar = argumentOne + argumentTwo;
return new Bar(argumentForBar);
}
}
Any suggestions?
EDIT
To make the question more clear, this is the Bar class.
public class Bar {
private final String SUFFIX = "BarSuffix";
private String field;
public Bar(String argumentForBar) {
field = argumentForBar + BAR_SUFFIX;
}
}
So, having that constructor in mind. When I test createBarFor(argumentOne,argumentTwo) in Foo, I can't figure out how to test that argumentOne and argumentTwo were used to create Bar unless I also test Bar constructor inside that test and assume what the internals of Bar are. argumentOne and argumentTwo are not stored fields of Bar but rather variables to calculate the value of a field in the object.