/** * 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); }
/** * {@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]); }
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; }
@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); }
private boolean isClassAnnotatedWithPowerMockAnnotation(Class<?> testClass) { return testClass.isAnnotationPresent(PrepareForTest.class) || testClass.isAnnotationPresent(SuppressStaticInitializationFor.class); }
@Test @SuppressStaticInitializationFor("samples.staticinitializer.EvilStaticInitializerExample") public void assertNativeCodeInvocationWorks() throws Exception { EvilStaticInitializerExample tested = new EvilStaticInitializerExample(); assertThat(tested.doSomeNativeStuffUsingTheLoadedSystemLibrary(), instanceOf(String.class)); }