How is the unit test method with enumeration parameters?

I use junit and EasyMock to unit test the project I'm working on. However, I ran into a problem. I have a good handful of methods that have a parameter that is an enumeration.

I came across java.lang.NullPointerException while trying to mock an enumeration, and it seems that the enumerations simply cannot be taunted. More information I found here:

http://download.oracle.com/javase/tutorial/java/javaOO/classvars.html

Is there any good way to unit test this method without bullying enum ??

Thanks!

EDITOR: Peter Torek was right! I thoroughly studied the fact that I could just plug in something for listing. For instance:

public void methodName (string description, Location buildingLocation) {

where Location is my listing, I can call the method like:

methodName ("here is my description", Location.DENVER);

+4
source share
1 answer

What does your enum contain, that you need to mock it? Why can't you just use the available values?

Since enum (presumably) static and immutable, they should be easily accessible for unit testing, you should not have problems creating them, they should not have a (mutable) global state, and they should not have external dependencies that make them difficult to use in modular tests.

Failure to comply with any of the above events would be a sign of a design problem for me, and not a unit testing problem.

+13
source

Source: https://habr.com/ru/post/1347720/


All Articles