Java 类org.powermock.core.classloader.annotations.SuppressStaticInitializationFor 实例源码

项目:powermock-examples-maven    文件:AbstractXMLRequestCreatorBaseTest.java   
/**
 * Test convert document to byte array.
 * 
 * @throws Exception
 *             If something unexpected goes wrong.
 */
@Test
@PrepareForTest
@SuppressStaticInitializationFor
public void testConvertDocumentToByteArray() throws Exception {
    // Create a fake document.
    Document document = DocumentHelper.createDocument();
    Element root = document.addElement("ListExecutionContexts");
    root.addAttribute("id", "2");
    replayAll();
    // Perform the test
    final byte[] array = tested.convertDocumentToByteArray(document);
    verifyAll();
    assertNotNull(array);
    assertEquals(70, array.length);
}
项目:powermock    文件:AbstractXMLRequestCreatorBaseTest.java   
/**
 * Test convert document to byte array.
 * 
 * @throws Exception
 *             If something unexpected goes wrong.
 */
@Test
@PrepareForTest
@SuppressStaticInitializationFor
public void testConvertDocumentToByteArray() throws Exception {
    // Create a fake document.
    Document document = DocumentHelper.createDocument();
    Element root = document.addElement("ListExecutionContexts");
    root.addAttribute("id", "2");
    replayAll();
    // Perform the test
    final byte[] array = tested.convertDocumentToByteArray(document);
    verifyAll();
    assertNotNull(array);
    assertEquals(70, array.length);
}
项目:powermock    文件:StaticConstructorSuppressExtractorImpl.java   
/**
 * {@inheritDoc}
 */
@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[0]);
}
项目:powermock    文件:PowerMockObjectFactory.java   
private boolean anyMethodInClassHasPowerMockAnnotation(Class<?> testClass) {
    final Method[] methods = testClass.getMethods();
    for (Method method : methods) {
        if(method.isAnnotationPresent(PrepareForTest.class) || method.isAnnotationPresent(SuppressStaticInitializationFor.class)) {
            return true;
        }
    }
    return false;
}
项目:powermock    文件:ChunkingAndStaticInitializerRemovalTest.java   
@SuppressStaticInitializationFor("samples.staticinitializer.SimpleStaticInitializerExample")
@Test
public void testMockingWithChunking() throws Exception {
    final String argument = "hello";
    assertNull(tested.getString());
    assertNull(tested.getConcatenatedString(argument));

    verify(tested).getConcatenatedString(argument);
}
项目:powermock    文件:PowerMockObjectFactory.java   
private boolean isClassAnnotatedWithPowerMockAnnotation(Class<?> testClass) {
    return testClass.isAnnotationPresent(PrepareForTest.class) || testClass.isAnnotationPresent(SuppressStaticInitializationFor.class);
}
项目:powermock    文件:EvilStaticInitializerExampleTest.java   
@Test
@SuppressStaticInitializationFor("samples.staticinitializer.EvilStaticInitializerExample")
public void assertNativeCodeInvocationWorks() throws Exception {
    EvilStaticInitializerExample tested = new EvilStaticInitializerExample();
    assertThat(tested.doSomeNativeStuffUsingTheLoadedSystemLibrary(), instanceOf(String.class));
}