I have an abstract class Foo that contains a public method abc() and a private method xyz() used in abc() that generates a random string. What abc() returns depends on the return value of xyz().
I also have a subclass Bar that extends Foo.
I would like to test Bar using abc(). However, since I don't know the result of xyz(), I don't know what abc() will return.
The code looks something like this:
public abstract class Foo {
public String abc() {
*xyz() called here*
}
private String xyz() {
*Generates a random string*
}
}
public class Bar extends Foo {
}
I tried stubbing or mocking but it doesn't work. I presume that the design of Foo should be changed but am not sure how. I use Spock. Any advice?