I have an enum class:-
public enum Action {
LOGGED_IN("logged_in"),
LOGGED_OUT("logged_out"),
private final String action;
/**
* @param action
*/
private Action(String action) {
this.action = action;
}
/**Fetches the action.
* @return String action
*/
public String getAction() {
return this.action;
}
}
I am writing the below Junit to mock this enum class so that i can add another enum value to this Action for junit testing.
@RunWith(PowerMockRunner.class)
public class TestClass{
public Action action;
@Test
@PrepareForTest(Action.class)
public void testgetFeatureIdNull() NoSuchFieldException, SecurityException {
Action dummy = PowerMockito.mock(Action.class);
Field value=Action.class.getDeclaredField("value");
value.setAccessible(true);
Whitebox.setInternalState(dummy, "value", "dummy");
Whitebox.setInternalState(dummy,"ordinal", 2);
request = "{" + " opportunityNumber: 45," + " id: 1," + " " + " s: {" + " id: 23"
+ " }" + "}";
action = Action.LOGGED_IN;
assertEquals(null, PatternGenertor.getFeatureid(dummy, request));
}
When running this code i am getting the below error:-
java.lang.NoSuchFieldException: value
at java.lang.Class.getDeclaredField(Unknown Source)
Can anyone please tell me where am i doing wrong?