Java Code Examples for org.powermock.api.mockito.PowerMockito#verifyNoMoreInteractions()

The following examples show how to use org.powermock.api.mockito.PowerMockito#verifyNoMoreInteractions() . 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: AppServletContextListenerTest.java    From aws-mock with MIT License 6 votes vote down vote up
@Test
public void Test_contextDestroyedPersistenceEnabled() {
    Whitebox.setInternalState(AppServletContextListener.class, "persistenceEnabled", true);
    acl.contextDestroyed(sce);

    verifyStatic();
    PersistenceUtils.saveAll(isA((new AbstractMockEc2Instance[1]).getClass()), eq(PersistenceStoreType.EC2));
    verifyStatic();
    PersistenceUtils.saveAll(isA((new MockVpc[1]).getClass()), eq(PersistenceStoreType.VPC));
    verifyStatic();
    PersistenceUtils.saveAll(isA((new MockVolume[1]).getClass()), eq(PersistenceStoreType.VOLUME));
    verifyStatic();
    PersistenceUtils.saveAll(isA((new MockTags[1]).getClass()), eq(PersistenceStoreType.TAGS));
    verifyStatic();
    PersistenceUtils.saveAll(isA((new MockSubnet[1]).getClass()), eq(PersistenceStoreType.SUBNET));
    verifyStatic();
    PersistenceUtils.saveAll(isA((new MockRouteTable[1]).getClass()), eq(PersistenceStoreType.ROUTETABLE));
    verifyStatic();
    PersistenceUtils.saveAll(isA((new MockInternetGateway[1]).getClass()), eq(PersistenceStoreType.INTERNETGATEWAY));
    PowerMockito.verifyNoMoreInteractions(PersistenceUtils.class);
    
    Whitebox.setInternalState(AppServletContextListener.class, "persistenceEnabled", false);
}
 
Example 2
Source File: CrashTest.java    From gdx-fireapp with Apache License 2.0 6 votes vote down vote up
@Test
public void initialize() {
    // Given
    PowerMockito.mockStatic(Crashlytics.class);
    PowerMockito.mockStatic(Fabric.class);
    Crash crash = new Crash();

    // When
    crash.initialize();
    crash.initialize();
    crash.initialize();

    // Then
    PowerMockito.verifyStatic(Fabric.class, VerificationModeFactory.times(1));
    Fabric.with(Mockito.any(AndroidApplication.class), Mockito.any(Crashlytics.class));
    PowerMockito.verifyNoMoreInteractions(Fabric.class);
}
 
Example 3
Source File: SaltApiNodeStepPlugin_ValidationTest.java    From salt-step with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testValidateAllArguments() throws SaltStepValidationException {
    PowerMockito.mockStatic(Validators.class);
    PowerMockito.doNothing().when(Validators.class);
    Validators.checkNotEmpty(Mockito.anyString(), Mockito.anyString(),
            Mockito.any(SaltApiNodeStepFailureReason.class), Mockito.same(node));

    plugin.validate(PARAM_USER, PARAM_PASSWORD, node);

    PowerMockito.verifyStatic();
    Validators.checkNotEmpty(SaltApiNodeStepPlugin.SALT_API_END_POINT_OPTION_NAME, PARAM_ENDPOINT,
            SaltApiNodeStepFailureReason.ARGUMENTS_MISSING, node);
    PowerMockito.verifyStatic();
    Validators.checkNotEmpty(SaltApiNodeStepPlugin.SALT_API_FUNCTION_OPTION_NAME, PARAM_FUNCTION,
            SaltApiNodeStepFailureReason.ARGUMENTS_MISSING, node);
    PowerMockito.verifyStatic();
    Validators.checkNotEmpty(SaltApiNodeStepPlugin.SALT_API_EAUTH_OPTION_NAME, PARAM_EAUTH,
            SaltApiNodeStepFailureReason.ARGUMENTS_MISSING, node);
    PowerMockito.verifyStatic();
    Validators.checkNotEmpty(SaltApiNodeStepPlugin.SALT_USER_OPTION_NAME, PARAM_USER,
            SaltApiNodeStepFailureReason.ARGUMENTS_MISSING, node);
    PowerMockito.verifyStatic();
    Validators.checkNotEmpty(SaltApiNodeStepPlugin.SALT_PASSWORD_OPTION_NAME, PARAM_PASSWORD,
            SaltApiNodeStepFailureReason.ARGUMENTS_MISSING, node);
    PowerMockito.verifyNoMoreInteractions(Validators.class);
}
 
Example 4
Source File: PcapHelperTest.java    From opensoc-streaming with Apache License 2.0 5 votes vote down vote up
/**
 * Input time is in SECONDS and data creation time is in MICROS.
 */
@Test
public void test_convertToDataCreationTimeUnit_seconds_micros_decimal() {
  PowerMockito.when(PcapHelper.getDataCreationTimeUnit()).thenReturn(
      TimeUnit.MICROS);
  PowerMockito.verifyNoMoreInteractions();

  long inputTime = 13; // input time in seconds (double to long type casting)
  long time = PcapHelper.convertSecondsToDataCreationTimeUnit(inputTime);

  Assert.isTrue(13000000L == time);
}
 
Example 5
Source File: SecureLoginTest.java    From pxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testLoginKerberosFirstTime() throws IOException {
    PowerMockito.mockStatic(PxfUserGroupInformation.class);
    expectedUGI = UserGroupInformation.createUserForTesting("some", new String[]{});
    expectedLoginSession = new LoginSession("config", "principal", "/path/to/keytab", expectedUGI, null, 0);
    configuration.set("hadoop.security.authentication", "kerberos");
    configuration.set(PROPERTY_KEY_SERVICE_PRINCIPAL, "principal");
    configuration.set(PROPERTY_KEY_SERVICE_KEYTAB, "/path/to/keytab");
    configuration.set("hadoop.kerberos.min.seconds.before.relogin", "90");
    when(PxfUserGroupInformation.loginUserFromKeytab(configuration, "server", "config", "principal", "/path/to/keytab")).thenReturn(expectedLoginSession);

    UserGroupInformation loginUGI = secureLogin.getLoginUser("server", "config", configuration);

    LoginSession loginSession = SecureLogin.getCache().get("server");
    assertEquals(1, SecureLogin.getCache().size());
    assertEquals(expectedLoginSession, loginSession);
    assertSame(loginUGI, loginSession.getLoginUser());
    assertSame(expectedUGI, loginUGI); // since actual login was mocked, we should get back whatever we mocked

    // verify static calls issued
    PowerMockito.verifyStatic();
    PxfUserGroupInformation.loginUserFromKeytab(configuration, "server", "config", "principal", "/path/to/keytab");
    PowerMockito.verifyStatic();
    PxfUserGroupInformation.reloginFromKeytab("server", expectedLoginSession);

    PowerMockito.verifyNoMoreInteractions(PxfUserGroupInformation.class);
}
 
Example 6
Source File: PcapHelperTest.java    From opensoc-streaming with Apache License 2.0 5 votes vote down vote up
/**
 * Input time is in SECONDS and data creation time is in MICROS.
 */
@Test
public void test_convertToDataCreationTimeUnit_seconds_micros_0() {
  PowerMockito.when(PcapHelper.getDataCreationTimeUnit()).thenReturn(
      TimeUnit.MICROS);
  PowerMockito.verifyNoMoreInteractions();

  long endTime = 0; // input time in micros
  long time = PcapHelper.convertToDataCreationTimeUnit(endTime);

  Assert.isTrue(0 == time);
}
 
Example 7
Source File: PcapHelperTest.java    From opensoc-streaming with Apache License 2.0 5 votes vote down vote up
/**
 * Input time is in SECONDS and data creation time is in MICROS.
 */
@Test
public void test_convertToDataCreationTimeUnit_seconds_micros() {
  PowerMockito.when(PcapHelper.getDataCreationTimeUnit()).thenReturn(
      TimeUnit.MICROS);
  PowerMockito.verifyNoMoreInteractions();

  long endTime = 1111122222L; // input time in seconds
  long time = PcapHelper.convertToDataCreationTimeUnit(endTime);

  Assert.isTrue(1111122222000000L == time);
}
 
Example 8
Source File: PcapHelperTest.java    From opensoc-streaming with Apache License 2.0 5 votes vote down vote up
/**
 * Input time is in MILLIS and data creation time is in MILLIS.
 */
@Test
public void test_convertToDataCreationTimeUnit_millis_millis() {
  PowerMockito.when(PcapHelper.getDataCreationTimeUnit()).thenReturn(
      TimeUnit.MILLIS);
  PowerMockito.verifyNoMoreInteractions();

  long endTime = 111112222233L; // input time in millis
  long time = PcapHelper.convertToDataCreationTimeUnit(endTime);

  Assert.isTrue(111112222233L == time);
}
 
Example 9
Source File: PcapHelperTest.java    From opensoc-streaming with Apache License 2.0 5 votes vote down vote up
/**
 * Input time is in SECONDS and data creation time is in MILLIS.
 */
@Test
public void test_convertToDataCreationTimeUnit_seconds_millis() {
  PowerMockito.when(PcapHelper.getDataCreationTimeUnit()).thenReturn(
      TimeUnit.MILLIS);
  PowerMockito.verifyNoMoreInteractions();

  long endTime = 1111122222L; // input time in seconds
  long time = PcapHelper.convertToDataCreationTimeUnit(endTime);

  Assert.isTrue(1111122222000L == time);
}
 
Example 10
Source File: PcapHelperTest.java    From opensoc-streaming with Apache License 2.0 5 votes vote down vote up
/**
 * Input time is in MICROS and data creation time is in SECONDS.
 */
@Test
public void test_convertToDataCreationTimeUnit_micros_seconds() {
  PowerMockito.when(PcapHelper.getDataCreationTimeUnit()).thenReturn(
      TimeUnit.SECONDS);
  PowerMockito.verifyNoMoreInteractions();

  long endTime = 1111122222333444L; // input time in micros
  long time = PcapHelper.convertToDataCreationTimeUnit(endTime);

  Assert.isTrue(1111122222L == time);
}
 
Example 11
Source File: PcapHelperTest.java    From opensoc-streaming with Apache License 2.0 5 votes vote down vote up
/**
 * Input time is in MILLIS and data creation time is in SECONDS.
 */
@Test
public void test_convertToDataCreationTimeUnit_millis_seconds() {
  PowerMockito.when(PcapHelper.getDataCreationTimeUnit()).thenReturn(
      TimeUnit.SECONDS);
  PowerMockito.verifyNoMoreInteractions();

  long endTime = 1111122222333L; // input time in millis
  long time = PcapHelper.convertToDataCreationTimeUnit(endTime);

  Assert.isTrue(1111122222L == time);
}
 
Example 12
Source File: Slf4jMdcDelegationTest.java    From tracee with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void clearAlsoRemovesTheThreadLocalTraceeKeys() {
	traceeKeys.get().add("test");
	unit.clear();
	verifyStatic(times(1));
	MDC.remove("test");
	PowerMockito.verifyNoMoreInteractions(MDC.class);
}
 
Example 13
Source File: AnalyticsUnitTest.java    From openshop.io-android with MIT License 5 votes vote down vote up
@Test
public void logOpenedByNotificationTest() throws Exception {
    prepareMockedFields();
    Analytics.prepareTrackersAndFbLogger(testShop, mockContext);

    Analytics.logOpenedByNotification("testContent");

    PowerMockito.verifyNoMoreInteractions(mockAppEventsLogger);
    verify(mockTracker, times(1)).send((Map<String, String>) notNull());
    verify(mockTrackerApp, times(1)).send((Map<String, String>) notNull());
}
 
Example 14
Source File: CrashTest.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
@Test
public void log() {
    // Given
    PowerMockito.mockStatic(Crashlytics.class);
    PowerMockito.mockStatic(Fabric.class);
    Crash crash = new Crash();

    // When
    crash.log("abc");

    // Then
    PowerMockito.verifyStatic(Crashlytics.class, VerificationModeFactory.times(1));
    Crashlytics.log("abc");
    PowerMockito.verifyNoMoreInteractions(Crashlytics.class);
}
 
Example 15
Source File: DefaultTypeFaceProviderTest.java    From CoachMarks with Apache License 2.0 5 votes vote down vote up
@Test
public void getTypeFaceFromAssetsFailTest() throws Exception {
    PowerMockito.mockStatic(Typeface.class);
    PowerMockito.mockStatic(Log.class);
    when(mMockContext.getAssets()).thenReturn(mMockedAssetManager);
    when(Typeface.createFromAsset(mMockedAssetManager, ASSET_PATH)).thenThrow(new RuntimeException());
    when(Log.e(anyString(), anyString())).thenReturn(1);

    Typeface typeface = mTypeFaceProvider.getTypeFaceFromAssets(ASSET_PATH);
    PowerMockito.verifyStatic(times(2));
    assert (typeface == null);
    PowerMockito.verifyNoMoreInteractions();
}
 
Example 16
Source File: DefaultTypeFaceProviderTest.java    From CoachMarks with Apache License 2.0 5 votes vote down vote up
@Test
public void getTypeFaceFromAssetsTest() throws Exception {
    PowerMockito.mockStatic(Typeface.class);
    when(mMockContext.getAssets()).thenReturn(mMockedAssetManager);
    when(Typeface.createFromAsset(mMockedAssetManager, ASSET_PATH)).thenReturn(mMockedTypeFace);

    Typeface typeface = mTypeFaceProvider.getTypeFaceFromAssets(ASSET_PATH);
    PowerMockito.verifyStatic(times(1));
    assert (typeface == mMockedTypeFace);
    PowerMockito.verifyNoMoreInteractions();
}
 
Example 17
Source File: PcapHelperTest.java    From opensoc-streaming with Apache License 2.0 5 votes vote down vote up
/**
 * Input time is in SECONDS and data creation time is in MICROS.
 */
@Test
public void test_convertToDataCreationTimeUnit_() {
  PowerMockito.when(PcapHelper.getDataCreationTimeUnit()).thenReturn(
      TimeUnit.MICROS);
  PowerMockito.verifyNoMoreInteractions();

  long endTime = (long) 111.333; // input time in seconds (double to long type
                                 // casting)
  long time = PcapHelper.convertToDataCreationTimeUnit(endTime);

  Assert.isTrue(111000000L == time);
}
 
Example 18
Source File: Slf4jMdcDelegationTest.java    From tracee with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void removeDoesNotRemoveUnregisteredKeysFromMDC() {
	unit.remove("A");
	PowerMockito.verifyNoMoreInteractions(MDC.class);
}
 
Example 19
Source File: SecureLoginTest.java    From pxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testLoginKerberosSameServerDifferentPrincipal() throws IOException {
    PowerMockito.mockStatic(PxfUserGroupInformation.class);
    expectedUGI = UserGroupInformation.createUserForTesting("some", new String[]{});

    expectedLoginSession = new LoginSession("config", "principal", "/path/to/keytab", expectedUGI, null, 0);

    configuration.set("hadoop.security.authentication", "kerberos");
    configuration.set(PROPERTY_KEY_SERVICE_PRINCIPAL, "principal");
    configuration.set(PROPERTY_KEY_SERVICE_KEYTAB, "/path/to/keytab");
    configuration.set("hadoop.kerberos.min.seconds.before.relogin", "90");
    when(PxfUserGroupInformation.loginUserFromKeytab(configuration, "server", "config", "principal", "/path/to/keytab")).thenReturn(expectedLoginSession);

    UserGroupInformation loginUGI = secureLogin.getLoginUser("server", "config", configuration);

    LoginSession loginSession = SecureLogin.getCache().get("server");
    assertEquals(1, SecureLogin.getCache().size());
    assertEquals(expectedLoginSession, loginSession);
    assertSame(loginUGI, loginSession.getLoginUser());
    assertSame(expectedUGI, loginUGI); // since actual login was mocked, we should get back whatever we mocked

    // ------------------- now change the principal in the configuration, login again -------------------------

    LoginSession expectedDiffLoginSession = new LoginSession("config", "diff-principal", "/path/to/keytab", expectedUGI, null, 90000);
    Configuration diffConfiguration = new Configuration();
    diffConfiguration.set("hadoop.security.authentication", "kerberos");
    diffConfiguration.set(PROPERTY_KEY_SERVICE_PRINCIPAL, "diff-principal");
    diffConfiguration.set(PROPERTY_KEY_SERVICE_KEYTAB, "/path/to/keytab");
    diffConfiguration.set("hadoop.kerberos.min.seconds.before.relogin", "180");
    when(PxfUserGroupInformation.loginUserFromKeytab(configuration, "server", "config", "principal", "/path/to/keytab")).thenReturn(expectedLoginSession);
    when(PxfUserGroupInformation.loginUserFromKeytab(diffConfiguration, "server", "config", "diff-principal", "/path/to/keytab")).thenReturn(expectedDiffLoginSession);
    when(PxfUserGroupInformation.getKerberosMinMillisBeforeRelogin("server", diffConfiguration)).thenReturn(180000L);

    UserGroupInformation diffLoginUGI = secureLogin.getLoginUser("server", "config", diffConfiguration);

    LoginSession diffLoginSession = SecureLogin.getCache().get("server");
    assertEquals(1, SecureLogin.getCache().size());
    assertEquals(expectedDiffLoginSession, diffLoginSession);
    assertSame(loginUGI, diffLoginSession.getLoginUser());
    assertSame(expectedUGI, diffLoginUGI); // since actual login was mocked, we should get back whatever we mocked
    assertNotSame(loginSession, diffLoginSession); // should be different object

    // verify static calls issued
    PowerMockito.verifyStatic();
    PxfUserGroupInformation.loginUserFromKeytab(configuration, "server", "config", "principal", "/path/to/keytab");
    PowerMockito.verifyStatic();
    PxfUserGroupInformation.reloginFromKeytab("server", expectedLoginSession);

    PowerMockito.verifyStatic();
    PxfUserGroupInformation.loginUserFromKeytab(diffConfiguration, "server", "config", "diff-principal", "/path/to/keytab");
    PowerMockito.verifyStatic(times(2));
    PxfUserGroupInformation.getKerberosMinMillisBeforeRelogin("server", diffConfiguration);
    PowerMockito.verifyStatic();
    PxfUserGroupInformation.reloginFromKeytab("server", expectedDiffLoginSession);

    PowerMockito.verifyNoMoreInteractions(PxfUserGroupInformation.class);
}
 
Example 20
Source File: SecureLoginTest.java    From pxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testLoginKerberosDifferentServer() throws IOException {
    PowerMockito.mockStatic(PxfUserGroupInformation.class);
    expectedUGI = UserGroupInformation.createUserForTesting("some", new String[]{});

    expectedLoginSession = new LoginSession("config", "principal", "/path/to/keytab", expectedUGI, null, 0);

    configuration.set("hadoop.security.authentication", "kerberos");
    configuration.set(PROPERTY_KEY_SERVICE_PRINCIPAL, "principal");
    configuration.set(PROPERTY_KEY_SERVICE_KEYTAB, "/path/to/keytab");
    when(PxfUserGroupInformation.loginUserFromKeytab(configuration, "server", "config", "principal", "/path/to/keytab")).thenReturn(expectedLoginSession);

    UserGroupInformation loginUGI = secureLogin.getLoginUser("server", "config", configuration);

    LoginSession loginSession = SecureLogin.getCache().get("server");
    assertEquals(1, SecureLogin.getCache().size());
    assertEquals(expectedLoginSession, loginSession);
    assertSame(loginUGI, loginSession.getLoginUser());
    assertSame(expectedUGI, loginUGI); // since actual login was mocked, we should get back whatever we mocked


    // ------------------- now login for another server -------------------------

    LoginSession expectedDiffLoginSession = new LoginSession("diff-config", "principal", "/path/to/keytab", expectedUGI, null, 0);
    Configuration diffConfiguration = new Configuration();
    diffConfiguration.set("hadoop.security.authentication", "kerberos");
    diffConfiguration.set(PROPERTY_KEY_SERVICE_PRINCIPAL, "principal");
    diffConfiguration.set(PROPERTY_KEY_SERVICE_KEYTAB, "/path/to/keytab");
    when(PxfUserGroupInformation.loginUserFromKeytab(diffConfiguration, "diff-server", "diff-config", "principal", "/path/to/keytab")).thenReturn(expectedDiffLoginSession);

    UserGroupInformation diffLoginUGI = secureLogin.getLoginUser("diff-server", "diff-config", diffConfiguration);

    LoginSession diffLoginSession = SecureLogin.getCache().get("diff-server");
    assertEquals(2, SecureLogin.getCache().size());
    assertEquals(expectedDiffLoginSession, diffLoginSession);
    assertSame(loginUGI, diffLoginSession.getLoginUser());
    assertSame(expectedUGI, diffLoginUGI); // since actual login was mocked, we should get back whatever we mocked
    assertNotSame(loginSession, diffLoginSession); // should be different object

    // verify static calls issued
    PowerMockito.verifyStatic();
    PxfUserGroupInformation.loginUserFromKeytab(configuration, "server", "config", "principal", "/path/to/keytab");
    PowerMockito.verifyStatic();
    PxfUserGroupInformation.reloginFromKeytab("server", expectedLoginSession);

    PowerMockito.verifyStatic();
    PxfUserGroupInformation.loginUserFromKeytab(diffConfiguration, "diff-server", "diff-config", "principal", "/path/to/keytab");
    PowerMockito.verifyStatic();
    PxfUserGroupInformation.reloginFromKeytab("diff-server", expectedDiffLoginSession);

    PowerMockito.verifyNoMoreInteractions(PxfUserGroupInformation.class);
}