Java Code Examples for org.powermock.api.mockito.PowerMockito#verifyStatic()
The following examples show how to use
org.powermock.api.mockito.PowerMockito#verifyStatic() .
These examples are extracted from open source projects.
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 Project: stetho File: ResponseHandlingInputStreamTest.java License: MIT License | 6 votes |
@Test public void testSwallowException() throws IOException { OutputStream exceptionOutputStream = new OutputStream() { @Override public void write(int oneByte) throws IOException { throw new TestIOException(); } }; ResponseHandlingInputStream responseHandlingInputStream = new ResponseHandlingInputStream( new ByteArrayInputStream(TEST_RESPONSE_BODY), TEST_REQUEST_ID, exceptionOutputStream, null /* decompressedCounter */, mNetworkPeerManager, new DefaultResponseHandler(mNetworkEventReporter, TEST_REQUEST_ID)); PowerMockito.mockStatic(CLog.class); responseHandlingInputStream.read(); PowerMockito.verifyStatic(); }
Example 2
Source Project: cs-actions File: SSLUtilsTest.java License: Apache License 2.0 | 6 votes |
@Test public void testConfigureStoreWithTLS() throws Exception { GetMailInput input = inputBuilder.build(); doReturn(objectMock).when(propertiesMock).setProperty(PropNames.MAIL + PopPropNames.POP3 + PropNames.SSL_ENABLE, String.valueOf(false)); doReturn(objectMock).when(propertiesMock).setProperty(PropNames.MAIL + PopPropNames.POP3 + PropNames.START_TLS_ENABLE, String.valueOf(true)); doReturn(objectMock).when(propertiesMock).setProperty(PropNames.MAIL + PopPropNames.POP3 + PropNames.START_TLS_REQUIRED, String.valueOf(true)); PowerMockito.mockStatic(Session.class); PowerMockito.doReturn(sessionMock).when(Session.class, "getInstance", Matchers.<Properties>any(), Matchers.<Authenticator>any()); doReturn(storeMock).when(sessionMock).getStore(any(String.class)); Store store = SSLUtils.configureStoreWithTLS(propertiesMock, authenticatorMock, input); assertEquals(storeMock, store); verify(propertiesMock).setProperty(PropNames.MAIL + PopPropNames.POP3 + SecurityConstants.SECURE_SUFFIX + PropNames.SSL_ENABLE, String.valueOf(false)); verify(propertiesMock).setProperty(PropNames.MAIL + PopPropNames.POP3 + SecurityConstants.SECURE_SUFFIX + PropNames.START_TLS_ENABLE, String.valueOf(true)); verify(propertiesMock).setProperty(PropNames.MAIL + PopPropNames.POP3 + SecurityConstants.SECURE_SUFFIX + PropNames.START_TLS_REQUIRED, String.valueOf(true)); PowerMockito.verifyStatic(); Session.getInstance(Matchers.<Properties>any(), Matchers.<Authenticator>any()); verify(sessionMock).getStore(PopPropNames.POP3 + SecurityConstants.SECURE_SUFFIX); }
Example 3
Source Project: hop File: RemovePipelineServletTest.java License: Apache License 2.0 | 6 votes |
@Test @PrepareForTest( { Encode.class } ) public void testRemovePipelineServletEscapesHtmlWhenPipelineNotFound() throws ServletException, IOException { HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class ); HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class ); StringWriter out = new StringWriter(); PrintWriter printWriter = new PrintWriter( out ); PowerMockito.spy( Encode.class ); when( mockHttpServletRequest.getContextPath() ).thenReturn( RemovePipelineServlet.CONTEXT_PATH ); when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST ); when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter ); removePipelineServlet.doGet( mockHttpServletRequest, mockHttpServletResponse ); assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H1", out.toString() ) ) ); PowerMockito.verifyStatic( atLeastOnce() ); Encode.forHtml( anyString() ); }
Example 4
Source Project: react-native-azurenotificationhub File: ReactNativeUtilTest.java License: MIT License | 6 votes |
@Test public void testProcessNotificationActionsParseError() { final int notificationID = 1; final String jsonString = "Invalid JSON format"; NotificationCompat.Builder notificationBuilder = PowerMockito.mock(NotificationCompat.Builder.class); Intent intent = PowerMockito.mock(Intent.class); when(IntentFactory.createIntent()).thenReturn(intent); when(mBundle.getString(KEY_REMOTE_NOTIFICATION_ACTIONS)).thenReturn(jsonString); processNotificationActions( mReactApplicationContext, mBundle, notificationBuilder, notificationID); PowerMockito.verifyStatic(IntentFactory.class, times(0)); IntentFactory.createIntent(); PowerMockito.verifyStatic(Log.class); Log.e(eq(ReactNativeUtil.TAG), eq(ERROR_COVERT_ACTIONS), any(JSONException.class)); }
Example 5
Source Project: gdx-fireapp File: JsonDataModifierTest.java License: Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") public void modify() throws Exception { // Given Class wantedType = String.class; String jsonData = "test"; PowerMockito.mockStatic(JsonProcessor.class); PowerMockito.mockStatic(Json.class); Function function = Mockito.mock(Function.class); Json json = PowerMockito.mock(Json.class); PowerMockito.whenNew(Json.class).withAnyArguments().thenReturn(json); JsonDataModifier<String> jsonDataModifier = new JsonDataModifier<String>(wantedType, function); Mockito.when(function.apply(Mockito.any())).thenReturn("test_transaction_callback"); Mockito.when(json.toJson(Mockito.any(), Mockito.any(Class.class))).thenReturn("test_json"); // When Object result = jsonDataModifier.modify(jsonData); // Then Assert.assertEquals("test_json", result); Mockito.verify(json, VerificationModeFactory.times(1)).toJson(Mockito.eq("test_transaction_callback"), Mockito.eq(wantedType)); PowerMockito.verifyStatic(JsonProcessor.class, VerificationModeFactory.times(1)); JsonProcessor.process(Mockito.eq(String.class), Mockito.eq(jsonData)); Mockito.verify(function, VerificationModeFactory.times(1)).apply(Mockito.isNull()); }
Example 6
Source Project: carbon-apimgt File: SQLConstantmanagerFactoryTestCase.java License: Apache License 2.0 | 5 votes |
@Test public void testInitializeSQLConstantManagerOracle() throws Exception { Mockito.when(databaseMetaData.getDriverName()).thenReturn("Oracle"); SQLConstantManagerFactory.initializeSQLConstantManager(); PowerMockito.verifyStatic(APIMgtDBUtil.class); APIMgtDBUtil.closeAllConnections(null, connection, null); }
Example 7
Source Project: pentaho-kettle File: GetTransStatusServletTest.java License: Apache License 2.0 | 5 votes |
@Test @PrepareForTest( { Encode.class } ) public void testGetTransStatusServletEscapesHtmlWhenTransFound() throws ServletException, IOException { KettleLogStore.init(); HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class ); HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class ); Trans mockTrans = mock( Trans.class ); TransMeta mockTransMeta = mock( TransMeta.class ); LogChannelInterface mockChannelInterface = mock( LogChannelInterface.class ); StringWriter out = new StringWriter(); PrintWriter printWriter = new PrintWriter( out ); PowerMockito.spy( Encode.class ); when( mockHttpServletRequest.getContextPath() ).thenReturn( GetTransStatusServlet.CONTEXT_PATH ); when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST ); when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter ); when( mockTransformationMap.getTransformation( any( CarteObjectEntry.class ) ) ).thenReturn( mockTrans ); when( mockTrans.getLogChannel() ).thenReturn( mockChannelInterface ); when( mockTrans.getTransMeta() ).thenReturn( mockTransMeta ); when( mockTransMeta.getMaximum() ).thenReturn( new Point( 10, 10 ) ); getTransStatusServlet.doGet( mockHttpServletRequest, mockHttpServletResponse ); assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "TITLE", out.toString() ) ) ); PowerMockito.verifyStatic( atLeastOnce() ); Encode.forHtml( anyString() ); }
Example 8
Source Project: PermissMe File: PermissMeTests.java License: Apache License 2.0 | 5 votes |
@Test public void testOnPermissionDenied_whenRequiredPermissionsAutoDenied_callRequiredPermissionListenerShowFailureUI() { final String[] permissions = { Manifest.permission.WRITE_EXTERNAL_STORAGE}; PowerMockito.when(PermissMeUtils.getDeniedPermissions(any(Activity.class), any(String[].class))).thenReturn (permissions); PowerMockito.when(PermissMeUtils.isAutoDeniedPermission(any(AppCompatActivity.class), any(String.class))) .thenReturn(true); // Return true to show permissionDeniedSnackbar mPermissMe.mPermissionsInfoBundle = mock(Bundle.class); when(mPermissMe.mPermissionsInfoBundle.getBoolean(eq(PermissMe.SHOULD_SHOW_UI_UPON_FAILURE_EXTRA), eq(true))) .thenReturn(true); // Create mock listener to check that correct callbacks are being called mPermissMe.mListener = mock(TestPermissionListener.class); // <<< EXECUTE CALL TO METHOD >>> mPermissMe.onPermissionDenied(PermissMe.REQUIRED_PERMISSION_REQUEST_CODE, permissions); ArgumentCaptor<String[]> permissionArgumentCaptor = ArgumentCaptor.forClass(String[].class); ArgumentCaptor<boolean[]> autoDeniedArgumentCaptor = ArgumentCaptor.forClass(boolean[].class); // Test callback methods in listener verify(mPermissMe.mListener, times(1)).onRequiredPermissionDenied(permissionArgumentCaptor.capture(), autoDeniedArgumentCaptor.capture()); verify(mPermissMe.mListener, never()).onOptionalPermissionDenied(any(String[].class), any(boolean[].class)); verify(mPermissMe.mListener, never()).onSuccess(); // Test values of the callbacks assertTrue(permissionArgumentCaptor.getValue().length == 1); assertTrue(autoDeniedArgumentCaptor.getValue().length == 1); assertArrayEquals(permissions, permissionArgumentCaptor.getValue()); assertTrue(autoDeniedArgumentCaptor.getValue()[0]); // Test that we do show the permission denied snackbar PowerMockito.verifyStatic(times(1)); PermissMeUtils.showPermissionDeniedSnackbar(any(Activity.class), anyString()); }
Example 9
Source Project: Instabug-React-Native File: RNInstabugReactnativeModuleTest.java License: MIT License | 5 votes |
@Test public void given$disable_whenQuery_thenShouldCallNativeApi() { // given PowerMockito.mockStatic(Instabug.class); // when rnModule.disable(); // then PowerMockito.verifyStatic(VerificationModeFactory.times(1)); Instabug.disable(); }
Example 10
Source Project: cloudbreak File: SaltJobIdTrackerTest.java License: Apache License 2.0 | 5 votes |
@Test public void callWithNotStartedAndSlsWithError() throws Exception { String jobId = "1"; try (SaltConnector saltConnector = Mockito.mock(SaltConnector.class)) { SaltJobRunner saltJobRunner = Mockito.mock(BaseSaltJobRunner.class); when(saltJobRunner.getJid()).thenReturn(JobId.jobId(jobId)); when(saltJobRunner.getJobState()).thenCallRealMethod(); doCallRealMethod().when(saltJobRunner).setJobState(any()); when(saltJobRunner.getNodesWithError()).thenCallRealMethod(); doCallRealMethod().when(saltJobRunner).setNodesWithError(any()); when(saltJobRunner.submit(any(SaltConnector.class))).thenReturn(jobId); saltJobRunner.setJobState(JobState.NOT_STARTED); Set<String> targets = Sets.newHashSet("10.0.0.1", "10.0.0.2", "10.0.0.3"); when(saltJobRunner.getTargetHostnames()).thenReturn(targets); PowerMockito.mockStatic(SaltStates.class); PowerMockito.when(SaltStates.jobIsRunning(any(), any())).thenReturn(false); PowerMockito.when(SaltStates.jidInfo(any(SaltConnector.class), anyString(), any(Target.class), any())) .thenThrow(new RuntimeException("Salt execution went wrong: saltErrorDetails")); try { new SaltJobIdTracker(saltConnector, saltJobRunner).call(); fail("should throw exception"); } catch (CloudbreakOrchestratorFailedException e) { assertThat(e.getMessage(), containsString("Salt execution went wrong: saltErrorDetails")); assertThat(e.getMessage(), not(containsString("Exception"))); } PowerMockito.verifyStatic(SaltStates.class); SaltStates.jobIsRunning(any(), eq(jobId)); checkTargets(targets, targetCaptor.getAllValues()); } }
Example 11
Source Project: cs-actions File: SSLUtilsTest.java License: Apache License 2.0 | 5 votes |
/** * Test method assSSLSettings with false trustAllRoots. * * @throws Exception */ @Test public void testAddSSLSettingsWithFalseTrustAllRoots() throws Exception { PowerMockito.whenNew(File.class) .withArguments(anyString()) .thenReturn(fileMock); doReturn(true).when(fileMock).exists(); PowerMockito.mockStatic(SSLContext.class); PowerMockito.doReturn(sslContextMock).when(SSLContext.class, "getInstance", anyString()); PowerMockito.mockStatic(SSLUtils.class); PowerMockito.whenNew(URL.class).withArguments(anyString()).thenReturn(urlMock); PowerMockito.doReturn(keyStoreMock).when(SSLUtils.class, "createKeyStore", anyObject(), anyString()); //can't mock TrustManager[] and KeyManager[] objects. PowerMockito.doReturn(null).when(SSLUtils.class, "createAuthTrustManagers", anyObject()); PowerMockito.doReturn(null).when(SSLUtils.class, "createKeyManagers", anyObject(), anyObject()); PowerMockito.whenNew(SecureRandom.class).withNoArguments().thenReturn(secureRandomMock); doNothing().when(sslContextMock).init(null, null, secureRandomMock); PowerMockito.doNothing().when(SSLContext.class, "setDefault", sslContextMock); PowerMockito.doCallRealMethod().when(SSLUtils.class, "addSSLSettings", anyBoolean(), anyString(), anyString(), anyString(), anyString()); SSLUtils.addSSLSettings(false, StringUtils.EMPTY, StringUtils.EMPTY, StringUtils.EMPTY, StringUtils.EMPTY); PowerMockito.verifyNew(File.class, times(2)) .withArguments(anyString()); verify(fileMock, times(2)).exists(); PowerMockito.verifyStatic(); SSLContext.getInstance(anyString()); SSLContext.setDefault(sslContextMock); SSLUtils.createKeyStore(Matchers.<URL>any(), anyString()); SSLUtils.createAuthTrustManagers(Matchers.<KeyStore>anyObject()); SSLUtils.createKeyManagers(Matchers.<KeyStore>any(), anyString()); SSLContext.setDefault(sslContextMock); PowerMockito.verifyNew(SecureRandom.class).withNoArguments(); PowerMockito.verifyNew(URL.class, times(2)).withArguments(anyString()); }
Example 12
Source Project: gdx-fireapp File: AnalyticsTest.java License: Apache License 2.0 | 5 votes |
@Test public void setUserId() { // Given Analytics analytics = new Analytics(); // When analytics.setUserId("test"); // Then PowerMockito.verifyStatic(FirebaseAnalytics.class, VerificationModeFactory.times(1)); FirebaseAnalytics.getInstance((Context) Gdx.app); Mockito.verify(firebaseAnalytics, VerificationModeFactory.times(1)) .setUserId(Mockito.eq("test")); Mockito.verifyNoMoreInteractions(firebaseAnalytics); }
Example 13
Source Project: ecs-cf-service-broker File: EcsServiceTest.java License: Apache License 2.0 | 5 votes |
/** * When changing a namespace plan and a different retention-class is * specified in the parameters, then the retention class should be added. * * @throws Exception when mocking fails */ @Test public void changeNamespacePlanNewRentention() throws Exception { Map<String, Object> retention = new HashMap<>(); retention.put(THIRTY_DAYS, THIRTY_DAYS_IN_SEC); Map<String, Object> params = new HashMap<>(); params.put(RETENTION, retention); setupUpdateNamespaceTest(); setupCreateNamespaceRetentionTest(false); ArgumentCaptor<String> nsCaptor = ArgumentCaptor.forClass(String.class); ArgumentCaptor<RetentionClassCreate> createCaptor = ArgumentCaptor .forClass(RetentionClassCreate.class); ServiceDefinitionProxy service = namespaceServiceFixture(); PlanProxy plan = service.findPlan(NAMESPACE_PLAN_ID2); Map<String, Object> serviceSettings = ecs.changeNamespacePlan(NAMESPACE, service, plan, params); Map<String, Object> returnRetention = (Map<String, Object>) serviceSettings.get(RETENTION); assertEquals(THIRTY_DAYS_IN_SEC, returnRetention.get(THIRTY_DAYS)); PowerMockito.verifyStatic(NamespaceRetentionAction.class); NamespaceRetentionAction.create(same(connection), nsCaptor.capture(), createCaptor.capture()); assertEquals(PREFIX + NAMESPACE, nsCaptor.getValue()); assertEquals(THIRTY_DAYS, createCaptor.getValue().getName()); assertEquals(THIRTY_DAYS_IN_SEC, createCaptor.getValue().getPeriod()); }
Example 14
Source Project: gdx-fireapp File: CrashTest.java License: Apache License 2.0 | 5 votes |
@Test public void initialize() { // Given Crash crash = new Crash(); // When crash.initialize(); crash.initialize(); crash.initialize(); // Then PowerMockito.verifyStatic(Fabric.class, VerificationModeFactory.times(1)); // only one time Fabric.with(Mockito.any(NSArray.class)); }
Example 15
Source Project: Instabug-React-Native File: RNInstabugRepliesModuleTest.java License: MIT License | 5 votes |
@Test public void given$setOnNewReplyReceivedHandler_whenQuery_thenShouldSetNativeCallback() { // given PowerMockito.mockStatic(Replies.class); Callback callback = mock(Callback.class); // when rnModule.setOnNewReplyReceivedHandler(callback); // then PowerMockito.verifyStatic(VerificationModeFactory.times(1)); Replies.setOnNewReplyReceivedCallback(any(Runnable.class)); }
Example 16
Source Project: camunda-bpm-platform File: LazyInitRegistrationTest.java License: Apache License 2.0 | 5 votes |
@Test public void setApplicationContextTest() { PowerMockito.mockStatic(LazyInitRegistration.class); LazyInitRegistration.register(lazyDelegateFilterMock); Set<LazyDelegateFilter<? extends Filter>> registrations = new HashSet<LazyDelegateFilter<? extends Filter>>(); registrations.add(lazyDelegateFilterMock); when(LazyInitRegistration.getRegistrations()).thenReturn(registrations); new LazyInitRegistration().setApplicationContext(applicationContextMock); assertEquals(LazyInitRegistration.APPLICATION_CONTEXT, applicationContextMock); PowerMockito.verifyStatic(LazyInitRegistration.class); LazyInitRegistration.lazyInit(lazyDelegateFilterMock); }
Example 17
Source Project: vividus File: AllureReportGeneratorTests.java License: Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") private void testEnd() throws Exception { File historyDirectory = testFolder.newFolder(); allureReportGenerator.setHistoryDirectory(historyDirectory); File reportDirectory = testFolder.getRoot(); allureReportGenerator.setReportDirectory(reportDirectory); ReportGenerator reportGenerator = PowerMockito.mock(ReportGenerator.class); PowerMockito.whenNew(ReportGenerator.class).withAnyArguments().thenReturn(reportGenerator); PowerMockito.mockStatic(FileUtils.class); PowerMockito.doAnswer(a -> { resolveTrendsDir(reportDirectory); return a; }).when(reportGenerator).generate(any(Path.class), any(List.class)); String text = "text"; when(FileUtils.readFileToString(any(File.class), eq(StandardCharsets.UTF_8))).thenReturn(text); allureReportGenerator.setReportDirectory(testFolder.getRoot()); Resource resource = mockResource("/allure-customization/some_file.txt"); Resource folder = mockResource("/allure-customization/folder/"); Resource[] resources = { resource, folder }; when(resourcePatternResolver.getResources(ALLURE_CUSTOMIZATION_PATTERN)).thenReturn(resources); ExecutorInfo executorInfo = new ExecutorInfo(); executorInfo.setName("Jenkins"); executorInfo.setType("jenkins"); executorInfo.setUrl("https://my-jenkins.url"); executorInfo.setBuildOrder(77L); executorInfo.setBuildName("test-run#77"); executorInfo.setBuildUrl("https://my-jenkins.url/test-run#77"); executorInfo.setReportName("Test Run Allure Report"); executorInfo.setReportUrl("https://my-jenkins.url/test-run#77/AllureReport"); when(propertyMapper.readValue("allure.executor.", ExecutorInfo.class)).thenReturn(executorInfo); allureReportGenerator.start(); allureReportGenerator.end(); PowerMockito.verifyStatic(FileUtils.class, never()); FileUtils.copyInputStreamToFile(eq(folder.getInputStream()), any(File.class)); PowerMockito.verifyStatic(FileUtils.class); FileUtils.copyInputStreamToFile(eq(resource.getInputStream()), any(File.class)); PowerMockito.verifyStatic(FileUtils.class, times(2)); FileUtils.writeStringToFile(any(File.class), eq(text), eq(StandardCharsets.UTF_8)); PowerMockito.verifyStatic(FileUtils.class); FileUtils.copyDirectory(argThat(arg -> arg.getAbsolutePath().equals(resolveTrendsDir(reportDirectory))), eq(historyDirectory)); verify(reportGenerator).generate(any(Path.class), any(List.class)); assertEquals("{" + "\"name\":\"" + executorInfo.getName() + "\",\"type\":\"" + executorInfo.getType() + "\",\"url\":\"" + executorInfo.getUrl() + "\",\"buildOrder\":" + executorInfo.getBuildOrder() + ",\"buildName\":\"" + executorInfo.getBuildName() + "\",\"buildUrl\":\"" + executorInfo.getBuildUrl() + "\",\"reportName\":\"" + executorInfo.getReportName() + "\",\"reportUrl\":\"" + executorInfo.getReportUrl() + "\"}", Files.readString(resultsDirectory.toPath().resolve("executor.json"))); assertEquals("[" + "{\"name\":\"Test defects\"," + "\"matchedStatuses\":[\"broken\"]}," + "{\"name\":\"Product defects\"," + "\"matchedStatuses\":[\"failed\"]}," + "{\"name\":\"Known issues\"," + "\"matchedStatuses\":[\"unknown\"]}" + "]", Files.readString(resultsDirectory.toPath().resolve("categories.json"))); }
Example 18
Source Project: litho File: ComponentLifecycleTest.java License: Apache License 2.0 | 4 votes |
@Test public void testOnShouldCreateLayoutWithNewSizeSpec_shouldUseCache() { ComponentsConfiguration.enableShouldCreateLayoutWithNewSizeSpec = true; Component component; InternalNode holder = mock(InternalNode.class); InternalNode resolved = mock(InternalNode.class); component = new SpyComponentBuilder() .setNode(mNode) .canMeasure(true) .isMountSpec(false) .isLayoutSpecWithSizeSpecCheck(true) .hasState(true) .build(mContext); when(holder.getTailComponent()).thenReturn(component); when(Layout.create(mContext, holder, 100, 100)).thenCallRealMethod(); PowerMockito.doReturn(resolved).when(Layout.class); Layout.create((ComponentContext) any(), (Component) any(), eq(true), eq(true)); // Resolve nested tree for the 1st time. InternalNode result = Layout.create(mContext, holder, 100, 100); PowerMockito.verifyStatic(Layout.class); // Layout should be created and measured. Layout.create((ComponentContext) any(), (Component) any(), eq(true), eq(true)); Layout.measure((ComponentContext) any(), eq(result), eq(100), eq(100), eq((DiffNode) null)); /* --- */ // Return nested tree next time. when(holder.getNestedTree()).thenReturn(result); // Use previous layout in next call. doReturn(true).when(component).canUsePreviousLayout((ComponentContext) any()); // Call resolve nested tree 2nd time. Layout.create(mContext, holder, 100, 100); // There should be no new invocation of Layout.create(). PowerMockito.verifyStatic(Layout.class, times(1)); Layout.create((ComponentContext) any(), (Component) any(), eq(true), eq(true)); // Should only remeasure. PowerMockito.verifyStatic(Layout.class, times(1)); Layout.remeasure(resolved, 100, 100); ComponentsConfiguration.enableShouldCreateLayoutWithNewSizeSpec = false; }
Example 19
Source Project: streaming-file-server File: BasicStaticClassTest.java License: MIT License | 3 votes |
public void testStaticMock() throws Exception { PowerMockito.mockStatic(StaticClass.class); when(StaticClass.underscore(anyString())).thenCallRealMethod(); when(StaticClass.child(anyString())).thenReturn("powermock is awesome!"); String actual = StaticClass.underscore("Powermock"); PowerMockito.verifyStatic(StaticClass.class); assertEquals("something wrong here...", "powermock-is-awesome!", actual); }
Example 20
Source Project: pitest File: PowerMockTest.java License: Apache License 2.0 | 3 votes |
@Test public void testReplaceStaticCallToMutatedClass() { PowerMockito.mockStatic(PowerMockCallsOwnMethod.class); new PowerMockCallsOwnMethod().call(); PowerMockito.verifyStatic(); PowerMockCallsOwnMethod.foo(); }