org.powermock.core.classloader.annotations.SuppressStaticInitializationFor Java Examples
The following examples show how to use
org.powermock.core.classloader.annotations.SuppressStaticInitializationFor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractXMLRequestCreatorBaseTest.java From powermock-examples-maven with Apache License 2.0 | 6 votes |
/** * 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); }
Example #2
Source File: TestWBFreeMarkerTemplateEngine.java From cms with Apache License 2.0 | 5 votes |
@Test @SuppressStaticInitializationFor("WBFreeMarkerTemplateEngine.class") @PrepareForTest({Environment.class, WPBFreeMarkerTemplateEngine.class}) public void process_ok_no_messages() { try { WPBFreeMarkerTemplateEngine templateEngine = new WPBFreeMarkerTemplateEngine(cacheInstancesMock); Whitebox.setInternalState(templateEngine, "configuration", configurationMock); String nameTemplate = "textXYZ"; Map rootMap = new HashMap(); rootMap.put(WPBModel.LOCALE_LANGUAGE_KEY, "en"); Writer out = new StringWriter(); Template templateMock = PowerMock.createMock(Template.class); EasyMock.expect(configurationMock.getTemplate(nameTemplate)).andReturn(templateMock); Locale locale = new Locale("en"); CmsResourceBundle resourceBundleMock = PowerMock.createMock(CmsResourceBundle.class); EasyMock.expect(freeMarkerFactoryMock.createResourceBundle(EasyMock.anyObject(WPBMessagesCache.class), EasyMock.anyObject(Locale.class))).andReturn(resourceBundleMock); Environment envMock = PowerMock.createMock(Environment.class); EasyMock.expect(templateMock.createProcessingEnvironment(rootMap, out)).andReturn(envMock); envMock.process(); Whitebox.setInternalState(templateEngine, "wbFreeMarkerFactory", freeMarkerFactoryMock); PowerMock.replay(cloudFileStorageMock, envMock, templateMock, resourceBundleMock, cacheFactoryMock, freeMarkerFactoryMock, configurationMock, templateLoaderMock, moduleDirectiveMock, messageCacheMock); templateEngine.process(nameTemplate, rootMap, out); PowerMock.verify(cloudFileStorageMock, envMock, templateMock, resourceBundleMock, cacheFactoryMock, freeMarkerFactoryMock, configurationMock, templateLoaderMock, moduleDirectiveMock, messageCacheMock); assertTrue (rootMap.containsKey(WPBModel.LOCALE_MESSAGES)); } catch (Exception e) { assertTrue (false); } }
Example #3
Source File: TestWBFreeMarkerTemplateEngine.java From cms with Apache License 2.0 | 5 votes |
@Test @SuppressStaticInitializationFor("WBFreeMarkerTemplateEngine.class") @PrepareForTest({Environment.class, WPBFreeMarkerTemplateEngine.class}) public void process_ok_with_messages() { try { WPBFreeMarkerTemplateEngine templateEngine = new WPBFreeMarkerTemplateEngine(cacheInstancesMock); Whitebox.setInternalState(templateEngine, "configuration", configurationMock); String nameTemplate = "textXYZ"; Map rootMap = new HashMap(); rootMap.put(WPBModel.LOCALE_LANGUAGE_KEY, "en"); rootMap.put(WPBModel.LOCALE_MESSAGES, new Object()); Writer out = new StringWriter(); Template templateMock = PowerMock.createMock(Template.class); EasyMock.expect(configurationMock.getTemplate(nameTemplate)).andReturn(templateMock); Environment envMock = PowerMock.createMock(Environment.class); EasyMock.expect(templateMock.createProcessingEnvironment(rootMap, out)).andReturn(envMock); envMock.process(); Whitebox.setInternalState(templateEngine, "wbFreeMarkerFactory", freeMarkerFactoryMock); PowerMock.replay(cloudFileStorageMock, envMock, templateMock, cacheFactoryMock, freeMarkerFactoryMock, configurationMock, templateLoaderMock, moduleDirectiveMock, messageCacheMock); templateEngine.process(nameTemplate, rootMap, out); PowerMock.verify(cloudFileStorageMock, envMock, templateMock, cacheFactoryMock, freeMarkerFactoryMock, configurationMock, templateLoaderMock, moduleDirectiveMock, messageCacheMock); assertTrue (rootMap.containsKey(WPBModel.LOCALE_MESSAGES)); } catch (Exception e) { assertTrue (false); } }
Example #4
Source File: TestWBFreeMarkerTemplateEngine.java From cms with Apache License 2.0 | 4 votes |
@Test @SuppressStaticInitializationFor("WBFreeMarkerTemplateEngine.class") @PrepareForTest({Environment.class, WPBFreeMarkerTemplateEngine.class}) public void test_initialize() { WPBFreeMarkerTemplateEngine templateEngine = new WPBFreeMarkerTemplateEngine(cacheInstancesMock); EasyMock.expect(freeMarkerFactoryMock.createConfiguration()).andReturn(configurationMock); EasyMock.expect(freeMarkerFactoryMock.createWBFreeMarkerModuleDirective()).andReturn(moduleDirectiveMock); EasyMock.expect(freeMarkerFactoryMock.createWBFreeMarkerTemplateLoader(cacheInstancesMock)).andReturn(templateLoaderMock); EasyMock.expect(freeMarkerFactoryMock.createWBFreeMarkerImageDirective()).andReturn(imageDirectiveMock); EasyMock.expect(freeMarkerFactoryMock.createWBFreeMarkerArticleDirective()).andReturn(articleDirectiveMock); EasyMock.expect(freeMarkerFactoryMock.createFreeMarkerUriDirective()).andReturn(uriDirectiveMock); configurationMock.setLocalizedLookup(false); configurationMock.setTemplateLoader(templateLoaderMock); moduleDirectiveMock.initialize(templateEngine, cacheInstancesMock); imageDirectiveMock.initialize(cloudStorageMock, cacheInstancesMock); configurationMock.setSharedVariable(WPBModel.MODULE_DIRECTIVE, moduleDirectiveMock); configurationMock.setSharedVariable(WPBModel.IMAGE_DIRECTIVE, imageDirectiveMock); configurationMock.setSharedVariable(WPBModel.ARTICLE_DIRECTIVE, articleDirectiveMock); configurationMock.setSharedVariable(WPBModel.URI_DIRECTIVE, uriDirectiveMock); Capture<String> captureDefaultEncoding = new Capture<String>(); Capture<String> captureOutputEncoding = new Capture<String>(); configurationMock.setDefaultEncoding(EasyMock.capture(captureDefaultEncoding)); configurationMock.setOutputEncoding(EasyMock.capture(captureOutputEncoding)); Whitebox.setInternalState(templateEngine, "wbFreeMarkerFactory", freeMarkerFactoryMock); PowerMock.replay(cloudFileStorageMock, cacheFactoryMock, freeMarkerFactoryMock, configurationMock, templateLoaderMock, moduleDirectiveMock, messageCacheMock); try { templateEngine.initialize(); PowerMock.verify(cloudFileStorageMock, cacheFactoryMock, freeMarkerFactoryMock, configurationMock, templateLoaderMock, moduleDirectiveMock, messageCacheMock); assertTrue (captureDefaultEncoding.getValue().equals("UTF-8")); assertTrue (captureOutputEncoding.getValue().equals("UTF-8")); } catch (Exception e) { assertTrue (false); } }