Java Code Examples for org.powermock.api.easymock.PowerMock#verify()
The following examples show how to use
org.powermock.api.easymock.PowerMock#verify() .
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: StaticWithJdomTest.java From powermock-examples-maven with Apache License 2.0 | 6 votes |
@org.junit.Test public void test() throws Exception { PowerMock.mockStatic(StaticClass.class); EasyMock.expect(StaticClass.staticMethod()).andReturn(2).anyTimes(); PowerMock.replay(StaticClass.class); int i = StaticClass.staticMethod(); String xml = "<xml>" + i + "</xml>"; SAXBuilder b = new SAXBuilder(); Document d = b.build(new StringReader(xml)); Assert.assertTrue(d.getRootElement().getText().equals("2")); PowerMock.verify(StaticClass.class); }
Example 2
Source File: TestWBFreeMarkerTemplateLoader.java From cms with Apache License 2.0 | 6 votes |
@Test public void test_findTemplateSource_wrongNameFormat() { try { String templatePage = "random test"; PowerMock.replay(wbUriCacheMock, wbWebPageCacheMock, wbWebPageModuleCacheMock, wbParameterCacheMock, wbImageCacheMock, wbArticleCacheMock, wbMessageCacheMock, wbProjectCacheMock); FreeMarkerTemplateLoader templateLoader = new FreeMarkerTemplateLoader(cacheInstances); FreeMarkerTemplateObject object = (FreeMarkerTemplateObject) templateLoader.findTemplateSource(templatePage); PowerMock.verify(wbUriCacheMock, wbWebPageCacheMock, wbWebPageModuleCacheMock, wbParameterCacheMock, wbImageCacheMock, wbArticleCacheMock, wbMessageCacheMock, wbProjectCacheMock); assertTrue(object == null); } catch (Exception e) { assertTrue(false); } }
Example 3
Source File: TestWBFreeMarkerTemplateLoader.java From cms with Apache License 2.0 | 6 votes |
@Test public void test_findTemplateSource_module_exceptionGetFromCache() { try { String templatePage = WPBTemplateEngine.WEBMODULES_PATH_PREFIX + "test"; EasyMock.expect(wbWebPageModuleCacheMock.getByExternalKey("test")).andThrow(new WPBIOException("")); PowerMock.replay(wbUriCacheMock, wbWebPageCacheMock, wbWebPageModuleCacheMock, wbParameterCacheMock, wbImageCacheMock, wbArticleCacheMock, wbMessageCacheMock, wbProjectCacheMock); FreeMarkerTemplateLoader templateLoader = new FreeMarkerTemplateLoader(cacheInstances); FreeMarkerTemplateObject object = (FreeMarkerTemplateObject) templateLoader.findTemplateSource(templatePage); PowerMock.verify(wbUriCacheMock, wbWebPageCacheMock, wbWebPageModuleCacheMock, wbParameterCacheMock, wbImageCacheMock, wbArticleCacheMock, wbMessageCacheMock, wbProjectCacheMock); assertTrue(object == null); } catch (Exception e) { assertTrue(false); } }
Example 4
Source File: TestWBFreeMarkerTemplateLoader.java From cms with Apache License 2.0 | 6 votes |
@Test public void test_findTemplateSource_module_ok() { try { String templatePage = WPBTemplateEngine.WEBMODULES_PATH_PREFIX + "test"; WPBPageModule webPageModuleMock = PowerMock.createMock(WPBPageModule.class); Date date = new Date(); EasyMock.expect(webPageModuleMock.getLastModified()).andReturn(date); EasyMock.expect(wbWebPageModuleCacheMock.getByExternalKey("test")).andReturn(webPageModuleMock); PowerMock.replay(wbUriCacheMock, wbWebPageCacheMock, wbWebPageModuleCacheMock, wbParameterCacheMock, wbImageCacheMock, wbArticleCacheMock, wbMessageCacheMock, wbProjectCacheMock, webPageModuleMock); FreeMarkerTemplateLoader templateLoader = new FreeMarkerTemplateLoader(cacheInstances); FreeMarkerTemplateObject object = (FreeMarkerTemplateObject) templateLoader.findTemplateSource(templatePage); PowerMock.verify(wbUriCacheMock, wbWebPageCacheMock, wbWebPageModuleCacheMock, wbParameterCacheMock, wbImageCacheMock, wbArticleCacheMock, wbMessageCacheMock, wbProjectCacheMock, webPageModuleMock); assertTrue(object.getExternalKey().equals("test")); assertTrue(object.getType() == TemplateType.TEMPLATE_MODULE); assertTrue(object.getLastModified() == date.getTime()); } catch (Exception e) { assertTrue(false); } }
Example 5
Source File: TestWBFreeMarkerTemplateLoader.java From cms with Apache License 2.0 | 6 votes |
@Test public void test_findTemplateSource_page_exceptionGetFromCache() { try { String templatePage = WPBTemplateEngine.WEBPAGES_PATH_PREFIX + "test"; EasyMock.expect(wbWebPageCacheMock.getByExternalKey("test")).andThrow(new WPBIOException("")); PowerMock.replay(wbUriCacheMock, wbWebPageCacheMock, wbWebPageModuleCacheMock, wbParameterCacheMock, wbImageCacheMock, wbArticleCacheMock, wbMessageCacheMock, wbProjectCacheMock); FreeMarkerTemplateLoader templateLoader = new FreeMarkerTemplateLoader(cacheInstances); FreeMarkerTemplateObject object = (FreeMarkerTemplateObject) templateLoader.findTemplateSource(templatePage); PowerMock.verify(wbUriCacheMock, wbWebPageCacheMock, wbWebPageModuleCacheMock, wbParameterCacheMock, wbImageCacheMock, wbArticleCacheMock, wbMessageCacheMock, wbProjectCacheMock); assertTrue(object == null); } catch (Exception e) { assertTrue(false); } }
Example 6
Source File: TestWBFreeMarkerTemplateLoader.java From cms with Apache License 2.0 | 6 votes |
@Test public void test_findTemplateSource_page_notfound() { try { String templatePage = WPBTemplateEngine.WEBPAGES_PATH_PREFIX + "test"; EasyMock.expect(wbWebPageCacheMock.getByExternalKey("test")).andReturn(null); PowerMock.replay(wbUriCacheMock, wbWebPageCacheMock, wbWebPageModuleCacheMock, wbParameterCacheMock, wbImageCacheMock, wbArticleCacheMock, wbMessageCacheMock, wbProjectCacheMock); FreeMarkerTemplateLoader templateLoader = new FreeMarkerTemplateLoader(cacheInstances); FreeMarkerTemplateObject object = (FreeMarkerTemplateObject) templateLoader.findTemplateSource(templatePage); PowerMock.verify(wbUriCacheMock, wbWebPageCacheMock, wbWebPageModuleCacheMock, wbParameterCacheMock, wbImageCacheMock, wbArticleCacheMock, wbMessageCacheMock, wbProjectCacheMock); assertTrue(object == null); } catch (Exception e) { assertTrue(false); } }
Example 7
Source File: ParamUtilsTest.java From turin-programming-language with Apache License 2.0 | 6 votes |
@Test public void testDesugarizeAsteriskParamWithMissingNonDefault() { List<FormalParameterNode> formalParameters = ImmutableList.of(fn1, fn2, fd1, fd2); Expression value = createMock(Expression.class); value.setParent(EasyMock.anyObject()); value.setParent(EasyMock.anyObject()); SymbolResolver resolver = createMock(SymbolResolver.class); ReferenceTypeUsage typeUsageOfAsteriskParam = createMock(ReferenceTypeUsage.class); expect(value.calcType()).andReturn(typeUsageOfAsteriskParam); expect(typeUsageOfAsteriskParam.isReference()).andReturn(true); expect(typeUsageOfAsteriskParam.asReferenceTypeUsage()).andReturn(typeUsageOfAsteriskParam); TypeDefinition typeOfAsteriskParam = PowerMock.createMock(TypeDefinitionNode.class); expect(typeUsageOfAsteriskParam.getTypeDefinition()).andReturn(typeOfAsteriskParam); expect(typeOfAsteriskParam.hasMethodFor("getFn1", Collections.emptyList(), false)).andReturn(true); expect(typeOfAsteriskParam.hasMethodFor("getFn2", Collections.emptyList(), false)).andReturn(false); Node parent = new IntLiteral(3); // it does not really matter replay(value, resolver, typeUsageOfAsteriskParam); PowerMock.replay(typeOfAsteriskParam); Either<String, List<ActualParam>> res = desugarizeAsteriskParam(formalParameters, value, resolver, parent); assertEquals(true, res.isLeft()); verify(value, resolver, typeUsageOfAsteriskParam); PowerMock.verify(typeOfAsteriskParam); }
Example 8
Source File: StartJobTaskTest.java From dropwizard-sundial with Apache License 2.0 | 6 votes |
@Test public void shouldPassParameters() throws Exception { StartJobTask task = new StartJobTask(); Map<String, List<String>> map = new HashMap<String, List<String>>(); map.put("JOB_NAME", Arrays.asList("test")); map.put("Param1", Arrays.asList("1")); map.put("Param2", Arrays.asList("2")); OutputStream stream = new ByteArrayOutputStream(); PrintWriter out = new PrintWriter(stream); PowerMock.mockStatic(SundialJobScheduler.class); SundialJobScheduler.startJob( "test", ImmutableMap.of( "JOB_NAME", (Object) "test", "Param1", (Object) "1", "Param2", (Object) "2")); EasyMock.expectLastCall(); PowerMock.replay(SundialJobScheduler.class); task.execute(map, out); PowerMock.verify(SundialJobScheduler.class); }
Example 9
Source File: TestWBFreeMarkerTemplateLoader.java From cms with Apache License 2.0 | 5 votes |
@Test public void test_getReader_page() { try { String templateName = "testX"; String htmlSource = "<b>abc</b>"; FreeMarkerTemplateObject templateObjectMock = PowerMock.createMock(FreeMarkerTemplateObject.class); EasyMock.expect(templateObjectMock.getType()).andReturn(TemplateType.TEMPLATE_PAGE); EasyMock.expect(templateObjectMock.getExternalKey()).andReturn(templateName); WPBPage pageMock = PowerMock.createMock(WPBPage.class); EasyMock.expect(pageMock.getHtmlSource()).andReturn(htmlSource); EasyMock.expect(wbWebPageCacheMock.getByExternalKey(templateName)).andReturn(pageMock); PowerMock.replay(wbUriCacheMock, wbWebPageCacheMock, wbWebPageModuleCacheMock, wbParameterCacheMock, wbImageCacheMock, wbArticleCacheMock, wbMessageCacheMock, wbProjectCacheMock, templateObjectMock, pageMock); FreeMarkerTemplateLoader templateLoader = new FreeMarkerTemplateLoader(cacheInstances); Reader reader = templateLoader.getReader(templateObjectMock, ""); BufferedReader strReader = new BufferedReader(reader); assertTrue(strReader.readLine().equals(htmlSource)); PowerMock.verify(wbUriCacheMock, wbWebPageCacheMock, wbWebPageModuleCacheMock, wbParameterCacheMock, wbImageCacheMock, wbArticleCacheMock, wbMessageCacheMock, wbProjectCacheMock, templateObjectMock, pageMock); }catch (Exception e) { assertTrue(false); } }
Example 10
Source File: EurekaDynamicServerListLoadBalancerTest.java From ribbon with Apache License 2.0 | 5 votes |
@Test public void testLoadBalancerHappyCase() throws Exception { Assert.assertNotEquals("the two test server list counts should be different", secondServerListSize, initialServerListSize); DynamicServerListLoadBalancer<DiscoveryEnabledServer> lb = null; try { Capture<EurekaEventListener> eventListenerCapture = new Capture<EurekaEventListener>(); eurekaClientMock.registerEventListener(EasyMock.capture(eventListenerCapture)); PowerMock.replay(DiscoveryClient.class); PowerMock.replay(eurekaClientMock); // actual testing // initial creation and loading of the first serverlist lb = new DynamicServerListLoadBalancer<DiscoveryEnabledServer>( config, new AvailabilityFilteringRule(), new DummyPing(), new DiscoveryEnabledNIWSServerList(vipAddress, eurekaClientProvider), new ZoneAffinityServerListFilter<DiscoveryEnabledServer>(), new EurekaNotificationServerListUpdater(eurekaClientProvider) ); Assert.assertEquals(initialServerListSize, lb.getServerCount(false)); // trigger an eureka CacheRefreshEvent eventListenerCapture.getValue().onEvent(new CacheRefreshedEvent()); Assert.assertTrue(verifyFinalServerListCount(secondServerListSize, lb)); } finally { if (lb != null) { lb.shutdown(); PowerMock.verify(eurekaClientMock); PowerMock.verify(DiscoveryClient.class); } } }
Example 11
Source File: TestWBFreeMarkerTemplateLoader.java From cms with Apache License 2.0 | 5 votes |
@Test public void test_getReader_module() { try { String templateName = "testX"; String htmlSource = "<b>abc</b>"; FreeMarkerTemplateObject templateObjectMock = PowerMock.createMock(FreeMarkerTemplateObject.class); EasyMock.expect(templateObjectMock.getType()).andReturn(TemplateType.TEMPLATE_MODULE); EasyMock.expect(templateObjectMock.getExternalKey()).andReturn(templateName); WPBPageModule pageModuleMock = PowerMock.createMock(WPBPageModule.class); EasyMock.expect(pageModuleMock.getHtmlSource()).andReturn(htmlSource); EasyMock.expect(wbWebPageModuleCacheMock.getByExternalKey(templateName)).andReturn(pageModuleMock); PowerMock.replay(wbUriCacheMock, wbWebPageCacheMock, wbWebPageModuleCacheMock, wbParameterCacheMock, wbImageCacheMock, wbArticleCacheMock, wbMessageCacheMock, wbProjectCacheMock, templateObjectMock, pageModuleMock); FreeMarkerTemplateLoader templateLoader = new FreeMarkerTemplateLoader(cacheInstances); Reader reader = templateLoader.getReader(templateObjectMock, ""); BufferedReader strReader = new BufferedReader(reader); assertTrue(strReader.readLine().equals(htmlSource)); PowerMock.verify(wbUriCacheMock, wbWebPageCacheMock, wbWebPageModuleCacheMock, wbParameterCacheMock, wbImageCacheMock, wbArticleCacheMock, wbMessageCacheMock, wbProjectCacheMock, templateObjectMock, pageModuleMock); }catch (Exception e) { assertTrue(false); } }
Example 12
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 13
Source File: TestWBFreeMarkerTemplateLoader.java From cms with Apache License 2.0 | 5 votes |
@Test public void test_getLastModified_page_exception() { try { String templateName = "testX"; FreeMarkerTemplateObject templateObjectMock = PowerMock.createMock(FreeMarkerTemplateObject.class); EasyMock.expect(templateObjectMock.getType()).andReturn(TemplateType.TEMPLATE_PAGE); //EasyMock.expect(templateObject.getLastModified()).andReturn(date.getTime()); EasyMock.expect(templateObjectMock.getExternalKey()).andReturn(templateName); EasyMock.expect(wbWebPageCacheMock.getByExternalKey(templateName)).andThrow(new WPBIOException("")); PowerMock.replay(wbUriCacheMock, wbWebPageCacheMock, wbWebPageModuleCacheMock, wbParameterCacheMock, wbImageCacheMock, wbArticleCacheMock, wbMessageCacheMock, wbProjectCacheMock, templateObjectMock); FreeMarkerTemplateLoader templateLoader = new FreeMarkerTemplateLoader(cacheInstances); long lastmodified = templateLoader.getLastModified(templateObjectMock); PowerMock.verify(wbUriCacheMock, wbWebPageCacheMock, wbWebPageModuleCacheMock, wbParameterCacheMock, wbImageCacheMock, wbArticleCacheMock, wbMessageCacheMock, wbProjectCacheMock, templateObjectMock); assertTrue (lastmodified == 0L); }catch (Exception e) { assertTrue(false); } }
Example 14
Source File: TestWBFreeMarkerTemplateLoader.java From cms with Apache License 2.0 | 5 votes |
@Test public void test_findTemplateSource_page_ok() { try { String templatePage = WPBTemplateEngine.WEBPAGES_PATH_PREFIX + "test"; WPBPage webPageMock = PowerMock.createMock(WPBPage.class); Date date = new Date(); EasyMock.expect(webPageMock.getLastModified()).andReturn(date); EasyMock.expect(wbWebPageCacheMock.getByExternalKey("test")).andReturn(webPageMock); PowerMock.replay(wbUriCacheMock, wbWebPageCacheMock, wbWebPageModuleCacheMock, wbParameterCacheMock, wbImageCacheMock, wbArticleCacheMock, wbMessageCacheMock, wbProjectCacheMock, webPageMock); FreeMarkerTemplateLoader templateLoader = new FreeMarkerTemplateLoader(cacheInstances); FreeMarkerTemplateObject object = (FreeMarkerTemplateObject) templateLoader.findTemplateSource(templatePage); PowerMock.verify(wbUriCacheMock, wbWebPageCacheMock, wbWebPageModuleCacheMock, wbParameterCacheMock, wbImageCacheMock, wbArticleCacheMock, wbMessageCacheMock, wbProjectCacheMock, webPageMock); assertTrue(object.getExternalKey().equals("test")); assertTrue(object.getType() == TemplateType.TEMPLATE_PAGE); assertTrue(object.getLastModified() == date.getTime()); } catch (Exception e) { assertTrue(false); } }
Example 15
Source File: ParamUtilsTest.java From turin-programming-language with Apache License 2.0 | 5 votes |
@Test public void testDesugarizeAsteriskParamWithOnlyNonDefaultAvailable() { List<FormalParameterNode> formalParameters = ImmutableList.of(fn1, fn2, fd1, fd2); Expression value = createMock(Expression.class); value.setParent(EasyMock.anyObject()); value.setParent(EasyMock.anyObject()); value.setParent(EasyMock.anyObject()); value.setParent(EasyMock.anyObject()); SymbolResolver resolver = createMock(SymbolResolver.class); ReferenceTypeUsage typeUsageOfAsteriskParam = createMock(ReferenceTypeUsage.class); expect(value.calcType()).andReturn(typeUsageOfAsteriskParam); expect(typeUsageOfAsteriskParam.isReference()).andReturn(true); expect(typeUsageOfAsteriskParam.asReferenceTypeUsage()).andReturn(typeUsageOfAsteriskParam); TypeDefinition typeOfAsteriskParam = PowerMock.createMock(TypeDefinitionNode.class); expect(typeUsageOfAsteriskParam.getTypeDefinition()).andReturn(typeOfAsteriskParam); expect(typeOfAsteriskParam.hasMethodFor("getFn1", Collections.emptyList(), false)).andReturn(true); expect(typeOfAsteriskParam.hasMethodFor("getFn2", Collections.emptyList(), false)).andReturn(true); expect(typeOfAsteriskParam.hasMethodFor("getFd1", Collections.emptyList(), false)).andReturn(false); expect(typeOfAsteriskParam.hasMethodFor("getFd2", Collections.emptyList(), false)).andReturn(false); Node parent = new IntLiteral(3); // it does not really matter replay(value, resolver, typeUsageOfAsteriskParam); PowerMock.replay(typeOfAsteriskParam); Either<String, List<ActualParam>> res = desugarizeAsteriskParam(formalParameters, value, resolver, parent); assertEquals(true, res.isRight()); // 2 + the map for default params assertEquals(3, res.getRight().size()); verify(value, resolver, typeUsageOfAsteriskParam); PowerMock.verify(typeOfAsteriskParam); }
Example 16
Source File: TestWBFreeMarkerTemplateLoader.java From cms with Apache License 2.0 | 5 votes |
@Test public void test_getLastModified_page() { try { String templateName = "testX"; Date date = new Date(); FreeMarkerTemplateObject templateObjectMock = PowerMock.createMock(FreeMarkerTemplateObject.class); EasyMock.expect(templateObjectMock.getType()).andReturn(TemplateType.TEMPLATE_PAGE); //EasyMock.expect(templateObject.getLastModified()).andReturn(date.getTime()); EasyMock.expect(templateObjectMock.getExternalKey()).andReturn(templateName); WPBPage pageMock = PowerMock.createMock(WPBPage.class); EasyMock.expect(pageMock.getLastModified()).andReturn(date); EasyMock.expect(wbWebPageCacheMock.getByExternalKey(templateName)).andReturn(pageMock); PowerMock.replay(wbUriCacheMock, wbWebPageCacheMock, wbWebPageModuleCacheMock, wbParameterCacheMock, wbImageCacheMock, wbArticleCacheMock, wbMessageCacheMock, wbProjectCacheMock, pageMock, templateObjectMock); FreeMarkerTemplateLoader templateLoader = new FreeMarkerTemplateLoader(cacheInstances); long lastmodified = templateLoader.getLastModified(templateObjectMock); PowerMock.verify(wbUriCacheMock, wbWebPageCacheMock, wbWebPageModuleCacheMock, wbParameterCacheMock, wbImageCacheMock, wbArticleCacheMock, wbMessageCacheMock, wbProjectCacheMock, pageMock, templateObjectMock); assertTrue (lastmodified == date.getTime()); }catch (Exception e) { assertTrue(false); } }
Example 17
Source File: TestWBFreeMarkerTemplateLoader.java From cms with Apache License 2.0 | 5 votes |
@Test public void test_getLastModified_module() { try { String templateName = "testX"; Date date = new Date(); FreeMarkerTemplateObject templateObjectMock = PowerMock.createMock(FreeMarkerTemplateObject.class); EasyMock.expect(templateObjectMock.getType()).andReturn(TemplateType.TEMPLATE_MODULE); //EasyMock.expect(templateObject.getLastModified()).andReturn(date.getTime()); EasyMock.expect(templateObjectMock.getExternalKey()).andReturn(templateName); WPBPageModule pageModuleMock = PowerMock.createMock(WPBPageModule.class); EasyMock.expect(pageModuleMock.getLastModified()).andReturn(date); EasyMock.expect(wbWebPageModuleCacheMock.getByExternalKey(templateName)).andReturn(pageModuleMock); PowerMock.replay(wbUriCacheMock, wbWebPageCacheMock, wbWebPageModuleCacheMock, wbParameterCacheMock, wbImageCacheMock, wbArticleCacheMock, wbMessageCacheMock, wbProjectCacheMock, pageModuleMock, templateObjectMock); FreeMarkerTemplateLoader templateLoader = new FreeMarkerTemplateLoader(cacheInstances); long lastmodified = templateLoader.getLastModified(templateObjectMock); PowerMock.verify(wbUriCacheMock, wbWebPageCacheMock, wbWebPageModuleCacheMock, wbParameterCacheMock, wbImageCacheMock, wbArticleCacheMock, wbMessageCacheMock, wbProjectCacheMock, templateObjectMock); assertTrue (lastmodified == date.getTime()); }catch (Exception e) { assertTrue(false); } }
Example 18
Source File: ProcessLauncherImplTest.java From chrome-devtools-java-client with Apache License 2.0 | 5 votes |
@Test public void testLaunch() throws Exception { List<String> args = new ArrayList<>(); args.add("arg1"); args.add("arg2"); ProcessBuilder processBuilder = PowerMock.createMock(ProcessBuilder.class); PowerMock.expectNew(ProcessBuilder.class, new Class[] {}).andReturn(processBuilder); Capture<List<String>> captureCommands = Capture.newInstance(); expect(processBuilder.command(capture(captureCommands))).andReturn(processBuilder); expect(processBuilder.redirectErrorStream(true)).andReturn(processBuilder); expect(processBuilder.redirectOutput(Redirect.PIPE)).andReturn(processBuilder); Process process = mock(Process.class); expect(processBuilder.start()).andReturn(process); PowerMock.replayAll(ProcessBuilder.class, processBuilder); assertEquals(process, processLauncher.launch("program-name", args)); PowerMock.verify(ProcessBuilder.class, processBuilder); List<String> commands = captureCommands.getValue(); assertEquals(3, commands.size()); assertEquals("program-name", commands.get(0)); assertEquals("arg1", commands.get(1)); assertEquals("arg2", commands.get(2)); }
Example 19
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); } }
Example 20
Source File: AnnotationManagerTest.java From saros with GNU General Public License v2.0 | 2 votes |
/** * Verifies that all added range highlighter removal mocks where called at least once. This can be * used to check whether the local representation of removed annotations was also removed. * * @see #mockAddRemoveRangeHighlighters(List, IFile, Editor, TextAttributes) */ private void verifyRemovalCall() { PowerMock.verify(AnnotationManager.class); }