How can I mock an instance of an enum class with PowerMock & Mockito?

前端 未结 3 467
无人及你
无人及你 2021-01-12 07:45

I tried to follow the example offered in the answer to this very similar question, but it does not work for me. I get the following error message:

java.lang.         


        
3条回答
  •  粉色の甜心
    2021-01-12 08:12

    Hi guys, to me worked as below:

    First add power mockito on pom.xml:

    
        org.powermock
        powermock-module-junit4
        2.0.4
        test
    
    

    and then on my class:

    @RunWith(PowerMockRunner.class)
    @PrepareForTest({EnumClass.class})
    public class EnumClassTest{
        private EnumClassTest enumClassTest;
        
        @Before
        public void setUp() {
            enumClassTest = mock(EnumClassTest.class);
        }
        
        @Test
        public void someMethod() {
            //My code test here
        }  
    

提交回复
热议问题