@Test public void testGetAllModules_multi() { Mockito.when(server.getModules()).thenReturn(new IModule[] {module1}); Mockito.when(server.getChildModules(any(IModule[].class), any(IProgressMonitor.class))) .thenReturn(new IModule[0]); Mockito.when(server.getChildModules(AdditionalMatchers.aryEq(new IModule[] {module1}), any(IProgressMonitor.class))).thenReturn(new IModule[] {module2a, module2b}); Mockito.when(server.getChildModules(AdditionalMatchers.aryEq(new IModule[] {module1, module2b}), any(IProgressMonitor.class))).thenReturn(new IModule[] {module3}); IModule[] result = ModuleUtils.getAllModules(server); Assert.assertNotNull(result); Assert.assertEquals(4, result.length); Assert.assertThat(result, IsArrayContainingInOrder.arrayContaining(module1, module2a, module2b, module3)); }
@Test @Parameters public void decorate_should_saveExpectedMeasureTotal_when_usingAnyMetric(final Metric<Integer> metric, final Collection<Measure> measures) { Mockito.when(this.context.getComponent()) .thenReturn(this.component); Mockito.when(this.component.getType()) .thenReturn(Type.PROJECT); Mockito.when(this.context.getChildrenMeasures(Matchers.eq(metric.getKey()))) .thenReturn(measures); Mockito.when(this.context.getChildrenMeasures(AdditionalMatchers.not(Matchers.eq(metric.getKey())))) .thenReturn(null); final AbstractSmellMeasureComputer sut = sut(); sut.compute(this.context); Mockito.verify(this.context, Mockito.times(1)) .getComponent(); Mockito.verify(this.context, Mockito.times(1)) .getChildrenMeasures(Matchers.eq(metric.getKey())); Mockito.verify(this.context, Mockito.times(1)) .addMeasure(Matchers.eq(metric.getKey()), Matchers.eq(3)); Mockito.verify(this.context, Mockito.times(sut.getInputMetricsKeys() .size() - 1)) .addMeasure(AdditionalMatchers.not(Matchers.eq(metric.getKey())), Matchers.eq(0)); }
@Test public void testNoRollOverNeeded() throws IOException{ final long startTime = 10000L; when(mockCurrentTimeProvider.getCurrentTimeMillis()).thenReturn(startTime); filesManager = new TestEventsFilesManager(RuntimeEnvironment.application, transform, mockCurrentTimeProvider, mockEventStorage, "testNoRollOverNeeded", EventsFilesManager.MAX_FILES_TO_KEEP); when(mockEventStorage.canWorkingFileStore(anyInt(), anyInt())) .thenReturn(true); filesManager.writeEvent(testEvent); verify(mockEventStorage).add(AdditionalMatchers.aryEq(transform.toBytes(testEvent))); verify(mockEventStorage).canWorkingFileStore(anyInt(), anyInt()); verify(mockCurrentTimeProvider, times(1)).getCurrentTimeMillis(); assertEquals("roll over time should NOT have been updated", startTime, filesManager.getLastRollOverTime()); }
@Test public void testDeliverGCRefresh() throws Exception { // setup GCIdSet idSet = mock(GCIdSet.class); when(idSet.numElements()).thenReturn(1); GCId id = mock(GCId.class); when(idSet.asArray()).thenReturn(new GCId[] { id }); message = new GCRefreshMessage(0, idSet, null, null); // act koalaGCPastImpl.deliver(null, message); // assert verify(continuation).receiveResult(AdditionalMatchers.aryEq(new Boolean[] { Boolean.TRUE })); verify(storageManager, never()).exists((Id) anyObject()); }
@Test public void testDelSelectionsJob() { JobMeta jobMeta = mock( JobMeta.class ); Spoon spoon = mock( Spoon.class ); JobEntryCopy selected1 = mock( JobEntryCopy.class ); JobEntryCopy selected2 = mock( JobEntryCopy.class ); when( jobMeta.getSelectedEntries() ).thenReturn( Arrays.asList( selected1, selected2 ) ); JobGraph jobGraph = mock( JobGraph.class ); doCallRealMethod().when( jobGraph ).setJobMeta( any( JobMeta.class ) ); doCallRealMethod().when( jobGraph ).setSpoon( any( Spoon.class ) ); doCallRealMethod().when( jobGraph ).delSelected( any( JobEntryCopy.class ) ); jobGraph.setJobMeta( jobMeta ); jobGraph.setSpoon( spoon ); jobGraph.delSelected( null ); verify( spoon ).deleteJobEntryCopies( eq( jobMeta ), AdditionalMatchers.aryEq( new JobEntryCopy[] { selected1, selected2 } ) ); }
@BeforeClass public static void setUp() throws Exception { userDAO = Mockito.mock(UserDAO.class); groupDAO = Mockito.mock(GroupDAO.class); rolesDAO = Mockito.mock(RolesDAO.class); permissionsDAO = Mockito.mock(PermissionDAO.class); userProfileController = Mockito.mock(UserProfileController.class); List<User> validUsers = new ArrayList<>(); validUsers.add(new User()); Group validGroup = new Group(VALID_GROUP_NAME); validGroup.setId(1); Mockito.when(rolesDAO.find( AdditionalMatchers.not(Matchers.eq(INVALID_ROLE_ID)))). thenReturn(Optional.fromNullable(new Role(ROLE_NAME))); Mockito.when(permissionsDAO.find( AdditionalMatchers.not(Matchers.eq(INVALID_Permission_ID)))). thenReturn(Optional.fromNullable(new Permission(PERMISSION_NAME))); Mockito.when(permissionsDAO.find(INVALID_Permission_ID)).thenReturn(Optional.absent()); Mockito.when(rolesDAO.find(INVALID_ROLE_ID)).thenReturn(Optional.absent()); Mockito.when(groupDAO.findByName(DUPLICATE_NAME)).thenReturn(new Group()); Mockito.when(groupDAO.save(Matchers.any())).thenReturn(validGroup); Mockito.when(userDAO.findUsersWithRole(Matchers.anyInt())).thenReturn(validUsers); Mockito.when(userDAO.findUsersWithPermissionLevel(Matchers.anyInt())).thenReturn(validUsers); Mockito.when(groupDAO.findByName(VALID_GROUP_NAME)).thenReturn(null); controller = new GroupController(groupDAO,userDAO,rolesDAO,permissionsDAO, userProfileController); }
@BeforeClass public static void setUp() throws Exception { filterDAO = Mockito.mock(FilterDAO.class); rolesDAO = Mockito.mock(RolesDAO.class); permissionsDAO = Mockito.mock(PermissionDAO.class); Filter validFilter = new Filter(VALID_FILTER_NAME); validFilter.setId(1); Mockito.when(rolesDAO.find( AdditionalMatchers.not(Matchers.eq(INVALID_ROLE_ID)))). thenReturn(Optional.fromNullable(new Role(ROLE_NAME))); Mockito.when(permissionsDAO.find( AdditionalMatchers.not(Matchers.eq(INVALID_Permission_ID)))). thenReturn(Optional.fromNullable(new Permission(PERMISSION_NAME))); Mockito.when(permissionsDAO.find(INVALID_Permission_ID)).thenReturn(Optional.absent()); Mockito.when(rolesDAO.find(INVALID_ROLE_ID)).thenReturn(Optional.absent()); Mockito.when(filterDAO.findByName(DUPLICATE_NAME)).thenReturn(new Filter()); Mockito.when(filterDAO.save(Matchers.any())).thenReturn(validFilter); Mockito.when(filterDAO.findByName(VALID_FILTER_NAME)).thenReturn(null); controller = new FilterController(filterDAO,rolesDAO,permissionsDAO); }
@Test public void testCommitAnalysisWithNewIssues() { settings.setProperty(GitLabPlugin.GITLAB_ONLY_ISSUE_FROM_COMMIT_FILE, false); DefaultInputFile inputFile1 = new DefaultInputFile("foo", "src/Foo.php"); PostJobIssue newIssue = Utils.newMockedIssue("foo:src/Foo.php", inputFile1, 1, Severity.BLOCKER, true, "msg1"); Mockito.when(commitFacade.getGitLabUrl(null, inputFile1, 1)).thenReturn("http://gitlab/blob/abc123/src/Foo.php#L1"); Mockito.when(commitFacade.getRuleLink("repo:rule")).thenReturn("http://myserver/coding_rules#rule_key=repo%3Arule"); PostJobIssue lineNotVisible = Utils.newMockedIssue("foo:src/Foo.php", inputFile1, 2, Severity.BLOCKER, true, "msg2"); Mockito.when(commitFacade.getGitLabUrl(null, inputFile1, 2)).thenReturn("http://gitlab/blob/abc123/src/Foo.php#L2"); DefaultInputFile inputFile2 = new DefaultInputFile("foo", "src/Foo2.php"); PostJobIssue fileNotInPR = Utils.newMockedIssue("foo:src/Foo2.php", inputFile2, 1, Severity.BLOCKER, true, "msg3"); PostJobIssue notNewIssue = Utils.newMockedIssue("foo:src/Foo.php", inputFile1, 1, Severity.BLOCKER, false, "msg"); PostJobIssue issueOnDir = Utils.newMockedIssue("foo:src", Severity.BLOCKER, true, "msg4"); PostJobIssue issueOnProject = Utils.newMockedIssue("foo", Severity.BLOCKER, true, "msg"); PostJobIssue globalIssue = Utils.newMockedIssue("foo:src/Foo.php", inputFile1, null, Severity.BLOCKER, true, "msg5"); Mockito.when(context.issues()).thenReturn(Arrays.asList(newIssue, globalIssue, issueOnProject, issueOnDir, fileNotInPR, lineNotVisible, notNewIssue)); Mockito.when(commitFacade.hasFile(inputFile1)).thenReturn(true); Mockito.when(commitFacade.getRevisionForLine(inputFile1, 1)).thenReturn("abc123"); commitIssuePostJob.execute(context); Mockito.verify(commitFacade).addGlobalComment(Mockito.contains("SonarQube analysis reported 6 issues")); Mockito.verify(commitFacade).addGlobalComment(Mockito.contains("* :no_entry: 6 blocker")); Mockito.verify(commitFacade).addGlobalComment(AdditionalMatchers.not(Mockito.contains("1. [Project"))); Mockito.verify(commitFacade).addGlobalComment(Mockito.contains("1. :no_entry: [msg2](http://gitlab/blob/abc123/src/Foo.php#L2) [:blue_book:](http://myserver/coding_rules#rule_key=repo%3Arule)")); Mockito.verify(commitFacade).createOrUpdateSonarQubeStatus("failed", "SonarQube reported 6 issues, with 6 blocker (fail)"); }
@Test public void testCommitAnalysisWithNewIssuesOnly() { settings.setProperty(GitLabPlugin.GITLAB_ONLY_ISSUE_FROM_COMMIT_FILE, true); DefaultInputFile inputFile1 = new DefaultInputFile("foo", "src/Foo.php"); PostJobIssue newIssue = Utils.newMockedIssue("foo:src/Foo.php", inputFile1, 1, Severity.BLOCKER, true, "msg1"); Mockito.when(commitFacade.getGitLabUrl(null, inputFile1, 1)).thenReturn("http://gitlab/blob/abc123/src/Foo.php#L1"); Mockito.when(commitFacade.getRuleLink("repo:rule")).thenReturn("http://myserver/coding_rules#rule_key=repo%3Arule"); PostJobIssue lineNotVisible = Utils.newMockedIssue("foo:src/Foo.php", inputFile1, 2, Severity.BLOCKER, true, "msg2"); Mockito.when(commitFacade.getGitLabUrl(null, inputFile1, 2)).thenReturn("http://gitlab/blob/abc123/src/Foo.php#L2"); DefaultInputFile inputFile2 = new DefaultInputFile("foo", "src/Foo2.php"); PostJobIssue fileNotInPR = Utils.newMockedIssue("foo:src/Foo2.php", inputFile2, 1, Severity.BLOCKER, true, "msg3"); PostJobIssue notNewIssue = Utils.newMockedIssue("foo:src/Foo.php", inputFile1, 1, Severity.BLOCKER, false, "msg"); PostJobIssue issueOnDir = Utils.newMockedIssue("foo:src", Severity.BLOCKER, true, "msg4"); PostJobIssue issueOnProject = Utils.newMockedIssue("foo", Severity.BLOCKER, true, "msg"); PostJobIssue globalIssue = Utils.newMockedIssue("foo:src/Foo.php", inputFile1, null, Severity.BLOCKER, true, "msg5"); Mockito.when(context.issues()).thenReturn(Arrays.asList(newIssue, globalIssue, issueOnProject, issueOnDir, fileNotInPR, lineNotVisible, notNewIssue)); Mockito.when(commitFacade.hasFile(inputFile1)).thenReturn(true); Mockito.when(commitFacade.getRevisionForLine(inputFile1, 1)).thenReturn("abc123"); commitIssuePostJob.execute(context); Mockito.verify(commitFacade).addGlobalComment(Mockito.contains("SonarQube analysis reported 5 issues")); Mockito.verify(commitFacade).addGlobalComment(Mockito.contains("* :no_entry: 5 blocker")); Mockito.verify(commitFacade).addGlobalComment(AdditionalMatchers.not(Mockito.contains("1. [Project"))); Mockito.verify(commitFacade) .addGlobalComment(Mockito.contains("1. :no_entry: [msg2](http://gitlab/blob/abc123/src/Foo.php#L2) [:blue_book:](http://myserver/coding_rules#rule_key=repo%3Arule)")); Mockito.verify(commitFacade).createOrUpdateReviewComment("abc123", inputFile1, 1, ":no_entry: msg1 [:blue_book:](http://myserver/coding_rules#rule_key=repo%3Arule)"); Mockito.verify(commitFacade).createOrUpdateSonarQubeStatus("failed", "SonarQube reported 5 issues, with 5 blocker (fail)"); }
@Test public void testCommitAnalysisWithNewIssuesOnlyLine() { settings.setProperty(GitLabPlugin.GITLAB_ONLY_ISSUE_FROM_COMMIT_LINE, true); DefaultInputFile inputFile1 = new DefaultInputFile("foo", "src/Foo.php"); PostJobIssue newIssue = Utils.newMockedIssue("foo:src/Foo.php", inputFile1, 1, Severity.BLOCKER, true, "msg1"); Mockito.when(commitFacade.getGitLabUrl(null, inputFile1, 1)).thenReturn("http://gitlab/blob/abc123/src/Foo.php#L1"); Mockito.when(commitFacade.getRuleLink("repo:rule")).thenReturn("http://myserver/coding_rules#rule_key=repo%3Arule"); PostJobIssue lineNotVisible = Utils.newMockedIssue("foo:src/Foo.php", inputFile1, 2, Severity.BLOCKER, true, "msg2"); Mockito.when(commitFacade.getGitLabUrl(null, inputFile1, 2)).thenReturn("http://gitlab/blob/abc123/src/Foo.php#L2"); DefaultInputFile inputFile2 = new DefaultInputFile("foo", "src/Foo2.php"); PostJobIssue fileNotInPR = Utils.newMockedIssue("foo:src/Foo2.php", inputFile2, 1, Severity.BLOCKER, true, "msg3"); PostJobIssue notNewIssue = Utils.newMockedIssue("foo:src/Foo.php", inputFile1, 1, Severity.BLOCKER, false, "msg"); PostJobIssue issueOnDir = Utils.newMockedIssue("foo:src", Severity.BLOCKER, true, "msg4"); PostJobIssue issueOnProject = Utils.newMockedIssue("foo", Severity.BLOCKER, true, "msg"); PostJobIssue globalIssue = Utils.newMockedIssue("foo:src/Foo.php", inputFile1, null, Severity.BLOCKER, true, "msg5"); Mockito.when(context.issues()).thenReturn(Arrays.asList(newIssue, globalIssue, issueOnProject, issueOnDir, fileNotInPR, lineNotVisible, notNewIssue)); Mockito.when(commitFacade.hasFile(inputFile1)).thenReturn(true); Mockito.when(commitFacade.getRevisionForLine(inputFile1, 1)).thenReturn("abc123"); commitIssuePostJob.execute(context); Mockito.verify(commitFacade).addGlobalComment(Mockito.contains("SonarQube analysis reported 1 issue")); Mockito.verify(commitFacade).addGlobalComment(Mockito.contains("* :no_entry: 1 blocker")); Mockito.verify(commitFacade).addGlobalComment(AdditionalMatchers.not(Mockito.contains("1. [Project"))); Mockito.verify(commitFacade) .addGlobalComment(AdditionalMatchers.not(Mockito.contains("1. :no_entry: [msg2](http://gitlab/blob/abc123/src/Foo.php#L2) [:blue_book:](http://myserver/coding_rules#rule_key=repo%3Arule)"))); Mockito.verify(commitFacade).createOrUpdateReviewComment("abc123", inputFile1, 1, ":no_entry: msg1 [:blue_book:](http://myserver/coding_rules#rule_key=repo%3Arule)"); Mockito.verify(commitFacade).createOrUpdateSonarQubeStatus("failed", "SonarQube reported 1 issue, with 1 blocker (fail)"); }
@Test public void testCommitAnalysisWithNewIssuesAllIssues() { settings.setProperty(GitLabPlugin.GITLAB_ALL_ISSUES, true); DefaultInputFile inputFile1 = new DefaultInputFile("foo", "src/Foo.php"); PostJobIssue newIssue = Utils.newMockedIssue("foo:src/Foo.php", inputFile1, 1, Severity.BLOCKER, true, "msg1"); Mockito.when(commitFacade.getGitLabUrl(null, inputFile1, 1)).thenReturn("http://gitlab/blob/abc123/src/Foo.php#L1"); Mockito.when(commitFacade.getRuleLink("repo:rule")).thenReturn("http://myserver/coding_rules#rule_key=repo%3Arule"); PostJobIssue lineNotVisible = Utils.newMockedIssue("foo:src/Foo.php", inputFile1, 2, Severity.BLOCKER, true, "msg2"); Mockito.when(commitFacade.getGitLabUrl(null, inputFile1, 2)).thenReturn("http://gitlab/blob/abc123/src/Foo.php#L2"); DefaultInputFile inputFile2 = new DefaultInputFile("foo", "src/Foo2.php"); PostJobIssue fileNotInPR = Utils.newMockedIssue("foo:src/Foo2.php", inputFile2, 1, Severity.BLOCKER, true, "msg3"); PostJobIssue notNewIssue = Utils.newMockedIssue("foo:src/Foo.php", inputFile1, 1, Severity.BLOCKER, false, "msg"); PostJobIssue issueOnDir = Utils.newMockedIssue("foo:src", Severity.BLOCKER, true, "msg4"); PostJobIssue issueOnProject = Utils.newMockedIssue("foo", Severity.BLOCKER, true, "msg"); PostJobIssue globalIssue = Utils.newMockedIssue("foo:src/Foo.php", inputFile1, null, Severity.BLOCKER, true, "msg5"); Mockito.when(context.issues()).thenReturn(Arrays.asList(newIssue, globalIssue, issueOnProject, issueOnDir, fileNotInPR, lineNotVisible, notNewIssue)); Mockito.when(commitFacade.hasFile(inputFile1)).thenReturn(true); Mockito.when(commitFacade.getRevisionForLine(inputFile1, 1)).thenReturn("abc123"); commitIssuePostJob.execute(context); Mockito.verify(commitFacade).addGlobalComment(Mockito.contains("SonarQube analysis reported 7 issues")); Mockito.verify(commitFacade).addGlobalComment(Mockito.contains("* :no_entry: 7 blocker")); Mockito.verify(commitFacade).addGlobalComment(AdditionalMatchers.not(Mockito.contains("1. [Project"))); Mockito.verify(commitFacade).addGlobalComment(Mockito.contains("1. :no_entry: [msg2](http://gitlab/blob/abc123/src/Foo.php#L2) [:blue_book:](http://myserver/coding_rules#rule_key=repo%3Arule)")); Mockito.verify(commitFacade).createOrUpdateSonarQubeStatus("failed", "SonarQube reported 7 issues, with 7 blocker (fail)"); }
@Test public void testProperCharsetUsed() throws IOException { when(mockAmqpBrokerConfig.getCharset()).thenReturn(Charset.forName("UTF-32")); String message = "ö"; byte[] expectedEncodedMessage = new byte[] { 0, 0, 0, -10 }; // In UTF-32 ö is mapped to 000000f6 AmqpProducerAdapter producerAdapter = new AmqpProducerAdapter("myTopic", ExchangeType.FANOUT, mockAmqpBrokerConfig, mockAmqpConnectionManager); producerAdapter.publish(message); verify(mockChannel).basicPublish(anyString(), anyString(), any(AMQP.BasicProperties.class), AdditionalMatchers.aryEq(expectedEncodedMessage)); }
@Test public void testSizeTriggeredRollOver() throws IOException{ final long startTime = 10000L; final long newMostRecentRollOverTime = 11500L; when(mockCurrentTimeProvider.getCurrentTimeMillis()) .thenReturn(startTime) .thenReturn(newMostRecentRollOverTime); filesManager = new TestEventsFilesManager(RuntimeEnvironment.application, transform, mockCurrentTimeProvider, mockEventStorage, "testSizeTriggeredRollOver", EventsFilesManager.MAX_FILES_TO_KEEP); when(mockEventStorage.canWorkingFileStore(anyInt(), anyInt())) .thenReturn(false); // Called during log message when(mockEventStorage.getWorkingFileUsedSizeInBytes()).thenReturn(10000); when(mockEventStorage.isWorkingFileEmpty()).thenReturn(false); filesManager.writeEvent(testEvent); verify(mockEventStorage).add(AdditionalMatchers.aryEq(transform.toBytes(testEvent))); verify(mockEventStorage).canWorkingFileStore(anyInt(), anyInt()); verify(mockEventStorage).getWorkingFileUsedSizeInBytes(); verify(mockEventStorage).isWorkingFileEmpty(); verify(mockEventStorage).rollOver(any(String.class)); verify(mockCurrentTimeProvider, times(2)).getCurrentTimeMillis(); assertEquals("roll over time should have been updated", newMostRecentRollOverTime, filesManager.getLastRollOverTime()); }
@Test public void testRampSampling() throws Exception { handler.handleMessage(null); MParticleApiClientImpl apiClient = Mockito.mock(MParticleApiClientImpl.class); MParticleApiClientImpl.MPRampException rampException = new MParticleApiClientImpl.MPRampException(); Mockito.when(apiClient.sendMessageBatch(Mockito.anyString())).thenThrow(rampException); handler.setApiClient(apiClient); handler.uploadMessage(522, ""); String[] params = {"522"}; Mockito.verify(mockDatabase, Mockito.times(1)).delete(Mockito.anyString(), Mockito.anyString(), AdditionalMatchers.aryEq(params)); }
@Test public void visitCOSName() throws Exception { COSName name = COSName.getPDFName("a()7"); InOrder inOrder = Mockito.inOrder(writer); victim.visit(name); inOrder.verify(writer).write((byte) 0x2F); inOrder.verify(writer).write((byte) 0x61); inOrder.verify(writer).write((byte) 0x23); inOrder.verify(writer).write(AdditionalMatchers.aryEq(new byte[] { 0x32, 0x38 })); inOrder.verify(writer).write((byte) 0x23); inOrder.verify(writer).write(AdditionalMatchers.aryEq(new byte[] { 0x32, 0x39 })); inOrder.verify(writer).write((byte) 0x37); }
@Test public void should_scream_when_no_matchers_inside_not() { try { mock.simpleMethod(AdditionalMatchers.not("jkl")); fail(); } catch (InvalidUseOfMatchersException e) { assertThat(e.getMessage()) .contains("No matchers found for") .containsIgnoringCase("Not(?)"); } }
@Test public void should_scream_when_not_enough_matchers_inside_or_AddtionalMatcher() { try { mock.simpleMethod(AdditionalMatchers.or(eq("jkl"), "asd")); fail(); } catch (InvalidUseOfMatchersException e) { assertThat(e.getMessage()) .containsIgnoringCase("inside additional matcher Or(?)") .contains("2 sub matchers expected") .contains("1 recorded"); } }
@Test public void testGetNewStrategyDependencies() { int round = 4; boolean[] strategy = new boolean[4]; strategy[0] = true; strategy[1] = false; strategy[2] = true; strategy[3] = false; double[] payoff = new double[4]; payoff[0] = 0.0; payoff[1] = 1.0; payoff[2] = 2.0; payoff[3] = 3.0; Bag neighbourBag = new Bag(); neighbourBag.add(agent1); neighbourBag.add(agent2); neighbourBag.add(agent3); Mockito.when(simulation.getRound()).thenReturn(round); Mockito.when(agent4.getNeighbourhood()).thenReturn(neighbourBag); Mockito.when(agent1.getPayoff(round - 1)).thenReturn(payoff[0]); Mockito.when(agent2.getPayoff(round - 1)).thenReturn(payoff[1]); Mockito.when(agent3.getPayoff(round - 1)).thenReturn(payoff[2]); Mockito.when(agent4.getPayoff(round - 1)).thenReturn(payoff[3]); Mockito.when(agent1.getStrategy(round - 1)).thenReturn(strategy[0]); Mockito.when(agent2.getStrategy(round - 1)).thenReturn(strategy[1]); Mockito.when(agent3.getStrategy(round - 1)).thenReturn(strategy[2]); Mockito.when(agent4.getStrategy(round - 1)).thenReturn(strategy[3]); boolean resultStrategy = imitation.getNewStrategy(agent4, simulation); Mockito.verify(imitation, Mockito.times(1)).getNewStrategy(Matchers.eq(4), AdditionalMatchers.aryEq(strategy), AdditionalMatchers.aryEq(payoff)); }
@Test public void postTest() throws Exception { Mockito.when(req.getParameter("indexingEnabled")).thenReturn("" + GlobalSettings.INDEXING_ENABLED_DEFAULT); Mockito.when(req.getParameter("maxConcurrentIndexing")).thenReturn( "" + GlobalSettings.MAX_CONCURRENT_INDEXING_DEFAULT); Mockito.when(req.getParameter("maxFileSize")).thenReturn("" + GlobalSettings.MAX_FILE_SIZE_DEFAULT); Mockito.when(req.getParameter("searchTimeout")).thenReturn("" + GlobalSettings.SEARCH_TIMEOUT_DEFAULT); Mockito.when(req.getParameter("noHighlightExtensions")).thenReturn( "" + GlobalSettings.NO_HIGHLIGHT_EXTENSIONS_DEFAULT); Mockito.when(req.getParameter("maxPreviewLines")).thenReturn("" + GlobalSettings.MAX_PREVIEW_LINES_DEFAULT); Mockito.when(req.getParameter("maxMatchLines")).thenReturn("" + GlobalSettings.MAX_MATCH_LINES_DEFAULT); Mockito.when(req.getParameter("maxFragments")).thenReturn("" + GlobalSettings.MAX_FRAGMENTS_DEFAULT); Mockito.when(req.getParameter("pageSize")).thenReturn("" + GlobalSettings.PAGE_SIZE_DEFAULT); Mockito.when(req.getParameter("commitHashBoost")).thenReturn("" + GlobalSettings.COMMIT_HASH_BOOST_DEFAULT); Mockito.when(req.getParameter("commitSubjectBoost")).thenReturn( "" + GlobalSettings.COMMIT_SUBJECT_BOOST_DEFAULT); Mockito.when(req.getParameter("commitBodyBoost")).thenReturn("" + GlobalSettings.COMMIT_BODY_BOOST_DEFAULT); Mockito.when(req.getParameter("fileNameBoost")).thenReturn("" + GlobalSettings.FILE_NAME_BOOST_DEFAULT); servlet.doPost(req, res); Mockito.verify(sm).setGlobalSettings( Mockito.eq(GlobalSettings.INDEXING_ENABLED_DEFAULT), Mockito.eq(GlobalSettings.MAX_CONCURRENT_INDEXING_DEFAULT), Mockito.eq(GlobalSettings.MAX_FILE_SIZE_DEFAULT), Mockito.eq(GlobalSettings.SEARCH_TIMEOUT_DEFAULT), Mockito.eq(GlobalSettings.NO_HIGHLIGHT_EXTENSIONS_DEFAULT), Mockito.eq(GlobalSettings.MAX_PREVIEW_LINES_DEFAULT), Mockito.eq(GlobalSettings.MAX_MATCH_LINES_DEFAULT), Mockito.eq(GlobalSettings.MAX_FRAGMENTS_DEFAULT), Mockito.eq(GlobalSettings.PAGE_SIZE_DEFAULT), AdditionalMatchers.eq(GlobalSettings.COMMIT_HASH_BOOST_DEFAULT, 1E-9), AdditionalMatchers.eq(GlobalSettings.COMMIT_SUBJECT_BOOST_DEFAULT, 1E-9), AdditionalMatchers.eq(GlobalSettings.COMMIT_BODY_BOOST_DEFAULT, 1E-9), AdditionalMatchers.eq(GlobalSettings.FILE_NAME_BOOST_DEFAULT, 1E-9)); Mockito.verify(res).setContentType(Mockito.contains("text/html")); }
/** * the test creates 2 electors which try to become active using a real * zookeeper server. It verifies that 1 becomes active and 1 becomes standby. * Upon becoming active the leader quits election and the test verifies that * the standby now becomes active. */ @Test(timeout=20000) public void testActiveStandbyTransition() throws Exception { LOG.info("starting test with parentDir:" + PARENT_DIR); assertFalse(electors[0].parentZNodeExists()); electors[0].ensureParentZNode(); assertTrue(electors[0].parentZNodeExists()); // First elector joins election, becomes active. electors[0].joinElection(appDatas[0]); ActiveStandbyElectorTestUtil.waitForActiveLockData(null, zkServer, PARENT_DIR, appDatas[0]); Mockito.verify(cbs[0], Mockito.timeout(1000)).becomeActive(); checkFatalsAndReset(); // Second elector joins election, becomes standby. electors[1].joinElection(appDatas[1]); Mockito.verify(cbs[1], Mockito.timeout(1000)).becomeStandby(); checkFatalsAndReset(); // First elector quits, second one should become active electors[0].quitElection(true); ActiveStandbyElectorTestUtil.waitForActiveLockData(null, zkServer, PARENT_DIR, appDatas[1]); Mockito.verify(cbs[1], Mockito.timeout(1000)).becomeActive(); checkFatalsAndReset(); // First one rejoins, becomes standby, second one stays active electors[0].joinElection(appDatas[0]); Mockito.verify(cbs[0], Mockito.timeout(1000)).becomeStandby(); checkFatalsAndReset(); // Second one expires, first one becomes active electors[1].preventSessionReestablishmentForTests(); try { zkServer.closeSession(electors[1].getZKSessionIdForTests()); ActiveStandbyElectorTestUtil.waitForActiveLockData(null, zkServer, PARENT_DIR, appDatas[0]); Mockito.verify(cbs[1], Mockito.timeout(1000)).enterNeutralMode(); Mockito.verify(cbs[0], Mockito.timeout(1000)).fenceOldActive( AdditionalMatchers.aryEq(appDatas[1])); Mockito.verify(cbs[0], Mockito.timeout(1000)).becomeActive(); } finally { electors[1].allowSessionReestablishmentForTests(); } // Second one eventually reconnects and becomes standby Mockito.verify(cbs[1], Mockito.timeout(5000)).becomeStandby(); checkFatalsAndReset(); // First one expires, second one should become active electors[0].preventSessionReestablishmentForTests(); try { zkServer.closeSession(electors[0].getZKSessionIdForTests()); ActiveStandbyElectorTestUtil.waitForActiveLockData(null, zkServer, PARENT_DIR, appDatas[1]); Mockito.verify(cbs[0], Mockito.timeout(1000)).enterNeutralMode(); Mockito.verify(cbs[1], Mockito.timeout(1000)).fenceOldActive( AdditionalMatchers.aryEq(appDatas[0])); Mockito.verify(cbs[1], Mockito.timeout(1000)).becomeActive(); } finally { electors[0].allowSessionReestablishmentForTests(); } checkFatalsAndReset(); }
/** * Delegates call to {@link AdditionalMatchers#geq(Comparable)}. */ default <T extends Comparable<T>> T geq(T value) { return AdditionalMatchers.geq(value); }
/** * Delegates call to {@link AdditionalMatchers#geq(byte)}. */ default byte geq(byte value) { return AdditionalMatchers.geq(value); }
/** * Delegates call to {@link AdditionalMatchers#geq(double)}. */ default double geq(double value) { return AdditionalMatchers.geq(value); }
/** * Delegates call to {@link AdditionalMatchers#geq(float)}. */ default float geq(float value) { return AdditionalMatchers.geq(value); }
/** * Delegates call to {@link AdditionalMatchers#geq(int)}. */ default int geq(int value) { return AdditionalMatchers.geq(value); }
/** * Delegates call to {@link AdditionalMatchers#geq(long)}. */ default long geq(long value) { return AdditionalMatchers.geq(value); }
/** * Delegates call to {@link AdditionalMatchers#geq(short)}. */ default short geq(short value) { return AdditionalMatchers.geq(value); }
/** * Delegates call to {@link AdditionalMatchers#leq(Comparable)}. */ default <T extends Comparable<T>> T leq(T value) { return AdditionalMatchers.leq(value); }
/** * Delegates call to {@link AdditionalMatchers#leq(byte)}. */ default byte leq(byte value) { return AdditionalMatchers.leq(value); }
/** * Delegates call to {@link AdditionalMatchers#leq(double)}. */ default double leq(double value) { return AdditionalMatchers.leq(value); }
/** * Delegates call to {@link AdditionalMatchers#leq(float)}. */ default float leq(float value) { return AdditionalMatchers.leq(value); }
/** * Delegates call to {@link AdditionalMatchers#leq(int)}. */ default int leq(int value) { return AdditionalMatchers.leq(value); }
/** * Delegates call to {@link AdditionalMatchers#leq(long)}. */ default long leq(long value) { return AdditionalMatchers.leq(value); }
/** * Delegates call to {@link AdditionalMatchers#leq(short)}. */ default short leq(short value) { return AdditionalMatchers.leq(value); }