Java 类org.mockito.internal.verification.VerificationModeFactory 实例源码

项目:plugin-id-ldap    文件:GroupLdapRepositoryTest.java   
@Test
public void addUser() {
    final Set<String> users = new HashSet<>();
    final GroupLdapRepository groupRepository = new GroupLdapRepository() {
        @Override
        public GroupOrg findById(final String name) {
            return new GroupOrg("dc=" + name, name, users);
        }

    };
    final LdapCacheRepository cacheRepository = Mockito.mock(LdapCacheRepository.class);
    groupRepository.setLdapCacheRepository(cacheRepository);
    final LdapTemplate ldapTemplate = Mockito.mock(LdapTemplate.class);
    groupRepository.setTemplate(ldapTemplate);
    addUser(groupRepository);

    Mockito.verify(cacheRepository, VerificationModeFactory.times(1)).addUserToGroup(ArgumentMatchers.any(UserOrg.class),
            ArgumentMatchers.any(GroupOrg.class));
}
项目:plugin-iam-node    文件:NodeBasedIamProviderTest.java   
@Test
public void authenticateSecondaryAccept() throws Exception {
    final Authentication authentication = new UsernamePasswordAuthenticationToken("user1", "secret");
    final Authentication authentication2 = new UsernamePasswordAuthenticationToken("user1v2", "secret");
    final IdentityServicePlugin servicePlugin = Mockito.mock(IdentityServicePlugin.class);
    final NodeBasedIamProvider provider = new NodeBasedIamProvider();
    provider.configuration = configuration;
    provider.servicePluginLocator = Mockito.mock(ServicePluginLocator.class);
    Mockito.when(provider.servicePluginLocator.getResource("service:id:ldap:adu", IdentityServicePlugin.class))
            .thenReturn(servicePlugin);
    Mockito.when(servicePlugin.accept(authentication, "service:id:ldap:adu")).thenReturn(true);
    Mockito.when(servicePlugin.authenticate(authentication, "service:id:ldap:adu", false))
            .thenReturn(authentication2);
    Assert.assertSame(authentication2, provider.authenticate(authentication));
    Mockito.verify(provider.servicePluginLocator, VerificationModeFactory.times(0))
            .getResource("service:id:ldap:dig", IdentityServicePlugin.class);
}
项目:plugin-iam-node    文件:NodeBasedIamProviderTest.java   
@Test
public void authenticateSecondaryDontAccept() throws Exception {
    final Authentication authentication = new UsernamePasswordAuthenticationToken("user1", "secret");
    final Authentication authentication2 = new UsernamePasswordAuthenticationToken("user1v2", "secret");
    final IdentityServicePlugin servicePluginSecondary = Mockito.mock(IdentityServicePlugin.class);
    final IdentityServicePlugin servicePluginPrimary = Mockito.mock(IdentityServicePlugin.class);
    final NodeBasedIamProvider provider = new NodeBasedIamProvider();
    provider.configuration = configuration;
    provider.servicePluginLocator = Mockito.mock(ServicePluginLocator.class);
    Mockito.when(provider.servicePluginLocator.getResource("service:id:ldap:adu", IdentityServicePlugin.class))
            .thenReturn(servicePluginSecondary);
    Mockito.when(servicePluginPrimary.authenticate(authentication, "service:id:ldap:dig", true))
            .thenReturn(authentication2);
    Mockito.when(
            provider.servicePluginLocator.getResourceExpected("service:id:ldap:dig", IdentityServicePlugin.class))
            .thenReturn(servicePluginPrimary);
    Assert.assertSame(authentication2, provider.authenticate(authentication));
    Mockito.verify(servicePluginSecondary, VerificationModeFactory.times(0)).authenticate(authentication,
            "service:id:ldap:adu", false);
}
项目:bootstrap    文件:NotFoundResponseFilterTest.java   
@SuppressWarnings("rawtypes")
@Test
public void filter404SingleParameter() {
    final ContainerRequestContext requestContext = Mockito.mock(ContainerRequestContext.class);
    final ContainerResponseContext responseContext = Mockito.mock(ContainerResponseContext.class);
    Mockito.when(responseContext.getStatus()).thenReturn(204);
    final Annotation anno1 = Mockito.mock(Annotation.class);
    final Annotation anno2 = Mockito.mock(Annotation.class);
    final Annotation[] annotations = new Annotation[] { anno1, anno2 };
    Mockito.when((Class) anno2.annotationType()).thenReturn(OnNullReturn404.class);
    Mockito.when(responseContext.getEntityAnnotations()).thenReturn(annotations);

    final UriInfo uriInfo = Mockito.mock(UriInfo.class);
    final MultivaluedMap<String, String> parameters = new MultivaluedHashMap<>();
    parameters.putSingle("id", "2000");

    Mockito.when(uriInfo.getPathParameters()).thenReturn(parameters);
    Mockito.when(requestContext.getUriInfo()).thenReturn(uriInfo);
    filter.filter(requestContext, responseContext);
    Mockito.verify(responseContext, VerificationModeFactory.atLeastOnce()).setStatus(404);
    Mockito.verify(responseContext, VerificationModeFactory.atLeastOnce()).setEntity(
            "{\"code\":\"entity\",\"message\":\"2000\",\"parameters\":null,\"cause\":null}", annotations, MediaType.APPLICATION_JSON_TYPE);
}
项目:bootstrap    文件:NotFoundResponseFilterTest.java   
@SuppressWarnings("rawtypes")
@Test
public void filter404NoParameter() {
    final ContainerRequestContext requestContext = Mockito.mock(ContainerRequestContext.class);
    final ContainerResponseContext responseContext = Mockito.mock(ContainerResponseContext.class);
    Mockito.when(responseContext.getStatus()).thenReturn(204);
    final Annotation anno1 = Mockito.mock(Annotation.class);
    final Annotation anno2 = Mockito.mock(Annotation.class);
    final Annotation[] annotations = new Annotation[] { anno1, anno2 };
    Mockito.when((Class) anno2.annotationType()).thenReturn(OnNullReturn404.class);
    Mockito.when(responseContext.getEntityAnnotations()).thenReturn(annotations);

    final UriInfo uriInfo = Mockito.mock(UriInfo.class);
    final MultivaluedMap<String, String> parameters = new MultivaluedHashMap<>();

    Mockito.when(uriInfo.getPathParameters()).thenReturn(parameters);
    Mockito.when(requestContext.getUriInfo()).thenReturn(uriInfo);
    filter.filter(requestContext, responseContext);
    Mockito.verify(responseContext, VerificationModeFactory.atLeastOnce()).setStatus(404);
    Mockito.verify(responseContext, VerificationModeFactory.atLeastOnce())
            .setEntity("{\"code\":\"data\",\"message\":null,\"parameters\":null,\"cause\":null}", annotations, MediaType.APPLICATION_JSON_TYPE);
}
项目:jcredstash    文件:JCredStashTest.java   
@Test
public void testPutSecretNewVersion() {
    String version = "foover";
    final PutItemRequest[] putItemRequest = new PutItemRequest[1];
    Mockito.when(dynamoDBClient.putItem(Mockito.any(PutItemRequest.class))).thenAnswer(invocationOnMock -> {
        Object[] args = invocationOnMock.getArguments();
        putItemRequest[0] = (PutItemRequest) args[0];
        return new PutItemResult();
    });

    JCredStash credStash = new JCredStash(dynamoDBClient, awskmsClient);
    credStash.putSecret("table", "mysecret", "foo", "alias/foo", new HashMap<>(), version);

    Mockito.verify(dynamoDBClient, VerificationModeFactory.times(1)).putItem(Mockito.any(PutItemRequest.class));
    Assert.assertEquals(putItemRequest[0].getItem().get("version").getS(), version);
}
项目:jcredstash    文件:JCredStashTest.java   
@Test
public void testPutSecretAutoIncrementVersion() {
    final PutItemRequest[] putItemRequest = new PutItemRequest[1];
    Mockito.when(dynamoDBClient.putItem(Mockito.any(PutItemRequest.class))).thenAnswer(invocationOnMock -> {
        Object[] args = invocationOnMock.getArguments();
        putItemRequest[0] = (PutItemRequest) args[0];
        return new PutItemResult();
    });

    JCredStash credStash = Mockito.spy(new JCredStash(dynamoDBClient, awskmsClient));
    Mockito.doReturn(padVersion(1)).when(credStash).getHighestVersion("table", "mysecret");
    credStash.putSecret("table", "mysecret", "foo", "alias/foo", new HashMap<>());

    Mockito.verify(dynamoDBClient, VerificationModeFactory.times(1)).putItem(Mockito.any(PutItemRequest.class));
    Assert.assertEquals(putItemRequest[0].getItem().get("version").getS(), padVersion(2));
}
项目:jcredstash    文件:JCredStashTest.java   
@Test
public void testGetSecret() {
    final QueryRequest[] queryRequest = new QueryRequest[1];
    Mockito.when(dynamoDBClient.query(Mockito.any(QueryRequest.class))).thenAnswer(invocationOnMock -> {
        Object[] args = invocationOnMock.getArguments();
        queryRequest[0] = (QueryRequest) args[0];
        return new QueryResult().withCount(1).withItems(Arrays.asList(
                mockItem("mysecret", padVersion(1), new byte[]{}, new byte[]{}, new byte[]{})
        ));
    });


    JCredStash credStash = Mockito.spy(new JCredStash(dynamoDBClient, awskmsClient));

    Mockito.doReturn("foo").when(credStash).getSecret(Mockito.any(JCredStash.StoredSecret.class), Mockito.any(Map.class));

    String secret = credStash.getSecret("table", "mysecret", new HashMap<>());

    Mockito.verify(dynamoDBClient, VerificationModeFactory.times(1)).query(Mockito.any(QueryRequest.class));
    Assert.assertEquals("foo", secret);
}
项目:jcredstash    文件:JCredStashTest.java   
@Test
public void testGetSecretWithVersion() {
    final GetItemRequest[] getItemRequest = new GetItemRequest[1];
    Mockito.when(dynamoDBClient.getItem(Mockito.any(GetItemRequest.class))).thenAnswer(invocationOnMock -> {
        Object[] args = invocationOnMock.getArguments();
        getItemRequest[0] = (GetItemRequest) args[0];
        return new GetItemResult();
    });

    JCredStash credStash = Mockito.spy(new JCredStash(dynamoDBClient, awskmsClient));
    Mockito.doReturn("foo").when(credStash).getSecret(Mockito.any(JCredStash.StoredSecret.class), Mockito.any(Map.class));

    credStash.getSecret("table", "mysecret", new HashMap<>(), padVersion(1));

    Mockito.verify(dynamoDBClient, VerificationModeFactory.times(1)).getItem(Mockito.any(GetItemRequest.class));
    Assert.assertEquals(getItemRequest[0].getKey().get("version").getS(), padVersion(1));
}
项目:Auth0.Android    文件:CustomTabsControllerTest.java   
@Test
public void shouldLaunchUriWithFallbackIfCustomTabIntentFails() throws Exception {
    doThrow(ActivityNotFoundException.class)
            .doNothing()
            .when(context).startActivity(any(Intent.class));
    controller.launchUri(uri);

    verify(context, new Timeout(MAX_TEST_WAIT_TIME_MS, VerificationModeFactory.times(2))).startActivity(launchIntentCaptor.capture());
    List<Intent> intents = launchIntentCaptor.getAllValues();

    Intent customTabIntent = intents.get(0);
    assertThat(customTabIntent.getAction(), is(Intent.ACTION_VIEW));
    assertThat(customTabIntent.getData(), is(uri));
    assertThat(customTabIntent, not(hasFlag(Intent.FLAG_ACTIVITY_NO_HISTORY)));
    assertThat(customTabIntent.hasExtra(CustomTabsIntent.EXTRA_SESSION), is(true));
    assertThat(customTabIntent.hasExtra(CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE), is(true));
    assertThat(customTabIntent.hasExtra(CustomTabsIntent.EXTRA_TOOLBAR_COLOR), is(false));
    assertThat(customTabIntent.getIntExtra(CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE, CustomTabsIntent.NO_TITLE), is(CustomTabsIntent.NO_TITLE));

    Intent fallbackIntent = intents.get(1);
    assertThat(fallbackIntent.getAction(), is(Intent.ACTION_VIEW));
    assertThat(fallbackIntent.getData(), is(uri));
    assertThat(fallbackIntent, hasFlag(Intent.FLAG_ACTIVITY_NO_HISTORY));
    assertThat(fallbackIntent.hasExtra(CustomTabsIntent.EXTRA_SESSION), is(false));
    assertThat(fallbackIntent.hasExtra(CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE), is(false));
}
项目:hamcrest-nextdeed    文件:WaitFunctionTest.java   
@Test
public void without_predicate_accept_any_value_immediately() throws Exception {
  WaitFunction<Void, String>
      waitFunction =
      (WaitFunction<Void, String>) WaitFunction
          .waitFor(new Function<Void, String>() {
            @Override
            public String apply(Void input) {
              return testName.getMethodName();
            }
          })
          .get();
  WaitFunction<Void, String> spy = Mockito.spy(waitFunction);

  String result = spy.apply(null);

  assertThat(result, Matchers.equalTo(testName.getMethodName()));
  // Sleep not expected because of immediate success.
  Mockito.verify(spy, VerificationModeFactory.atMost(0)).sleep(Mockito.anyLong());
}
项目:FinanceAnalytics    文件:MarketDataProviderWithOverrideTest.java   
public void testSubscriptionSuccess() throws InterruptedException {
  final MarketDataInjectorImpl overrideInjector = new MarketDataInjectorImpl();
  final MockMarketDataProvider p1 = new MockMarketDataProvider("p1", true, 1);
  final MarketDataProviderWithOverride provider = new MarketDataProviderWithOverride(p1, overrideInjector);
  final MarketDataListener listener = mock(MarketDataListener.class);
  provider.addListener(listener);

  final ValueSpecification spec = getSpecification(1);

  provider.subscribe(spec);
  p1.awaitSubscriptionResponses();

  verify(listener).subscriptionsSucceeded(Collections.singleton(spec));
  verify(listener, VerificationModeFactory.noMoreInteractions()).subscriptionsSucceeded(Collections.singleton(Mockito.<ValueSpecification>anyObject()));

  p1.valuesChanged(Collections.singleton(spec));
  verify(listener, VerificationModeFactory.times(1)).valuesChanged(Collections.singleton(spec));
}
项目:vso-intellij    文件:StatusBarManagerTest.java   
@Test
public void testProjectOpenedEvent_RiderVsts() {
    when(applicationNamesInfo.getProductName()).thenReturn(IdeaHelper.RIDER_PRODUCT_NAME);
    PowerMockito.mockStatic(ApplicationNamesInfo.class);
    when(ApplicationNamesInfo.getInstance()).thenReturn(applicationNamesInfo);
    when(VcsHelper.isVstsRepo(project)).thenReturn(true);

    StatusBarManager.setupStatusBar();
    Map<String, Object> map = EventContextHelper.createContext(EventContextHelper.SENDER_PROJECT_OPENED);
    EventContextHelper.setProject(map, project);
    ServerEventManager.getInstance().triggerAllEvents(map);
    verify(statusBar, VerificationModeFactory.times(1)).addWidget(any(BuildWidget.class), Matchers.eq(project));
    buildStatusLookupOperation.onLookupStarted();
    buildStatusLookupOperation.onLookupResults(new BuildStatusLookupOperation.BuildStatusResults(
            new ServerContextBuilder().uri("https://test.visualstudio.com/").type(ServerContext.Type.VSO).build(),
            new ArrayList<BuildStatusLookupOperation.BuildStatusRecord>()));
    verify(statusBar, VerificationModeFactory.times(1)).updateWidget(anyString());
}
项目:vso-intellij    文件:StatusBarManagerTest.java   
@Test
public void testRepoChangedEvent_afterProjectOpened() {
    StatusBarManager.setupStatusBar();
    Map<String, Object> map = EventContextHelper.createContext(EventContextHelper.SENDER_PROJECT_OPENED);
    EventContextHelper.setProject(map, project);
    ServerEventManager.getInstance().triggerAllEvents(map);
    verify(statusBar, VerificationModeFactory.times(1)).addWidget(any(BuildWidget.class), Matchers.eq(project));
    buildStatusLookupOperation.onLookupStarted();
    buildStatusLookupOperation.onLookupResults(new BuildStatusLookupOperation.BuildStatusResults(
            new ServerContextBuilder().uri("https://test.visualstudio.com/").type(ServerContext.Type.VSO).build(),
            new ArrayList<BuildStatusLookupOperation.BuildStatusRecord>()));
    verify(statusBar, VerificationModeFactory.times(1)).updateWidget(anyString());

    // Now close the project
    Map<String, Object> map2 = EventContextHelper.createContext(EventContextHelper.SENDER_PROJECT_CLOSING);
    EventContextHelper.setProject(map2, project);
    ServerEventManager.getInstance().triggerAllEvents(map2);
    verify(statusBar, VerificationModeFactory.times(1)).removeWidget(anyString());
}
项目:teiid    文件:TestXAConnection.java   
@Test public void testConnectionClose() throws Exception {

        final ConnectionImpl mmConn = TestConnection.getMMConnection();

        XAConnectionImpl xaConn = new XAConnectionImpl(mmConn);

        Connection conn = xaConn.getConnection();
        StatementImpl stmt = (StatementImpl)conn.createStatement();
        conn.setAutoCommit(false);
        conn.close();

        ServerConnection sc = xaConn.getConnectionImpl().getServerConnection();
        Mockito.verify(sc, VerificationModeFactory.times(1)).cleanUp();

        assertTrue(stmt.isClosed());
        assertTrue(conn.getAutoCommit());

        conn = xaConn.getConnection();
        stmt = (StatementImpl)conn.createStatement();
        XAResource resource = xaConn.getXAResource();
        resource.start(new XidImpl(1, new byte[0], new byte[0]), XAResource.TMNOFLAGS);
        conn.close();

        assertTrue(stmt.isClosed());
        assertTrue(conn.getAutoCommit());
    }
项目:astor    文件:MockitoCore.java   
public void verifyNoMoreInteractions(Object... mocks) {
    assertMocksNotEmpty(mocks);
    mockingProgress.validateState();
    for (Object mock : mocks) {
        try {
            if (mock == null) {
                reporter.nullPassedToVerifyNoMoreInteractions();
            }
            InvocationContainer invocations = mockUtil.getMockHandler(mock).getInvocationContainer();
            VerificationDataImpl data = new VerificationDataImpl(invocations, null);
            VerificationModeFactory.noMoreInteractions().verify(data);
        } catch (NotAMockException e) {
            reporter.notAMockPassedToVerifyNoMoreInteractions();
        }
    }
}
项目:astor    文件:MockHandlerTest.java   
@Test
public void shouldRemoveVerificationModeEvenWhenInvalidMatchers() throws Throwable {
    //given
    Invocation invocation = new InvocationBuilder().toInvocation();
    MockHandler handler = new MockHandler();
    handler.mockingProgress.verificationStarted(VerificationModeFactory.atLeastOnce());
    handler.matchersBinder = new MatchersBinder() {
        public InvocationMatcher bindMatchers(ArgumentMatcherStorage argumentMatcherStorage, Invocation invocation) {
            throw new InvalidUseOfMatchersException();
        }
    };

    try {
        //when
        handler.handle(invocation);

        //then
        fail();
    } catch (InvalidUseOfMatchersException e) {}

    assertNull(handler.mockingProgress.pullVerificationMode());
}
项目:astor    文件:MockitoCore.java   
public void verifyNoMoreInteractions(Object... mocks) {
    assertMocksNotEmpty(mocks);
    mockingProgress.validateState();
    for (Object mock : mocks) {
        try {
            if (mock == null) {
                reporter.nullPassedToVerifyNoMoreInteractions();
            }
            InvocationContainer invocations = mockUtil.getMockHandler(mock).getInvocationContainer();
            VerificationDataImpl data = new VerificationDataImpl(invocations, null);
            VerificationModeFactory.noMoreInteractions().verify(data);
        } catch (NotAMockException e) {
            reporter.notAMockPassedToVerifyNoMoreInteractions();
        }
    }
}
项目:astor    文件:MockHandlerImplTest.java   
@Test
public void shouldRemoveVerificationModeEvenWhenInvalidMatchers() throws Throwable {
    // given
    Invocation invocation = new InvocationBuilder().toInvocation();
    @SuppressWarnings("rawtypes")
       MockHandlerImpl<?> handler = new MockHandlerImpl(new MockSettingsImpl());
    handler.mockingProgress.verificationStarted(VerificationModeFactory.atLeastOnce());
    handler.matchersBinder = new MatchersBinder() {
        public InvocationMatcher bindMatchers(ArgumentMatcherStorage argumentMatcherStorage, Invocation invocation) {
            throw new InvalidUseOfMatchersException();
        }
    };

    try {
        // when
        handler.handle(invocation);

        // then
        fail();
    } catch (InvalidUseOfMatchersException e) {
    }

    assertNull(handler.mockingProgress.pullVerificationMode());
}
项目:score    文件:ExecutionServiceTest.java   
@Test
public void handlePausedFlow_UserPausedTest() throws InterruptedException {
    final Long executionId = 111L;
    final String branch_id = null;

    Execution exe = getExecutionObjToPause(executionId, branch_id);

    ExecutionSummary execSummary = new ExecutionSummary();
    execSummary.setPauseReason(PauseReason.USER_PAUSED);
    execSummary.setStatus(ExecutionStatus.PENDING_PAUSE);
    when(workerConfigurationService.isExecutionPaused(executionId, branch_id)).thenReturn(true);
    when(pauseResumeService.readPausedExecution(executionId, branch_id)).thenReturn(execSummary);

    boolean result = executionService.handlePausedFlow(exe);

    Mockito.verify(pauseResumeService, VerificationModeFactory.times(1)).writeExecutionObject(executionId, branch_id, exe);
    Assert.assertTrue(result);
}
项目:score    文件:ExecutionServiceTest.java   
@Test
// branch is running, and parent is paused by the user -> branch should be paused
public void handlePausedFlow_UserPausedParentTest() throws InterruptedException {
    final Long executionId = 111L;
    final String branch_id = "branch_id";

    Execution exe = getExecutionObjToPause(executionId, branch_id);

    // branch is not paused
    ExecutionSummary branch = new ExecutionSummary();
    branch.setStatus(ExecutionStatus.RUNNING);
    when(workerConfigurationService.isExecutionPaused(executionId, branch_id)).thenReturn(false);

    // parent is paused
    ExecutionSummary parent = new ExecutionSummary();
    parent.setPauseReason(PauseReason.USER_PAUSED);
    parent.setStatus(ExecutionStatus.PENDING_PAUSE);
    when(workerConfigurationService.isExecutionPaused(executionId, null)).thenReturn(true);
    when(pauseResumeService.readPausedExecution(executionId, null)).thenReturn(parent);

    boolean result = executionService.handlePausedFlow(exe);

    Mockito.verify(pauseResumeService, VerificationModeFactory.times(1)).pauseExecution(executionId, branch_id, PauseReason.USER_PAUSED);
    Mockito.verify(pauseResumeService, VerificationModeFactory.times(1)).writeExecutionObject(executionId, branch_id, exe);
    Assert.assertTrue(result);
}
项目:helios-skydns    文件:SkyDnsServiceRegistrarTest.java   
@Test
public void testUnRegistrationNotRefreshedAnyMore() throws Exception {
  final SkyDnsServiceRegistrar registrar = makeRegistrar();
  when(client.set(ETCD_KEY, EXPECTED, TTL))
      .thenReturn(Futures.immediateFuture(response));

  final ServiceRegistrationHandle handle = registrar.register(
      new ServiceRegistration(ENDPOINTS));
  verify(client, timeout(WAIT_TIMEOUT)).set(ETCD_KEY, EXPECTED, TTL);

  when(client.delete(ETCD_KEY)).thenReturn(Futures.immediateFuture(response));
  registrar.unregister(handle);
  verify(client, timeout(WAIT_TIMEOUT)).delete(ETCD_KEY);

  Thread.sleep(2000);
  verify(client, VerificationModeFactory.noMoreInteractions()).set(ETCD_KEY, EXPECTED, TTL);
  registrar.close();
}
项目:hbase-indexer    文件:BatchStateUpdaterTest.java   
@Test
public void testRun_Running() throws Exception {
    String jobId = "job_201407251005_0815";
    createDefinition("mytest", jobId);
    RunningJob job = createJob(jobId, JobStatus.RUNNING);

    when(job.getJobState()).thenReturn(JobStatus.RUNNING);

    Assert.assertEquals(0, executorService.getQueue().size());
    checkAllIndexes();

    Assert.assertEquals(1, executorService.getQueue().size());
    verify(model, VerificationModeFactory.times(1)).getIndexer(anyString());
    verify(model, VerificationModeFactory.times(0)).updateIndexerInternal(any(IndexerDefinition.class));
    Thread.sleep(60);
    Assert.assertEquals(1, executorService.getQueue().size());
    verify(model, VerificationModeFactory.times(2)).getIndexer(anyString());
    verify(model, VerificationModeFactory.times(0)).updateIndexerInternal(any(IndexerDefinition.class));


    when(job.getJobState()).thenReturn(JobStatus.SUCCEEDED);
    Thread.sleep(60);
    Assert.assertEquals(0, executorService.getQueue().size());
    verify(model, VerificationModeFactory.times(3)).getIndexer(anyString());
    verify(model, VerificationModeFactory.times(1)).updateIndexerInternal(any(IndexerDefinition.class));
}
项目:plugin-id    文件:UserOrgResourceTest.java   
@Test
public void updatePassword() {
    resource.applicationContext = Mockito.mock(ApplicationContext.class);
    final IPasswordGenerator generator = Mockito.mock(IPasswordGenerator.class);
    Mockito.when(resource.applicationContext.getBeansOfType(IPasswordGenerator.class)).thenReturn(Collections.singletonMap("bean", generator));
    resource.updatePassword(newUser());
    Mockito.verify(generator, VerificationModeFactory.atLeast(1)).generate("wuser");
}
项目:plugin-id    文件:UserOrgResourceTest.java   
@Test
public void resetPasswordByAdmin() {
    resource.applicationContext = Mockito.mock(ApplicationContext.class);
    final IPasswordGenerator generator = Mockito.mock(IPasswordGenerator.class);
    Mockito.when(resource.applicationContext.getBeansOfType(IPasswordGenerator.class)).thenReturn(Collections.singletonMap("bean", generator));
    resource.resetPasswordByAdmin(newUser());
    Mockito.verify(generator, VerificationModeFactory.atLeast(1)).generate("wuser");
}
项目:jcredstash    文件:JCredStashTest.java   
@Test
public void testPutSecretDefaultVersion() {
    final PutItemRequest[] putItemRequest = new PutItemRequest[1];
    Mockito.when(dynamoDBClient.putItem(Mockito.any(PutItemRequest.class))).thenAnswer(invocationOnMock -> {
        Object[] args = invocationOnMock.getArguments();
        putItemRequest[0] = (PutItemRequest) args[0];
        return new PutItemResult();
    });

    JCredStash credStash = new JCredStash(dynamoDBClient, awskmsClient);
    credStash.putSecret("table", "mysecret", "foo", "alias/foo", new HashMap<>(), null);

    Mockito.verify(dynamoDBClient, VerificationModeFactory.times(1)).putItem(Mockito.any(PutItemRequest.class));
    Assert.assertEquals(putItemRequest[0].getItem().get("version").getS(), padVersion(1));
}
项目:otinane    文件:UserServiceImplTest.java   
@Test
public void testAddUserSuccess() throws Exception{
    String username="qwertyui";
    String password="12345678";

    User user = new User();
    user.setUsername(username);
    user.setPasswordConfirm(password);
    user.setPassword(password);

    userService.save(user);

    Mockito.verify(userRepository, VerificationModeFactory.times(1)).save(Mockito.any(User.class));
    Mockito.reset(userRepository);
}
项目:otinane    文件:UserServiceImplTest.java   
@Test
public void testFindUserByUsername() throws Exception{
    String username = "qwertyui";

    userService.findByUsername(username);

    Mockito.verify(userRepository, VerificationModeFactory.times(1)).findByUsername(Mockito.anyString());
}
项目:otinane    文件:ItemServiceImplTest.java   
@Test
public void testAddItemSuccess() throws Exception{
    List<Item> items = new ArrayList<>();

    items.addAll(itemService.getAllItems());

    Mockito.verify(itemRepository, VerificationModeFactory.times(1)).GetAll();
    Mockito.reset(itemRepository);
}
项目:aet    文件:ComparisonResultsRouterTest.java   
@Override
@Test
public void closeConnections() throws Exception {
  tested.closeConnections();
  verify(session, VerificationModeFactory.times(1)).close();
  verify(consumer, VerificationModeFactory.times(1)).close();
  verify(sender, VerificationModeFactory.times(0)).close();
}
项目:aet    文件:CollectDispatcherTest.java   
@Override
@org.junit.Test
public void closeConnections() throws Exception {
  tested.closeConnections();
  verify(session, VerificationModeFactory.times(1)).close();
  verify(sender, VerificationModeFactory.times(1)).close();
}
项目:interface-it    文件:CommandLineMainTest.java   
@Test
public void execute_can_generate_child_and_parent() throws IOException {
    String[] args = givenSetupForParentChildGeneration();
    CommandLineMain.execute(args, out, generator, new ArgumentParser(args), reader, statsProvider);
    verify(generator).generateMixinJavaFiles(
            toStringContainsAllOf("OptionsForSplittingChildAndParent [" + "targetPackage=com.example, "
                    + "saveDirectory=., childMixinName=MockitoMixin, "
                    + "parentMixinName=MatchersMixin, childClass=class org.mockito.Mockito, "
                    + "getMethodFilter(class org.mockito.Mockito)=com.github.aro_tech.interface_it.api.options.OptionsForSplittingChildAndParent$$Lambda"),
            any(), eq(org.mockito.Mockito.class), eq(org.mockito.Matchers.class));
    verify(out, VerificationModeFactory.times(2)).println(startsWith("Wrote file: "));
    verify(out).println(containsAllOf("2 constants", "1 method"));
    verify(out).println(containsAllOf("1 constant", "7 methods"));
}
项目:FinanceAnalytics    文件:MarketDataProviderWithOverrideTest.java   
public void testSubscriptionFailure() throws InterruptedException {
  final MarketDataInjectorImpl overrideInjector = new MarketDataInjectorImpl();
  final MockMarketDataProvider p1 = new MockMarketDataProvider("p1", false, 1);
  final MarketDataProviderWithOverride provider = new MarketDataProviderWithOverride(p1, overrideInjector);
  final MarketDataListener listener = mock(MarketDataListener.class);
  provider.addListener(listener);

  final ValueSpecification spec = getSpecification(1);

  provider.subscribe(spec);
  p1.awaitSubscriptionResponses();

  verify(listener).subscriptionFailed(spec, "p1");
  verify(listener, VerificationModeFactory.noMoreInteractions()).subscriptionFailed(Mockito.<ValueSpecification>anyObject(), Mockito.anyString());
}
项目:vso-intellij    文件:StatusBarManagerTest.java   
@Test
public void testProjectOpenedEvent_NotRider() {
    StatusBarManager.setupStatusBar();
    Map<String, Object> map = EventContextHelper.createContext(EventContextHelper.SENDER_PROJECT_OPENED);
    EventContextHelper.setProject(map, project);
    ServerEventManager.getInstance().triggerAllEvents(map);
    verify(statusBar, VerificationModeFactory.times(1)).addWidget(any(BuildWidget.class), Matchers.eq(project));
    buildStatusLookupOperation.onLookupStarted();
    buildStatusLookupOperation.onLookupResults(new BuildStatusLookupOperation.BuildStatusResults(
            new ServerContextBuilder().uri("https://test.visualstudio.com/").type(ServerContext.Type.VSO).build(),
            new ArrayList<BuildStatusLookupOperation.BuildStatusRecord>()));
    verify(statusBar, VerificationModeFactory.times(1)).updateWidget(anyString());
}
项目:vso-intellij    文件:StatusBarManagerTest.java   
@Test
public void testProjectOpenedEvent_RiderNotVsts() {
    when(applicationNamesInfo.getProductName()).thenReturn(IdeaHelper.RIDER_PRODUCT_NAME);
    PowerMockito.mockStatic(ApplicationNamesInfo.class);
    when(ApplicationNamesInfo.getInstance()).thenReturn(applicationNamesInfo);
    when(VcsHelper.isVstsRepo(project)).thenReturn(false);
    when(statusBar.getWidget(anyString())).thenReturn(new BuildWidget());

    StatusBarManager.setupStatusBar();
    Map<String, Object> map = EventContextHelper.createContext(EventContextHelper.SENDER_PROJECT_OPENED);
    EventContextHelper.setProject(map, project);
    ServerEventManager.getInstance().triggerAllEvents(map);
    verify(statusBar, VerificationModeFactory.times(0)).addWidget(any(BuildWidget.class), Matchers.eq(project));
    verify(statusBar, VerificationModeFactory.times(1)).removeWidget(any(String.class));
}
项目:vso-intellij    文件:StatusBarManagerTest.java   
@Test
public void testRepoChangedEvent() {
    StatusBarManager.setupStatusBar();
    Map<String, Object> map = EventContextHelper.createContext(EventContextHelper.SENDER_REPO_CHANGED);
    EventContextHelper.setProject(map, project);
    ServerEventManager.getInstance().triggerAllEvents(map);
    verify(statusBar, VerificationModeFactory.times(1)).addWidget(any(BuildWidget.class), Matchers.eq(project));
    buildStatusLookupOperation.onLookupStarted();
    buildStatusLookupOperation.onLookupResults(new BuildStatusLookupOperation.BuildStatusResults(
            new ServerContextBuilder().uri("https://test.visualstudio.com/").type(ServerContext.Type.VSO).build(),
            new ArrayList<BuildStatusLookupOperation.BuildStatusRecord>()));
    verify(statusBar, VerificationModeFactory.times(1)).updateWidget(anyString());
}
项目:vso-intellij    文件:StatusBarManagerTest.java   
@Test
public void testProjectClosingEvent_noPreviousEvents() {
    StatusBarManager.setupStatusBar();
    Map<String, Object> map = EventContextHelper.createContext(EventContextHelper.SENDER_PROJECT_CLOSING);
    EventContextHelper.setProject(map, project);
    ServerEventManager.getInstance().triggerAllEvents(map);
    verify(statusBar, VerificationModeFactory.times(0)).addWidget(any(BuildWidget.class), Matchers.eq(project));
    verify(statusBar, VerificationModeFactory.times(0)).removeWidget(anyString());
}
项目:vso-intellij    文件:StatusBarManagerTest.java   
@Test
public void testUpdateStatusBar() {
    StatusBarManager.setupStatusBar();
    // An unknown sender should cause a call to UpdateStatusBar()
    Map<String, Object> map = EventContextHelper.createContext("TestSender");
    EventContextHelper.setProject(map, project);
    ServerEventManager.getInstance().triggerAllEvents(map);
    verify(statusBar, VerificationModeFactory.times(1)).addWidget(any(BuildWidget.class), Matchers.eq(project));
}
项目:slack-rtm-api    文件:SlackWebsocketConnectionTest.java   
@Test
public void testCreateWaitThreadAfterConnect() throws Exception {
    SlackAuthen slackAuthen = PowerMockito.mock(SlackAuthen.class);
    PowerMockito.whenNew(SlackAuthen.class).withNoArguments().thenReturn(slackAuthen);
    PowerMockito.when(slackAuthen.tokenAuthen(Mockito.anyString(), Mockito.anyString(), Mockito.anyInt())).thenReturn(slackInfo);

    ClientManager clientManager = PowerMockito.mock(ClientManager.class);
    PowerMockito.mockStatic(ClientManager.class);
    PowerMockito.when(ClientManager.createClient()).thenReturn(clientManager);

    SlackWebsocketConnection slackWebsocketConnection = PowerMockito.spy(new SlackWebsocketConnection("token", null, 8080));
    slackWebsocketConnection.connect();
    PowerMockito.doNothing().when(slackWebsocketConnection, "await");
    PowerMockito.verifyPrivate(slackWebsocketConnection, VerificationModeFactory.atLeastOnce()).invoke("await");
}