The usual approach here is to make sure type
is the desired value. To do that you would need to change determineTriangleType
to return the required type.
This is where mock objects come in. The idea is to extend the Java class under test and override determineTriangleType
to return the right value unconditionally in your derived implementation. Then you call the method you want to test on a instance of the derived class, and now the method's if statement will execute.
public class DerivedToCheckIf extends BaseClass {
@Override
public String determineTriangleType(String side1, String side2, String side3) {
// call to super implementation may not be required
// if the method does not change object state which affects the method under test
super.determineTriangleType(side1, side2, side3);
return "Equilateral";
}
}