Java 11, New to TDD and to unit testing in general. I have a class that contains a unique method : buy() It does a few thing like search for the product in the productRepo, prepare the receipt. It finally returns an object (receipt).
public Receipt buy(){
// find product
// create the receipt
return receipt;
}
NOTE : I omitted the parameters because they are not important to the problem
Now I have to do the unit tests for that method. I have a few problems : I would normally run a test and compare the expectedReceipt with the one obtained from the call. However :
- the Receipt class has no getters (only a constructor)
- theReceipt class doesnt override the equals method and doesnt only have simple attributes (double, string ,etc)
- I cant include any new dependency to my project, I got : mockito and junit.
- The method buy() has to absolutely return an instance of Receipt.
So I have no way of testing for equality. What can I do ? Heres what I tried :
- I verified that some method was called from my mock (productRepository).
- I tried extending that Receipt class and implement myself an equals method. However, the generic equals method from the Object class seems to be called in my tests.
Any ideas or hints ? Thank you