I'm using junit and EasyMock to do unit testing on a project I'm working on. However, I've run into a problem. I have a good handful of methods that have a parameter that is an enumeration.
I ran into the java.lang.NullPointerException when attempting to mock the enum, and it seems enums just cannot be mocked. More information I found on it here:
http://download.oracle.com/javase/tutorial/java/javaOO/classvars.html
Is there any good way to unit test this method without mocking the enum??
Thanks!
EDIT: Péter Török was right! I was completely looking over the fact that I could just plug in something for the enum. For example:
public void methodName(String description, Location buildingLocation) {
where Location is my enum, I can call the method as:
methodName("here is my description", Location.DENVER);
What does your enum
contain that you need to mock it? Why can't you just simply use the available values themselves?
Since enum
s are (supposed to be) stateless and immutable, they should be readily available for unit testing, you should have no problems in instantiating them, they should hold no (mutable) global state and should have no external dependencies which make them hard to use in unit tests.
Failing any of the above would be a sign of a design problem to me rather than a unit testing problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With