public enum AnEnumExample { NOT_WORKING { @Override public String testViolatingMethod() { WithNewPreparedClass anObj = new WithNewPreparedClass(); return anObj.getValue(); } };
public abstract String testViolatingMethod(); public static String nonViolatingMethod() { WithNewPreparedClass anObj = new WithNewPreparedClass(); return anObj.getValue(); }}
@Test@PrepareForTest(AnEnumExample.class)public class AnEnumExampleTestCase extends PowerMockTestCase {
@BeforeMethod public void setup() throws Exception { WithNewPreparedClass mockObj = mock(WithNewPreparedClass.class); when(mockObj.getValue()).thenReturn("mockAnswer"); PowerMockito.whenNew(WithNewPreparedClass.class).withNoArguments().thenReturn(mockObj); }
public void shouldReturnMockAnswerOnStaticMethod() { //This is successful assertEquals(AnEnumExample.nonViolatingMethod(), "mockAnswer"); }
public void shouldReturnMockAnswerOnEnumMethod() { //This is not successful assertEquals(AnEnumExample.NOT_WORKING.testViolatingMethod(), "mockAnswer"); }}
--
You received this message because you are subscribed to the Google Groups "PowerMock" group.
To unsubscribe from this group and stop receiving emails from it, send an email to powermock+...@googlegroups.com.
To post to this group, send email to powe...@googlegroups.com.
Visit this group at http://groups.google.com/group/powermock.
For more options, visit https://groups.google.com/d/optout.