using Powermock annotations via interface or annotation type

108 views
Skip to first unread message

Ceyhan Kasap

unread,
Feb 5, 2020, 8:03:47 AM2/5/20
to PowerMock
Hi Team,

We are trying to use Powermock and for starters we feel that it is a very good unit test tool for static method testing.

We could not figure out how to use  Powermock annotations in interface or annotation types. 

When we use them in an abstract class and make our test class extend it works

@RunWith(PowerMockRunner.class)
@PrepareForTest({ Dummy.class })
@PowerMockIgnore({ "javax.management.*", "com.mycompany.excludepackage.*" })
public abstract class BaseTestClass {




}



However defining them in an interface as follows and make the test class implement that interface does not work :


@RunWith(PowerMockRunner.class)
@PrepareForTest({ Dummy.class })
@PowerMockIgnore({ "javax.management.*", "com.mycompany.excludepackage.*" })
public interface ITestClass {


 
}


Implementing a custom annotation as follows and annotate the test class with that annotation does not help either :  


@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@RunWith(PowerMockRunner.class)
@PrepareForTest({ Dummy.class })
@PowerMockIgnore({ "javax.management.*", "com.mycompany.excludepackage.*" })
public @interface TestClassAnnotation {


}




For both cases we are having ClassNotPreparedException

org.powermock.api.mockito.ClassNotPreparedException:


[Ljava.lang.Object;@43bc63a3
The class xxx not prepared for test.


 at org
.powermock.api.mockito.expectation.reporter.MockitoPowerMockReporter.classNotPrepared(MockitoPowerMockReporter.java:29)
 at org
.powermock.api.mockito.internal.mockcreation.MockTypeValidatorFactory$DefaultMockTypeValidator.validate(MockTypeValidatorFactory.java:37)
 at org
.powermock.api.mockito.internal.mockcreation.AbstractMockCreator.validateType(AbstractMockCreator.java:10)
 at org
.powermock.api.mockito.internal.mockcreation.DefaultMockCreator.createMock(DefaultMockCreator.java:49)
 at org
.powermock.api.mockito.internal.mockcreation.DefaultMockCreator.mock(DefaultMockCreator.java:40)
 at org
.powermock.api.mockito.PowerMockito.mockStatic(PowerMockito.java:62)

So is there any way we can make use of the annotations other than extending a class. Extending a class will be too restrictive for us because we will need to ignore different packages for same test class.

We are searching a way to achieve this by composition not by inheritance.

Any other recommendation for applying multiple annotations by composition would also help

Thanks in advance
 
Reply all
Reply to author
Forward
0 new messages