Search in sources :

Example 1 with SuppressStaticInitializationFor

use of org.powermock.core.classloader.annotations.SuppressStaticInitializationFor in project powermock by powermock.

the class StaticConstructorSuppressExtractorImpl method getClassesToModify.

@Override
public String[] getClassesToModify(AnnotatedElement element) {
    List<String> all = new LinkedList<String>();
    final SuppressStaticInitializationFor suppressAnnotation = element.getAnnotation(SuppressStaticInitializationFor.class);
    if (suppressAnnotation == null) {
        return null;
    } else {
        final String[] value = suppressAnnotation.value();
        for (String classToSuppress : value) {
            if (!"".equals(classToSuppress)) {
                all.add(classToSuppress);
                MockRepository.addSuppressStaticInitializer(classToSuppress);
            }
        }
    }
    return all.toArray(new String[all.size()]);
}
Also used : SuppressStaticInitializationFor(org.powermock.core.classloader.annotations.SuppressStaticInitializationFor) LinkedList(java.util.LinkedList)

Example 2 with SuppressStaticInitializationFor

use of org.powermock.core.classloader.annotations.SuppressStaticInitializationFor in project powermock by powermock.

the class EvilStaticInitializerExampleTest method assertNativeCodeInvocationWorks.

@Test
@SuppressStaticInitializationFor("samples.staticinitializer.EvilStaticInitializerExample")
public void assertNativeCodeInvocationWorks() {
    EvilStaticInitializerExample tested = new EvilStaticInitializerExample();
    assertThat(tested.doSomeNativeStuffUsingTheLoadedSystemLibrary(), instanceOf(String.class));
}
Also used : EvilStaticInitializerExample(samples.staticinitializer.EvilStaticInitializerExample) Test(org.junit.Test) SuppressStaticInitializationFor(org.powermock.core.classloader.annotations.SuppressStaticInitializationFor)

Aggregations

SuppressStaticInitializationFor (org.powermock.core.classloader.annotations.SuppressStaticInitializationFor)2 LinkedList (java.util.LinkedList)1 Test (org.junit.Test)1 EvilStaticInitializerExample (samples.staticinitializer.EvilStaticInitializerExample)1