Best Mockito code snippet using org.mockito.Mockito.atLeastOnce
Source:MeasureLibraryGridToolbarTest.java
...70 public void testApplyDefaultEditButton() {71 toolbar.applyDefault();72 Mockito.verify(toolbar.getEditOrViewButton(), Mockito.times(1)).setEnabled(Mockito.eq(false));73 Mockito.verify(toolbar.getEditOrViewButton(), Mockito.never()).setEnabled(Mockito.eq(true));74 Mockito.verify(toolbar.getEditOrViewButton(), Mockito.atLeastOnce()).setIcon(Mockito.eq(IconType.EDIT));75 Mockito.verify(toolbar.getEditOrViewButton(), Mockito.atLeastOnce()).setText(Mockito.eq("Edit"));76 Mockito.verify(toolbar.getEditOrViewButton(), Mockito.times(1)).setTitle(Mockito.eq("Click to edit"));77 Mockito.verify(toolbar.getEditOrViewButton(), Mockito.times(1)).setWidth(Mockito.eq("64px"));78 }79 @Test80 public void testApplyDefaultShareButton() {81 toolbar.applyDefault();82 Mockito.verify(toolbar.getShareButton(), Mockito.times(1)).setEnabled(Mockito.eq(false));83 Mockito.verify(toolbar.getShareButton(), Mockito.times(1)).setIcon(Mockito.eq(IconType.SHARE_SQUARE));84 Mockito.verify(toolbar.getShareButton(), Mockito.times(1)).setText(Mockito.eq("Share"));85 Mockito.verify(toolbar.getShareButton(), Mockito.times(1)).setTitle(Mockito.eq("Click to share"));86 Mockito.verify(toolbar.getShareButton(), Mockito.times(1)).setWidth(Mockito.eq("68px"));87 }88 @Test89 public void testApplyDefaultExportButton() {90 toolbar.applyDefault();91 Mockito.verify(toolbar.getExportButton(), Mockito.times(1)).setEnabled(Mockito.eq(false));92 Mockito.verify(toolbar.getExportButton(), Mockito.times(1)).setIcon(Mockito.eq(IconType.DOWNLOAD));93 Mockito.verify(toolbar.getExportButton(), Mockito.times(1)).setText(Mockito.eq("Export"));94 Mockito.verify(toolbar.getExportButton(), Mockito.times(1)).setTitle(Mockito.eq("Click to export"));95 Mockito.verify(toolbar.getExportButton(), Mockito.times(1)).setWidth(Mockito.eq("72px"));96 }97 @Test98 public void testExportOnEmptySelection() {99 toolbar.updateOnSelectionChanged(Collections.emptyList());100 Mockito.verify(toolbar.getExportButton(), Mockito.times(1)).setEnabled(Mockito.eq(false));101 Mockito.verify(toolbar.getExportButton(), Mockito.times(1)).setIcon(Mockito.eq(IconType.DOWNLOAD));102 Mockito.verify(toolbar.getExportButton(), Mockito.times(1)).setText(Mockito.eq("Export"));103 Mockito.verify(toolbar.getExportButton(), Mockito.times(1)).setTitle(Mockito.eq("Click to export"));104 Mockito.verify(toolbar.getExportButton(), Mockito.times(1)).setWidth(Mockito.eq("72px"));105 }106 @Test107 public void testApplyDefaultFhirValidationButton() {108 toolbar.applyDefault();109 Mockito.verify(toolbar.getFhirValidationButton(), Mockito.times(1)).setEnabled(Mockito.eq(false));110 Mockito.verify(toolbar.getFhirValidationButton(), Mockito.times(1)).setIcon(Mockito.eq(IconType.FILE_TEXT_O));111 Mockito.verify(toolbar.getFhirValidationButton(), Mockito.times(1)).setText(Mockito.eq("Run FHIR Validation"));112 Mockito.verify(toolbar.getFhirValidationButton(), Mockito.times(1)).setTitle(Mockito.eq("Click to Run FHIR Validation"));113 Mockito.verify(toolbar.getFhirValidationButton(), Mockito.times(1)).setWidth(Mockito.eq("146px"));114 }115 @Test116 public void testExportOnSelectionNoExportableItem() {117 toolbar.updateOnSelectionChanged(Arrays.asList(118 new ManageMeasureSearchModel.Result(),119 new ManageMeasureSearchModel.Result()120 ));121 Mockito.verify(toolbar.getExportButton(), Mockito.atLeastOnce()).setEnabled(Mockito.eq(false));122 Mockito.verify(toolbar.getExportButton(), Mockito.atLeastOnce()).setIcon(Mockito.eq(IconType.DOWNLOAD));123 Mockito.verify(toolbar.getExportButton(), Mockito.atLeastOnce()).setText(Mockito.eq("Export"));124 Mockito.verify(toolbar.getExportButton(), Mockito.atLeastOnce()).setTitle(Mockito.eq("Click to export"));125 Mockito.verify(toolbar.getExportButton(), Mockito.atLeastOnce()).setWidth(Mockito.eq("72px"));126 }127 @Test128 public void testExportOnSelectionOneExportableItem() {129 toolbar.updateOnSelectionChanged(Arrays.asList(130 new ManageMeasureSearchModel.Result() {{131 setExportable(true);132 setMeasureModel(ModelTypeHelper.QDM);133 }},134 new ManageMeasureSearchModel.Result()135 ));136 Mockito.verify(toolbar.getExportButton(), Mockito.atLeastOnce()).setEnabled(Mockito.eq(true));137 Mockito.verify(toolbar.getExportButton(), Mockito.atLeastOnce()).setIcon(Mockito.eq(IconType.DOWNLOAD));138 Mockito.verify(toolbar.getExportButton(), Mockito.atLeastOnce()).setText(Mockito.eq("Export"));139 Mockito.verify(toolbar.getExportButton(), Mockito.atLeastOnce()).setTitle(Mockito.eq("Click to export"));140 Mockito.verify(toolbar.getExportButton(), Mockito.atLeastOnce()).setWidth(Mockito.eq("72px"));141 }142 @Test143 public void testVersionButtonOnSelectionDraftableNotVersionable() {144 ManageMeasureSearchModel.Result item = new ManageMeasureSearchModel.Result();145 item.setDraftable(true);146 item.setVersionable(false);147 item.setIsComposite(false);148 toolbar.updateOnSelectionChanged(Arrays.asList(item));149 Mockito.verify(toolbar.getVersionButton(), Mockito.atLeastOnce()).setEnabled(Mockito.eq(true));150 Mockito.verify(toolbar.getVersionButton(), Mockito.atLeastOnce()).setText(Mockito.eq("Create Draft"));151 Mockito.verify(toolbar.getVersionButton(), Mockito.atLeastOnce()).setTitle(Mockito.eq("Click to create draft"));152 }153 @Test154 public void testVersionButtonOnSelectionVersionableNotDraftable() {155 ManageMeasureSearchModel.Result item = new ManageMeasureSearchModel.Result();156 item.setVersionable(true);157 item.setDraftable(false);158 item.setIsComposite(false);159 toolbar.updateOnSelectionChanged(Arrays.asList(item));160 Mockito.verify(toolbar.getVersionButton(), Mockito.atLeastOnce()).setEnabled(Mockito.eq(true));161 Mockito.verify(toolbar.getVersionButton(), Mockito.atLeastOnce()).setText(Mockito.eq("Create Version"));162 Mockito.verify(toolbar.getVersionButton(), Mockito.atLeastOnce()).setTitle(Mockito.eq("Click to create version"));163 }164 @Test165 public void testVersionButtonOnSelectionNotVersionableNotDraftable() {166 ManageMeasureSearchModel.Result item = new ManageMeasureSearchModel.Result();167 item.setVersionable(false);168 item.setDraftable(false);169 item.setIsComposite(true);170 toolbar.updateOnSelectionChanged(Arrays.asList(item));171 Mockito.verify(toolbar.getVersionButton(), Mockito.atLeastOnce()).setEnabled(Mockito.eq(false));172 Mockito.verify(toolbar.getVersionButton(), Mockito.atLeastOnce()).setText(Mockito.eq("Create Version or Draft"));173 Mockito.verify(toolbar.getVersionButton(), Mockito.atLeastOnce()).setTitle(Mockito.eq("Click to create version or draft"));174 }175 @Test176 public void testVersionButtonOnSelectionVersionableDraftable() {177 ManageMeasureSearchModel.Result item = new ManageMeasureSearchModel.Result();178 item.setVersionable(true);179 item.setDraftable(true);180 item.setIsComposite(true);181 toolbar.updateOnSelectionChanged(Arrays.asList(item));182 Mockito.verify(toolbar.getVersionButton(), Mockito.atLeastOnce()).setEnabled(Mockito.eq(true));183 Mockito.verify(toolbar.getVersionButton(), Mockito.atLeastOnce()).setText(Mockito.eq("Create Draft"));184 Mockito.verify(toolbar.getVersionButton(), Mockito.atLeastOnce()).setTitle(Mockito.eq("Click to create draft"));185 }186 @Test187 public void testHistoryOnSelectedNotEmpty() {188 ManageMeasureSearchModel.Result item = new ManageMeasureSearchModel.Result();189 item.setIsComposite(true);190 toolbar.updateOnSelectionChanged(Arrays.asList(item));191 Mockito.verify(toolbar.getHistoryButton(), Mockito.atLeastOnce()).setEnabled(Mockito.eq(true));192 }193 @Test194 public void testViewOnSelectedNotEditable() {195 ManageMeasureSearchModel.Result item = new ManageMeasureSearchModel.Result();196 item.setIsComposite(true);197 item.setMeasureEditOrViewable(true);198 toolbar.updateOnSelectionChanged(Arrays.asList(item));199 Mockito.verify(toolbar.getEditOrViewButton(), Mockito.atLeastOnce()).setEnabled(Mockito.eq(true));200 Mockito.verify(toolbar.getEditOrViewButton(), Mockito.atLeastOnce()).setIcon(Mockito.eq(IconType.EYE));201 Mockito.verify(toolbar.getEditOrViewButton(), Mockito.atLeastOnce()).setText(Mockito.eq("View"));202 Mockito.verify(toolbar.getEditOrViewButton(), Mockito.atLeastOnce()).setTitle(Mockito.eq("Read-Only"));203 }204 @Test205 public void testEditOnSelectedEditableAndLocked() {206 ManageMeasureSearchModel.Result item = new ManageMeasureSearchModel.Result();207 item.setEditable(true);208 item.setMeasureLocked(true);209 item.setLockedUserInfo(new LockedUserInfo());210 item.getLockedUserInfo().setEmailAddress("fake@gmail.com");211 item.setIsComposite(true);212 item.setMeasureEditOrViewable(true);213 toolbar.updateOnSelectionChanged(Arrays.asList(item));214 Mockito.verify(toolbar.getEditOrViewButton(), Mockito.atLeastOnce()).setEnabled(Mockito.eq(false));215 Mockito.verify(toolbar.getEditOrViewButton(), Mockito.never()).setEnabled(Mockito.eq(true));216 Mockito.verify(toolbar.getEditOrViewButton(), Mockito.atLeastOnce()).setIcon(Mockito.eq(IconType.LOCK));217 Mockito.verify(toolbar.getEditOrViewButton(), Mockito.atLeastOnce()).setText(Mockito.eq("Edit"));218 Mockito.verify(toolbar.getEditOrViewButton(), Mockito.atLeastOnce()).setTitle(Mockito.eq("Measure in use by fake@gmail.com"));219 }220 @Test221 public void testEditOnSelectedEditableAndNotLocked() {222 ManageMeasureSearchModel.Result item = new ManageMeasureSearchModel.Result();223 item.setEditable(true);224 item.setMeasureLocked(false);225 item.setLockedUserInfo(new LockedUserInfo());226 item.getLockedUserInfo().setEmailAddress("fake@gmail.com");227 item.setIsComposite(true);228 item.setMeasureEditOrViewable(true);229 toolbar.updateOnSelectionChanged(Arrays.asList(item));230 Mockito.verify(toolbar.getEditOrViewButton(), Mockito.atLeastOnce()).setEnabled(Mockito.eq(true));231 Mockito.verify(toolbar.getEditOrViewButton(), Mockito.atLeastOnce()).setIcon(Mockito.eq(IconType.EDIT));232 Mockito.verify(toolbar.getEditOrViewButton(), Mockito.atLeastOnce()).setText(Mockito.eq("Edit"));233 Mockito.verify(toolbar.getEditOrViewButton(), Mockito.atLeastOnce()).setTitle(Mockito.eq("Click to edit"));234 }235 @Test236 public void testShareOnNotSharable() {237 ManageMeasureSearchModel.Result item = new ManageMeasureSearchModel.Result();238 item.setSharable(false);239 item.setIsComposite(true);240 toolbar.updateOnSelectionChanged(Arrays.asList(item));241 Mockito.verify(toolbar.getShareButton(), Mockito.atLeastOnce()).setEnabled(Mockito.eq(false));242 Mockito.verify(toolbar.getShareButton(), Mockito.never()).setEnabled(Mockito.eq(true));243 }244 @Test245 public void testShareOnSharable() {246 ManageMeasureSearchModel.Result item = new ManageMeasureSearchModel.Result();247 item.setSharable(true);248 item.setIsComposite(true);249 toolbar.updateOnSelectionChanged(Arrays.asList(item));250 Mockito.verify(toolbar.getShareButton(), Mockito.atLeastOnce()).setEnabled(Mockito.eq(true));251 }252 @Test253 public void testCloneOnClonable() {254 ManageMeasureSearchModel.Result item = new ManageMeasureSearchModel.Result();255 item.setClonable(true);256 item.setIsComposite(true);257 toolbar.updateOnSelectionChanged(Arrays.asList(item));258 Mockito.verify(toolbar.getCloneButton(), Mockito.atLeastOnce()).setEnabled(Mockito.eq(true));259 }260 @Test261 public void testCloneOnNotClonableNotComposite() {262 ManageMeasureSearchModel.Result item = new ManageMeasureSearchModel.Result();263 item.setClonable(false);264 item.setIsComposite(false);265 toolbar.updateOnSelectionChanged(Arrays.asList(item));266 Mockito.verify(toolbar.getCloneButton(), Mockito.atLeastOnce()).setEnabled(Mockito.eq(false));267 Mockito.verify(toolbar.getCloneButton(), Mockito.never()).setEnabled(Mockito.eq(true));268 Mockito.verify(toolbar.getCloneButton(), Mockito.atLeastOnce()).setTitle(Mockito.eq("Measure not cloneable"));269 }270 @Test271 public void testCloneOnNotClonableComposite() {272 ManageMeasureSearchModel.Result item = new ManageMeasureSearchModel.Result();273 item.setClonable(false);274 item.setIsComposite(true);275 toolbar.updateOnSelectionChanged(Arrays.asList(item));276 Mockito.verify(toolbar.getCloneButton(), Mockito.atLeastOnce()).setEnabled(Mockito.eq(false));277 Mockito.verify(toolbar.getCloneButton(), Mockito.never()).setEnabled(Mockito.eq(true));278 Mockito.verify(toolbar.getCloneButton(), Mockito.atLeastOnce()).setTitle(Mockito.eq("Composite measure not cloneable"));279 }280 @Test281 public void testRunValidationButtonEnabled() {282 ManageMeasureSearchModel.Result item = new ManageMeasureSearchModel.Result();283 item.setClonable(true);284 item.setValidatable(true);285 toolbar.updateOnSelectionChanged(Arrays.asList(item));286 Mockito.verify(toolbar.getFhirValidationButton(), Mockito.atLeastOnce()).setEnabled(Mockito.eq(true));287 }288 @Test289 public void testRunValidationButtonDisabled() {290 ManageMeasureSearchModel.Result item = new ManageMeasureSearchModel.Result();291 item.setClonable(true);292 item.setValidatable(false);293 toolbar.updateOnSelectionChanged(Arrays.asList(item));294 Mockito.verify(toolbar.getFhirValidationButton(), Mockito.atLeastOnce()).setEnabled(Mockito.eq(false));295 Mockito.verify(toolbar.getFhirValidationButton(), Mockito.never()).setEnabled(Mockito.eq(true));296 }297 @Test298 public void testAllDisabledMultipleSelectedNotExportable() {299 ManageMeasureSearchModel.Result item0 = new ManageMeasureSearchModel.Result();300 item0.setIsComposite(true);301 ManageMeasureSearchModel.Result item1 = new ManageMeasureSearchModel.Result();302 item1.setIsComposite(true);303 toolbar.updateOnSelectionChanged(Arrays.asList(item0, item1));304 Mockito.verify(toolbar.getShareButton(), Mockito.never()).setEnabled(Mockito.eq(true));305 Mockito.verify(toolbar.getEditOrViewButton(), Mockito.never()).setEnabled(Mockito.eq(true));306 Mockito.verify(toolbar.getVersionButton(), Mockito.never()).setEnabled(Mockito.eq(true));307 Mockito.verify(toolbar.getHistoryButton(), Mockito.never()).setEnabled(Mockito.eq(true));308 Mockito.verify(toolbar.getCloneButton(), Mockito.never()).setEnabled(Mockito.eq(true));309 Mockito.verify(toolbar.getExportButton(), Mockito.never()).setEnabled(Mockito.eq(true));310 Mockito.verify(toolbar.getFhirValidationButton(), Mockito.never()).setEnabled(Mockito.eq(true));311 Mockito.verify(toolbar.getConvertButton(), Mockito.never()).setEnabled(Mockito.eq(true));312 }313 @Test314 public void testExportEnabledOndMultipleSelectedExportable() {315 ManageMeasureSearchModel.Result item0 = new ManageMeasureSearchModel.Result();316 item0.setExportable(true);317 item0.setIsComposite(true);318 item0.setMeasureModel(ModelTypeHelper.QDM);319 ManageMeasureSearchModel.Result item1 = new ManageMeasureSearchModel.Result();320 item1.setExportable(true);321 item1.setIsComposite(true);322 item0.setMeasureModel(ModelTypeHelper.QDM);323 toolbar.updateOnSelectionChanged(Arrays.asList(item0, item1));324 Mockito.verify(toolbar.getShareButton(), Mockito.never()).setEnabled(Mockito.eq(true));325 Mockito.verify(toolbar.getEditOrViewButton(), Mockito.never()).setEnabled(Mockito.eq(true));326 Mockito.verify(toolbar.getVersionButton(), Mockito.never()).setEnabled(Mockito.eq(true));327 Mockito.verify(toolbar.getHistoryButton(), Mockito.never()).setEnabled(Mockito.eq(true));328 Mockito.verify(toolbar.getCloneButton(), Mockito.never()).setEnabled(Mockito.eq(true));329 Mockito.verify(toolbar.getFhirValidationButton(), Mockito.never()).setEnabled(Mockito.eq(true));330 Mockito.verify(toolbar.getConvertButton(), Mockito.never()).setEnabled(Mockito.eq(true));331 Mockito.verify(toolbar.getExportButton(), Mockito.atLeastOnce()).setEnabled(Mockito.eq(true));332 }333 @Test334 public void testCovertNotEnabled() {335 ManageMeasureSearchModel.Result item0 = new ManageMeasureSearchModel.Result();336 toolbar.updateOnSelectionChanged(Collections.singleton(item0));337 Mockito.verify(toolbar.getConvertButton(), Mockito.never()).setEnabled(Mockito.eq(true));338 Mockito.verify(toolbar.getConvertButton(), Mockito.atLeastOnce()).setEnabled(Mockito.eq(false));339 }340 @Test341 public void testCovertEnabled() {342 ManageMeasureSearchModel.Result item0 = new ManageMeasureSearchModel.Result();343 item0.setFhirConvertible(true);344 toolbar.updateOnSelectionChanged(Collections.singleton(item0));345 Mockito.verify(toolbar.getConvertButton(), Mockito.atLeastOnce()).setEnabled(Mockito.eq(true));346 }347 @Test348 public void testConvertibleButtonNotVisible() {349 Mockito.reset(toolbar.getConvertButton());350 Mockito.when(options.isConvertButtonVisible()).thenReturn(false);351 toolbar.applyOptions();352 Mockito.verify(toolbar.getConvertButton(), Mockito.times(1)).setVisible(Mockito.eq(false));353 Mockito.verify(toolbar.getConvertButton(), Mockito.never()).setVisible(Mockito.eq(true));354 }355 @Test356 public void testConvertibleButtonVisible() {357 Mockito.reset(toolbar.getConvertButton());358 Mockito.when(options.isConvertButtonVisible()).thenReturn(true);359 toolbar.applyOptions();360 Mockito.verify(toolbar.getConvertButton(), Mockito.atLeastOnce()).setVisible(Mockito.eq(true));361 Mockito.verify(toolbar.getConvertButton(), Mockito.never()).setVisible(Mockito.eq(false));362 }363 @Test364 public void testFhirValidationButtonNotVisible() {365 Mockito.reset(toolbar.getFhirValidationButton());366 Mockito.when(options.isFhirValidationButtonVisible()).thenReturn(false);367 toolbar.applyOptions();368 Mockito.verify(toolbar.getFhirValidationButton(), Mockito.times(1)).setVisible(Mockito.eq(false));369 Mockito.verify(toolbar.getFhirValidationButton(), Mockito.never()).setVisible(Mockito.eq(true));370 }371 @Test372 public void testFhirValidationButtonVisible() {373 Mockito.reset(toolbar.getFhirValidationButton());374 Mockito.when(options.isFhirValidationButtonVisible()).thenReturn(true);375 toolbar.applyOptions();376 Mockito.verify(toolbar.getFhirValidationButton(), Mockito.atLeastOnce()).setVisible(Mockito.eq(true));377 Mockito.verify(toolbar.getFhirValidationButton(), Mockito.never()).setVisible(Mockito.eq(false));378 }379 @Test380 public void testWithOptionsInstanceCreated() {381 MeasureLibraryGridToolbar toolbar = MeasureLibraryGridToolbar.withOptions("BarOfFoo",new MeasureLibraryGridToolbar.Options());382 Assert.assertNotNull(toolbar);383 }384 @Test385 public void testFromFeatureFlagsConvertButtonNotVisible() {386 HashMap<String, Boolean> flags = new HashMap<>();387 MatContext.get().setFeatureFlags(flags);388 MeasureLibraryGridToolbar.Options otherOptions = MeasureLibraryGridToolbar.Options.fromFeatureFlags();389 Assert.assertFalse(otherOptions.isConvertButtonVisible());390 }...
Source:GlobalThrottleEngineClientTestCase.java
...64 @Test65 public void testValidateCorrectExecutionPlan() throws Exception {66 GlobalThrottleEngineClient globalThrottleEngineClient = new GlobalThrottleEngineClientWrapper(authenticationAdminStub, eventProcessorAdminServiceStub, policyDeployer);67 boolean validity= globalThrottleEngineClient.validateExecutionPlan(EX_PLAN);68 Mockito.verify(authenticationAdminStub, Mockito.atLeastOnce()).login(USER_NAME, PASSWORD, HOST);69 Assert.assertTrue(validity);70 }71 @Test72 public void testValidateWrongExecutionPlan() throws Exception {73 GlobalThrottleEngineClient globalThrottleEngineClient = new GlobalThrottleEngineClientWrapper(authenticationAdminStub, eventProcessorAdminServiceStub, policyDeployer);74 boolean validity= globalThrottleEngineClient.validateExecutionPlan(EX_PLAN_WRONG);75 Mockito.verify(authenticationAdminStub, Mockito.atLeastOnce()).login(USER_NAME, PASSWORD, HOST);76 Assert.assertFalse(validity);77 }78 @Test79 public void testRemoteExceptionWhenValidateExPlan() throws Exception{80 GlobalThrottleEngineClient globalThrottleEngineClient = new GlobalThrottleEngineClientWrapper(authenticationAdminStub, eventProcessorAdminServiceStub, policyDeployer);81 Mockito.when(eventProcessorAdminServiceStub.validateExecutionPlan(EX_PLAN_WRONG)).thenThrow(RemoteException.class);82 boolean validity= globalThrottleEngineClient.validateExecutionPlan(EX_PLAN_WRONG);83 Mockito.verify(authenticationAdminStub, Mockito.atLeastOnce()).login(USER_NAME, PASSWORD, HOST);84 Assert.assertFalse(validity);85 }86 @Test87 public void testRemoteExceptionWhenDeleteExPlan() throws Exception{88 GlobalThrottleEngineClient globalThrottleEngineClient = new GlobalThrottleEngineClientWrapper(authenticationAdminStub, eventProcessorAdminServiceStub, policyDeployer);89 Mockito.when(authenticationAdminStub.login(USER_NAME, PASSWORD, HOST)).thenThrow(RemoteException.class);90 globalThrottleEngineClient.deleteExecutionPlan(EX_PLAN_WRONG);91 Mockito.verify(authenticationAdminStub, Mockito.atLeastOnce()).login(USER_NAME, PASSWORD, HOST);92 }93 @Test94 public void testRemoteExceptionWhenDeployExPlanAndLogout() throws Exception{95 GlobalThrottleEngineClient globalThrottleEngineClient = new GlobalThrottleEngineClientWrapper(authenticationAdminStub, eventProcessorAdminServiceStub, policyDeployer);96 Mockito.doThrow(RemoteException.class).when(authenticationAdminStub).logout();97 globalThrottleEngineClient.deployExecutionPlan(EX_PLAN);98 Mockito.verify(authenticationAdminStub, Mockito.atLeastOnce()).login(USER_NAME, PASSWORD, HOST);99 Mockito.verify(eventProcessorAdminServiceStub, Mockito.times(1)).deployExecutionPlan(EX_PLAN);100 }101 @Test102 public void testRemoteExceptionWhenUpdateExPlanAndLogout() throws Exception{103 GlobalThrottleEngineClient globalThrottleEngineClient = new GlobalThrottleEngineClientWrapper(authenticationAdminStub, eventProcessorAdminServiceStub, policyDeployer);104 Mockito.doThrow(RemoteException.class).when(authenticationAdminStub).logout();105 globalThrottleEngineClient.updateExecutionPlan(EX_PLAN_NAME, EX_PLAN);106 Mockito.verify(authenticationAdminStub, Mockito.atLeastOnce()).login(USER_NAME, PASSWORD, HOST);107 Mockito.verify(eventProcessorAdminServiceStub, Mockito.times(1)).editActiveExecutionPlan(EX_PLAN, EX_PLAN_NAME);108 }109 @Test110 public void testMalformedURLExceptionWhenValidateExPlan() throws Exception{111 GlobalThrottleEngineClient globalThrottleEngineClient = new GlobalThrottleEngineClientWrapper(authenticationAdminStub, eventProcessorAdminServiceStub, policyDeployer);112 Mockito.when(policyDeployer.getServiceUrl()).thenReturn("htp://foo.com");113 boolean validity= globalThrottleEngineClient.validateExecutionPlan(EX_PLAN);114 Assert.assertFalse(validity);115 }116 @Test117 public void testMalformedURLExceptionWhenDeleteExPlan() throws Exception{118 GlobalThrottleEngineClient globalThrottleEngineClient = new GlobalThrottleEngineClientWrapper(authenticationAdminStub, eventProcessorAdminServiceStub, policyDeployer);119 Mockito.when(policyDeployer.getServiceUrl()).thenReturn("htp://foo.com");120 globalThrottleEngineClient.deleteExecutionPlan(EX_PLAN_NAME);121 Mockito.verify(eventProcessorAdminServiceStub, Mockito.times(1)).undeployActiveExecutionPlan(EX_PLAN_NAME);122 }123 @Test124 public void testRemoteExceptionWhenDeleteExPlanViaEventProcessorStub() throws Exception{125 GlobalThrottleEngineClient globalThrottleEngineClient = new GlobalThrottleEngineClientWrapper(authenticationAdminStub, eventProcessorAdminServiceStub, policyDeployer);126 Mockito.doThrow(RemoteException.class).when(eventProcessorAdminServiceStub).undeployActiveExecutionPlan(EX_PLAN_NAME);127 globalThrottleEngineClient.deleteExecutionPlan(EX_PLAN_NAME);128 Mockito.verify(eventProcessorAdminServiceStub, Mockito.times(1)).undeployActiveExecutionPlan(EX_PLAN_NAME);129 }130 @Test131 public void testLoginAuthenticationExceptionWhenLoginWhileDeploying() throws Exception{132 GlobalThrottleEngineClient globalThrottleEngineClient = new GlobalThrottleEngineClientWrapper(authenticationAdminStub, eventProcessorAdminServiceStub, policyDeployer);133 Mockito.when(authenticationAdminStub.login(USER_NAME,PASSWORD,HOST)).thenThrow(LoginAuthenticationExceptionException.class);134 boolean validity= globalThrottleEngineClient.validateExecutionPlan(EX_PLAN_WRONG);135 Mockito.verify(authenticationAdminStub, Mockito.atLeastOnce()).login(USER_NAME, PASSWORD, HOST);136 Assert.assertFalse(validity);137 }138 @Test139 public void testLoginAuthenticationExceptionWhenLoginWhileDeleting() throws Exception{140 GlobalThrottleEngineClient globalThrottleEngineClient = new GlobalThrottleEngineClientWrapper(authenticationAdminStub, eventProcessorAdminServiceStub, policyDeployer);141 Mockito.when(authenticationAdminStub.login(USER_NAME,PASSWORD,HOST)).thenThrow(LoginAuthenticationExceptionException.class);142 globalThrottleEngineClient.deleteExecutionPlan(EX_PLAN);143 Mockito.verify(authenticationAdminStub, Mockito.atLeastOnce()).login(USER_NAME, PASSWORD, HOST);144 }145 @Test146 public void testDeployExecutionPlan() throws Exception {147 GlobalThrottleEngineClient globalThrottleEngineClient = new GlobalThrottleEngineClientWrapper(authenticationAdminStub, eventProcessorAdminServiceStub, policyDeployer);148 globalThrottleEngineClient.deployExecutionPlan(EX_PLAN);149 Mockito.verify(authenticationAdminStub, Mockito.atLeastOnce()).login(USER_NAME, PASSWORD, HOST);150 Mockito.verify(eventProcessorAdminServiceStub, Mockito.times(1)).deployExecutionPlan(EX_PLAN);151 }152 @Test153 public void testLogoutAuthenticationExceptionWhenDeployingExPlan() throws Exception{154 GlobalThrottleEngineClient globalThrottleEngineClient = new GlobalThrottleEngineClientWrapper(authenticationAdminStub, eventProcessorAdminServiceStub, policyDeployer);155 Mockito.doThrow(LogoutAuthenticationExceptionException.class).when(authenticationAdminStub).logout();156 globalThrottleEngineClient.deployExecutionPlan(EX_PLAN);157 Mockito.verify(authenticationAdminStub, Mockito.atLeastOnce()).login(USER_NAME, PASSWORD, HOST);158 Mockito.verify(eventProcessorAdminServiceStub, Mockito.times(1)).deployExecutionPlan(EX_PLAN);159 }160 @Test161 public void testLogoutAuthenticationExceptionWhenUpdatingExPlan() throws Exception{162 GlobalThrottleEngineClient globalThrottleEngineClient = new GlobalThrottleEngineClientWrapper(authenticationAdminStub, eventProcessorAdminServiceStub, policyDeployer);163 Mockito.doThrow(LogoutAuthenticationExceptionException.class).when(authenticationAdminStub).logout();164 globalThrottleEngineClient.updateExecutionPlan(EX_PLAN_NAME, EX_PLAN);165 Mockito.verify(authenticationAdminStub, Mockito.atLeastOnce()).login(USER_NAME, PASSWORD, HOST);166 Mockito.verify(eventProcessorAdminServiceStub, Mockito.times(1)).editActiveExecutionPlan(EX_PLAN, EX_PLAN_NAME);167 }168 @Test169 public void testUpdateExecutionPlan() throws Exception {170 GlobalThrottleEngineClient globalThrottleEngineClient = new GlobalThrottleEngineClientWrapper(authenticationAdminStub, eventProcessorAdminServiceStub, policyDeployer);171 globalThrottleEngineClient.updateExecutionPlan(EX_PLAN_NAME, EX_PLAN);172 Mockito.verify(authenticationAdminStub, Mockito.atLeastOnce()).login(USER_NAME, PASSWORD, HOST);173 Mockito.verify(eventProcessorAdminServiceStub, Mockito.times(1)).editActiveExecutionPlan(EX_PLAN, EX_PLAN_NAME);174 }175 @Test176 public void testDeleteExecutionPlan() throws Exception {177 GlobalThrottleEngineClient globalThrottleEngineClient = new GlobalThrottleEngineClientWrapper(authenticationAdminStub, eventProcessorAdminServiceStub, policyDeployer);178 globalThrottleEngineClient.deleteExecutionPlan(EX_PLAN_NAME);179 Mockito.verify(authenticationAdminStub, Mockito.atLeastOnce()).login(USER_NAME, PASSWORD, HOST);180 Mockito.verify(eventProcessorAdminServiceStub, Mockito.times(1)).undeployActiveExecutionPlan(EX_PLAN_NAME);181 }182}...
Source:TestIOUtils.java
...48 InputStream inputStream = Mockito.mock(InputStream.class);49 OutputStream outputStream = Mockito.mock(OutputStream.class);50 Mockito.doReturn(-1).when(inputStream).read(new byte[1]);51 IOUtils.copyBytes(inputStream, outputStream, 1, true);52 Mockito.verify(inputStream, Mockito.atLeastOnce()).close();53 Mockito.verify(outputStream, Mockito.atLeastOnce()).close();54 }55 @Test56 public void testCopyBytesShouldCloseInputSteamWhenOutputStreamCloseThrowsException()57 throws Exception {58 InputStream inputStream = Mockito.mock(InputStream.class);59 OutputStream outputStream = Mockito.mock(OutputStream.class);60 Mockito.doReturn(-1).when(inputStream).read(new byte[1]);61 Mockito.doThrow(new IOException()).when(outputStream).close();62 try{63 IOUtils.copyBytes(inputStream, outputStream, 1, true);64 } catch (IOException e) {65 }66 Mockito.verify(inputStream, Mockito.atLeastOnce()).close();67 Mockito.verify(outputStream, Mockito.atLeastOnce()).close();68 }69 @Test70 public void testCopyBytesShouldCloseInputSteamWhenOutputStreamCloseThrowsRunTimeException()71 throws Exception {72 InputStream inputStream = Mockito.mock(InputStream.class);73 OutputStream outputStream = Mockito.mock(OutputStream.class);74 Mockito.doReturn(-1).when(inputStream).read(new byte[1]);75 Mockito.doThrow(new RuntimeException()).when(outputStream).close();76 try {77 IOUtils.copyBytes(inputStream, outputStream, 1, true);78 fail("Didn't throw exception");79 } catch (RuntimeException e) {80 }81 Mockito.verify(outputStream, Mockito.atLeastOnce()).close();82 }83 @Test84 public void testCopyBytesShouldCloseInputSteamWhenInputStreamCloseThrowsRunTimeException()85 throws Exception {86 InputStream inputStream = Mockito.mock(InputStream.class);87 OutputStream outputStream = Mockito.mock(OutputStream.class);88 Mockito.doReturn(-1).when(inputStream).read(new byte[1]);89 Mockito.doThrow(new RuntimeException()).when(inputStream).close();90 try {91 IOUtils.copyBytes(inputStream, outputStream, 1, true);92 fail("Didn't throw exception");93 } catch (RuntimeException e) {94 }95 Mockito.verify(inputStream, Mockito.atLeastOnce()).close();96 }97 @Test98 public void testCopyBytesShouldNotCloseStreamsWhenCloseIsFalse()99 throws Exception {100 InputStream inputStream = Mockito.mock(InputStream.class);101 OutputStream outputStream = Mockito.mock(OutputStream.class);102 Mockito.doReturn(-1).when(inputStream).read(new byte[1]);103 IOUtils.copyBytes(inputStream, outputStream, 1, false);104 Mockito.verify(inputStream, Mockito.atMost(0)).close();105 Mockito.verify(outputStream, Mockito.atMost(0)).close();106 }107 @Test108 public void testCopyBytesWithCountShouldCloseStreamsWhenCloseIsTrue()109 throws Exception {110 InputStream inputStream = Mockito.mock(InputStream.class);111 OutputStream outputStream = Mockito.mock(OutputStream.class);112 Mockito.doReturn(-1).when(inputStream).read(new byte[4096], 0, 1);113 IOUtils.copyBytes(inputStream, outputStream, (long) 1, true);114 Mockito.verify(inputStream, Mockito.atLeastOnce()).close();115 Mockito.verify(outputStream, Mockito.atLeastOnce()).close();116 }117 @Test118 public void testCopyBytesWithCountShouldNotCloseStreamsWhenCloseIsFalse()119 throws Exception {120 InputStream inputStream = Mockito.mock(InputStream.class);121 OutputStream outputStream = Mockito.mock(OutputStream.class);122 Mockito.doReturn(-1).when(inputStream).read(new byte[4096], 0, 1);123 IOUtils.copyBytes(inputStream, outputStream, (long) 1, false);124 Mockito.verify(inputStream, Mockito.atMost(0)).close();125 Mockito.verify(outputStream, Mockito.atMost(0)).close();126 }127 @Test128 public void testCopyBytesWithCountShouldThrowOutTheStreamClosureExceptions()129 throws Exception {130 InputStream inputStream = Mockito.mock(InputStream.class);131 OutputStream outputStream = Mockito.mock(OutputStream.class);132 Mockito.doReturn(-1).when(inputStream).read(new byte[4096], 0, 1);133 Mockito.doThrow(new IOException("Exception in closing the stream")).when(134 outputStream).close();135 try {136 IOUtils.copyBytes(inputStream, outputStream, (long) 1, true);137 fail("Should throw out the exception");138 } catch (IOException e) {139 assertEquals("Not throwing the expected exception.",140 "Exception in closing the stream", e.getMessage());141 }142 Mockito.verify(inputStream, Mockito.atLeastOnce()).close();143 Mockito.verify(outputStream, Mockito.atLeastOnce()).close();144 }145 @Test146 public void testWriteFully() throws IOException {147 final int INPUT_BUFFER_LEN = 10000;148 final int HALFWAY = 1 + (INPUT_BUFFER_LEN / 2);149 byte[] input = new byte[INPUT_BUFFER_LEN];150 for (int i = 0; i < input.length; i++) {151 input[i] = (byte)(i & 0xff);152 }153 byte[] output = new byte[input.length];154 155 try {156 RandomAccessFile raf = new RandomAccessFile(TEST_FILE_NAME, "rw");157 FileChannel fc = raf.getChannel();...
Source:AuthennticationManagerTest.java
...94 return null;95 }96 });97 authenticationManager.changePassword(context, "testOldcred", "testNewcred", authenticationCallback);98 Mockito.verify(handler, Mockito.atLeastOnce())99 .sendMessage(Mockito.any(Message.class));100 /*Mockito.verify(commsManager, Mockito.times(1)).processRequest(Mockito.any(), any(CommsListener.class));*/101 /*Assert.assertEquals(inputStream, Util.getCertificate(context));*/102 }103 @Test104 public void testAutenticateUser() {105 authenticationManager.authenticateUser(inputStream, authenticationCallback);106 Mockito.verify(commsManager, Mockito.times(1)).authenticate(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), any(InputStream.class), any(CommsListener.class));107 }108 @Test109 public void testgetCredValidityDays() {110 final Gson gson = new GsonBuilder().create();111 ResponseObject responseObject = new ResponseObject();112 responseObject.setStatusCode(200);113 RequestObject requestObject = new RequestObject(RequestObject.RequestType.GET, "Test1", "Test2");114 requestObject.setCertFileStream(inputStream);115 requestObject.setMessageBody("DemoMessage");116 responseObject.setHeaders(headers);117 responseObject.setResponseBody(gson.toJson(userRoles));118 PowerMockito.when(commsManager.processRequest(Mockito.any(RequestObject.class), Mockito.any(CommsListener.class))).thenAnswer(new Answer<Object>() {119 @Override120 public Object answer(InvocationOnMock invocation) throws Throwable {121 ((CommsListener)invocation.getArguments()[1]).onResponse(responseObject);122 return null;123 }124 });125 authenticationManager.checkUserRole(context, authenticationCallback);126 Mockito.verify(handler, Mockito.atLeastOnce())127 .sendMessage(Mockito.any(Message.class));128 //Mockito.verify(commsManager, Mockito.times(1)).processRequest(Mockito.any(), any(CommsListener.class));129 }130 @Test131 public void testResponse() {132 userRoles.add(Util.UserType.ROLE_PREMIUM.toString());133 final Gson gson = new GsonBuilder().create();134 ResponseObject responseObject = new ResponseObject();135 responseObject.setStatusCode(200);136 responseObject.setStatusMessage("Success");137 responseObject.setHeaders(headers);138 responseObject.setResponseBody(gson.toJson(userRoles));139 authenticationManager.onResponse(responseObject);140 Mockito.verify(handler, Mockito.atLeastOnce())141 .sendMessage(Mockito.any(Message.class));142 authenticationManager.onFailure(4, "Test2");143 Mockito.verify(handler, Mockito.atLeastOnce())144 .sendMessage(Mockito.any(Message.class));145 }146 @Test147 public void testResponsePaid() {148 userRoles.add(Util.UserType.ROLE_PAID.toString());149 final Gson gson = new GsonBuilder().create();150 ResponseObject responseObject = new ResponseObject();151 responseObject.setStatusCode(200);152 responseObject.setStatusMessage("Success");153 responseObject.setHeaders(headers);154 responseObject.setResponseBody(gson.toJson(userRoles));155 authenticationManager.onResponse(responseObject);156 Mockito.verify(handler, Mockito.atLeastOnce())157 .sendMessage(Mockito.any(Message.class));158 authenticationManager.onFailure(4, "Test2");159 Mockito.verify(handler, Mockito.atLeastOnce())160 .sendMessage(Mockito.any(Message.class));161 }162 @Test163 public void testResponsePaidFree() {164 userRoles.add(Util.UserType.ROLE_FREE.toString());165 final Gson gson = new GsonBuilder().create();166 ResponseObject responseObject = new ResponseObject();167 responseObject.setStatusCode(200);168 responseObject.setStatusMessage("Success");169 responseObject.setHeaders(headers);170 responseObject.setResponseBody(gson.toJson(userRoles));171 authenticationManager.onResponse(responseObject);172 Mockito.verify(handler, Mockito.atLeastOnce())173 .sendMessage(Mockito.any(Message.class));174 authenticationManager.onFailure(4, "Test2");175 Mockito.verify(handler, Mockito.atLeastOnce())176 .sendMessage(Mockito.any(Message.class));177 }178 @Test179 public void testResponseFailure() {180 userRoles.add(Util.UserType.ROLE_FREE.toString());181 final Gson gson = new GsonBuilder().create();182 ResponseObject responseObject = new ResponseObject();183 responseObject.setStatusCode(406);184 responseObject.setStatusMessage("Success");185 responseObject.setHeaders(headers);186 responseObject.setResponseBody(gson.toJson(userRoles));187 authenticationManager.onResponse(responseObject);188 Mockito.verify(handler, Mockito.atLeastOnce())189 .sendMessage(Mockito.any(Message.class));190 authenticationManager.onFailure(4, "Test2");191 Mockito.verify(handler, Mockito.atLeastOnce())192 .sendMessage(Mockito.any(Message.class));193 }194}...
Source:BearingRestClientTest.java
...52 @Test53 public void testUploads() {54 final String SITE_NAME = "SITE_NAME";55 bearingRestClient.uploadSiteData(SITE_NAME, callback);56 Mockito.verify(dataUploader, Mockito.atLeastOnce())57 .uploadSiteData(Mockito.anyString(), Mockito.any(BearingClientCallback.class));58 bearingRestClient.uploadLocationData(SITE_NAME, "LOC_NAME", BearingConfiguration.Approach.FINGERPRINT, callback);59 Mockito.verify(dataUploader, Mockito.atLeastOnce())60 .uploadLocationData(Mockito.anyString(), Mockito.anyString(), Mockito.any(BearingConfiguration.Approach.class), Mockito.any(BearingClientCallback.class));61 bearingRestClient.uploadLocationsDataForSite(SITE_NAME, BearingConfiguration.Approach.FINGERPRINT, callback);62 Mockito.verify(dataUploader, Mockito.atLeastOnce())63 .uploadLocationsForSite(Mockito.anyString(), Mockito.any(BearingConfiguration.Approach.class), Mockito.any(BearingClientCallback.class));64 bearingRestClient.uploadClassifierData(SITE_NAME, callback);65 Mockito.verify(dataUploader, Mockito.atLeastOnce())66 .uploadClassifierData(Mockito.anyString(), Mockito.any(BearingClientCallback.class));67 bearingRestClient.generateSVMTOnServer(SITE_NAME, BearingConfiguration.Approach.FINGERPRINT, callback);68 Mockito.verify(dataUploader, Mockito.atLeastOnce())69 .generateClassifierDataOnServer(Mockito.anyString(), Mockito.any(BearingConfiguration.Approach.class), Mockito.any(BearingClientCallback.class));70 bearingRestClient.renameSiteOnServer(SITE_NAME, SITE_NAME, callback);71 Mockito.verify(dataUploader, Mockito.atLeastOnce())72 .renameSiteOnServer(Mockito.anyString(), Mockito.anyString(), Mockito.any(BearingClientCallback.class));73 bearingRestClient.processDataOnServer(SITE_NAME, new ArrayList<SnapshotObservation>(), new ArrayList<BearingConfiguration.SensorType>(), callback);74 Mockito.verify(dataUploader, Mockito.atLeastOnce())75 .processDataOnServer(Mockito.anyString(), Mockito.anyListOf(SnapshotObservation.class), Mockito.anyListOf(BearingConfiguration.SensorType.class), Mockito.any(BearingClientCallback.class));76 bearingRestClient.uploadSiteThreshLocationsData(SITE_NAME, callback);77 Mockito.verify(dataUploader, Mockito.atLeastOnce())78 .uploadSiteThreshLocationsData(Mockito.anyString(), Mockito.any(BearingClientCallback.class));79 }80 @Test81 public void testDownloads() {82 final String SITE_NAME = "SITE_NAME";83 bearingRestClient.downloadSiteData(SITE_NAME, callback);84 Mockito.verify(dataDownloader, Mockito.atLeastOnce())85 .downloadSiteData(Mockito.anyString(), Mockito.any(BearingClientCallback.class));86 bearingRestClient.downloadLocationData(SITE_NAME, "LOC_NAME", callback);87 Mockito.verify(dataDownloader, Mockito.atLeastOnce())88 .downloadLocationData(Mockito.anyString(), Mockito.anyString(), Mockito.any(BearingClientCallback.class));89 bearingRestClient.downloadLocationsDataForSite(SITE_NAME, callback);90 Mockito.verify(dataDownloader, Mockito.atLeastOnce())91 .downloadAllLocationDataForSiteFromServer(Mockito.anyString(), Mockito.any(BearingClientCallback.class));92 bearingRestClient.downloadClassifierData(SITE_NAME, true, callback);93 Mockito.verify(dataDownloader, Mockito.atLeastOnce())94 .downloadClassifierData(Mockito.anyString(), Mockito.anyBoolean(), Mockito.any(BearingClientCallback.class));95 bearingRestClient.getAllSiteNames(getDataCallback);96 Mockito.verify(dataDownloader, Mockito.atLeastOnce())97 .getAllSiteNames(Mockito.any(BearingClientCallback.GetDataCallback.class));98 bearingRestClient.getAllLocationNamesForSite(SITE_NAME, getDataCallback);99 Mockito.verify(dataDownloader, Mockito.atLeastOnce())100 .getAllLocationNames(Mockito.anyString(), Mockito.any(BearingClientCallback.GetDataCallback.class));101 bearingRestClient.getClusterData(SITE_NAME, callback);102 Mockito.verify(dataDownloader, Mockito.atLeastOnce())103 .getClusterData(Mockito.anyString(), Mockito.any(BearingClientCallback.class));104 bearingRestClient.downloadSourceIdMap(callback);105 Mockito.verify(dataDownloader, Mockito.atLeastOnce())106 .downloadSourceIdMap(Mockito.any(BearingClientCallback.class));107 bearingRestClient.downloadSiteThreshData(SITE_NAME, callback);108 Mockito.verify(dataDownloader, Mockito.atLeastOnce())109 .downloadSourceIdMap(Mockito.any(BearingClientCallback.class));110 }111 @Test112 public void deleteSiteDataTest(){113 StorageType storageType = null;114 bearingRestClient.deleteSiteData("siteName", storageType, callback);115 Mockito.verify(dataTrimmer,Mockito.atLeastOnce()).deleteSiteData(Mockito.anyString(), Mockito.any(BearingClientCallback.class));116 }117 @Test118 public void deleteLocationDataTest(){119 StorageType storageType = null;120 bearingRestClient.deleteLocationData("siteName", "locationName", storageType, callback);121 Mockito.verify(dataTrimmer,Mockito.atLeastOnce()).deleteLocationData(Mockito.anyString(), Mockito.anyString(), Mockito.any(StorageType.class), Mockito.any(BearingClientCallback.class));122 }123}...
Source:PreGeneralizedFeatureSourceNotCachedTest.java
...15 * Lesser General Public License for more details.16 */17package org.geotools.data.gen;18import static org.mockito.ArgumentMatchers.any;19import static org.mockito.Mockito.atLeastOnce;20import static org.mockito.Mockito.spy;21import org.geotools.data.Query;22import org.geotools.data.Repository;23import org.geotools.data.Transaction;24import org.geotools.util.factory.Hints;25import org.junit.Assert;26import org.junit.Test;27import org.mockito.Mockito;28public class PreGeneralizedFeatureSourceNotCachedTest29 extends AbstractPreGeneralizedFeatureSourceTest {30 static final String ConfigName = "src/test/resources/geninfo_shapefile.xml";31 private Repository repository;32 @Override33 protected Repository getRepository() {34 repository = spy(new DSFinderRepository());35 return repository;36 }37 @Test38 public void getBoundsHitsRepositoryDataStore() {39 try {40 PreGeneralizedDataStore ds = getDataStore(ConfigName);41 PreGeneralizedFeatureSource fs =42 (PreGeneralizedFeatureSource) ds.getFeatureSource("GenStreams");43 fs.getBounds();44 Mockito.verify(repository, atLeastOnce()).dataStore(any());45 Mockito.clearInvocations(repository);46 fs.getBounds();47 Mockito.verify(repository, atLeastOnce()).dataStore(any());48 Mockito.clearInvocations(repository);49 Query query1 = new Query("GenStreams");50 fs.getCount(query1);51 Mockito.verify(repository, atLeastOnce()).dataStore(any());52 Mockito.clearInvocations(repository);53 Query query2 = new Query("GenStreams");54 query2.getHints().put(Hints.GEOMETRY_DISTANCE, 0.0);55 fs.getFeatures(query2);56 Mockito.verify(repository, atLeastOnce()).dataStore(any());57 Mockito.clearInvocations(repository);58 Query query3 = new Query("GenStreams");59 query3.getHints().put(Hints.GEOMETRY_DISTANCE, 1.0);60 fs.getFeatures(query2);61 Mockito.verify(repository, atLeastOnce()).dataStore(any());62 Mockito.clearInvocations(repository);63 Query query4 = new Query("GenStreams");64 query4.getHints().put(Hints.GEOMETRY_DISTANCE, 5.0);65 fs.getFeatures(query3);66 Mockito.verify(repository, atLeastOnce()).dataStore(any());67 Mockito.clearInvocations(repository);68 Query query5 = new Query("GenStreams");69 query4.getHints().put(Hints.GEOMETRY_DISTANCE, 1.0);70 ds.getFeatureReader(query5, Transaction.AUTO_COMMIT);71 Mockito.verify(repository, atLeastOnce()).dataStore(any());72 Mockito.clearInvocations(repository);73 fs.getInfo();74 Mockito.verify(repository, atLeastOnce()).dataStore(any());75 Mockito.clearInvocations(repository);76 } catch (Exception ex) {77 Assert.fail(ex.getMessage());78 }79 }80}...
Source:TextComponentTest.java
...33import org.junit.runner.RunWith;34import static org.mockito.Matchers.anyInt;35import static org.mockito.Matchers.eq;36import org.mockito.Mock;37import static org.mockito.Mockito.atLeastOnce;38import static org.mockito.Mockito.mock;39import static org.mockito.Mockito.times;40import static org.mockito.Mockito.verify;41import static org.mockito.Mockito.when;42import org.mockito.runners.MockitoJUnitRunner;4344@RunWith(MockitoJUnitRunner.class)45public class TextComponentTest46{47 @Mock48 private Graphics2D graphics;49 50 @Before51 public void before()52 {53 when(graphics.getFontMetrics()).thenReturn(mock(FontMetrics.class));54 }55 56 @Test57 public void testRender()58 {59 TextComponent textComponent = new TextComponent();60 textComponent.setText("test");61 textComponent.setColor(Color.RED);62 textComponent.render(graphics);63 verify(graphics, times(2)).drawString(eq("test"), anyInt(), anyInt());64 verify(graphics, atLeastOnce()).setColor(Color.RED);65 }66 67 @Test68 public void testRender2()69 {70 TextComponent textComponent = new TextComponent();71 textComponent.setText("<col=0000ff>test");72 textComponent.render(graphics);73 verify(graphics, times(2)).drawString(eq("test"), anyInt(), anyInt());74 verify(graphics, atLeastOnce()).setColor(Color.BLUE);75 }76 77 @Test78 public void testRender3()79 {80 TextComponent textComponent = new TextComponent();81 textComponent.setText("<col=0000ff>test<col=00ff00> test");82 textComponent.render(graphics);83 verify(graphics, atLeastOnce()).drawString(eq("test"), anyInt(), anyInt());84 verify(graphics, atLeastOnce()).drawString(eq(" test"), anyInt(), anyInt());85 verify(graphics, atLeastOnce()).setColor(Color.BLUE);86 verify(graphics, atLeastOnce()).setColor(Color.GREEN);87 }
...
Source:ArticleCommandTest.java
...35 public void articleTest() throws UnsupportedEncodingException, IOException, StorageBackendException, ParseException{36 37 ArticleCommand a = new ArticleCommand();38 a.processLine(conn, "article", "article".getBytes("UTF-8"));39 verify(conn, atLeastOnce()).println(startsWith("420")); //Current article is invalid40 41 Article art0 = Mockito.mock(Article.class);//mock article42 when(storage.getArticle("<messageid@foo.bar>", null)).thenReturn(art0);43 when(art0.getMsgID_host()).thenReturn("foo.bar");44 45 a.processLine(conn, "article <messageid@foo.bar>", "article <messageid@foo.bar>".getBytes("UTF-8"));46 verify(conn, atLeastOnce()).println(startsWith("220")); 47 verify(conn, atLeastOnce()).println(".");48 49 a.processLine(conn, "body <messageid@foo.bar>", "body <messageid@foo.bar>".getBytes("UTF-8"));50 verify(conn, atLeastOnce()).println(startsWith("222")); 51 verify(conn, atLeastOnce()).println(".");52 53 a.processLine(conn, "head <messageid@foo.bar>", "head <messageid@foo.bar>".getBytes("UTF-8"));54 verify(conn, atLeastOnce()).println(startsWith("221")); 55 verify(conn, atLeastOnce()).println(".");56 57 when(storage.getArticle(null, 2)).thenReturn(art0);58 a.processLine(conn, "article 2", "article 2".getBytes("UTF-8"));59 verify(conn, atLeastOnce()).println(startsWith("220")); 60 verify(conn, atLeastOnce()).println(".");61 62 }63}...
atLeastOnce
Using AI Code Generation
1package com.ack.junit.mock;2import static org.mockito.Mockito.atLeastOnce;3import static org.mockito.Mockito.mock;4import static org.mockito.Mockito.verify;5public class AtLeastOnceDemo {6 public static void main( String[] args ) {7 MyInterface myInterface = mock( MyInterface.class );8 myInterface.doSomething();9 verify( myInterface, atLeastOnce() ).doSomething();10 }11}12package com.ack.junit.mock;13public interface MyInterface {14 public void doSomething();15}16package com.ack.junit.mock;17import static org.mockito.Mockito.atLeast;18import static org.mockito.Mockito.mock;19import static org.mockito.Mockito.verify;20public class AtLeastDemo {21 public static void main( String[] args ) {22 MyInterface myInterface = mock( MyInterface.class );23 myInterface.doSomething();24 myInterface.doSomething();25 myInterface.doSomething();26 verify( myInterface, atLeast( 2 ) ).doSomething();27 }28}29package com.ack.junit.mock;30import static org.mockito.Mockito.atMost;31import static org.mockito.Mockito.mock;32import static org.mockito.Mockito.verify;33public class AtMostDemo {34 public static void main( String[] args ) {35 MyInterface myInterface = mock( MyInterface.class );36 myInterface.doSomething();37 myInterface.doSomething();38 myInterface.doSomething();39 verify( myInterface, atMost( 3 ) ).doSomething();40 }41}42package com.ack.junit.mock;43import static org.mockito.Mockito.atMostOnce;44import static org.mockito.Mockito.mock;45import static org.mockito.Mockito.verify;46public class AtMostOnceDemo {47 public static void main( String[] args ) {48 MyInterface myInterface = mock( MyInterface.class );49 myInterface.doSomething();
atLeastOnce
Using AI Code Generation
1import static org.mockito.Mockito.atLeastOnce;2import static org.mockito.Mockito.mock;3import static org.mockito.Mockito.verify;4import java.util.List;5public class AtLeastOnce {6 public static void main(String[] args) {7 List<String> mockList = mock(List.class);8 mockList.add("one");9 mockList.add("two");10 mockList.add("three");11 mockList.add("four");12 verify(mockList, atLeastOnce()).add("one");13 verify(mockList, atLeastOnce()).add("two");14 verify(mockList, atLeastOnce()).add("three");15 verify(mockList, atLeastOnce()).add("four");16 }17}
atLeastOnce
Using AI Code Generation
1import static org.mockito.Mockito.*;2import org.mockito.*;3import org.mockito.exceptions.*;4import org.mockito.stubbing.*;5import org.mockito.invocation.*;6import org.mockito.verification.*;7import org.mockito.matchers.*;8import org.mockito.configuration.*;9import org.mockito.listeners.*;10import org.mockito.cglib.*;11import org.mockito.cglib.core.*;12import org.mockito.cglib.proxy.*;13import org.mockito.cglib.transform.*;14import org.mockito.cglib.transform.impl.*;15import org.mockito.cglib.util.*;16import org.mockito.cglib.asm.*;17import org.mockito.cglib.beans.*;18import org.mockito.cglib.reflect.*;19import org.mockito.asm.*;20import org.mockito.asm.tree.*;21import org.mockito.asm.util.*;22import org.junit.Test;23import org.junit.runner.RunWith;24import org.junit.runners.JUnit4;25import static org.junit.Assert.*;26@RunWith(JUnit4.class)27public class atLeastOnceTest {28 public void test() {29 List mockList = mock(List.class);30 mockList.add("one");31 mockList.clear();32 verify(mockList).add("one");33 verify(mockList).clear();34 verify(mockList, atLeastOnce()).add("one");35 verify(mockList, atLeastOnce()).clear();36 }37}
atLeastOnce
Using AI Code Generation
1import static org.mockito.Mockito.*;2import java.util.LinkedList;3import org.junit.Test;4public class Test1 {5 public void test1() {6 LinkedList mockedList = mock(LinkedList.class);7 when(mockedList.get(0)).thenReturn("first");8 when(mockedList.get(1)).thenThrow(new RuntimeException());9 System.out.println(mockedList.get(0));10 System.out.println(mockedList.get(999));11 }12 public void test2() {13 LinkedList mockedList = mock(LinkedList.class);14 when(mockedList.get(anyInt())).thenReturn("element");15 System.out.println(mockedList.get(9));16 System.out.println(mockedList.get(999));17 }18 public void test3() {19 LinkedList mockedList = mock(LinkedList.class);20 when(mockedList.get(anyInt())).thenReturn("element").thenThrow(new RuntimeException());21 System.out.println(mockedList.get(9));22 System.out.println(mockedList.get(999));23 }24 public void test4() {25 LinkedList mockedList = mock(LinkedList.class);26 when(mockedList.get(anyInt())).thenThrow(new RuntimeException());27 System.out.println(mockedList.get(9));28 System.out.println(mockedList.get(999));29 }30 public void test5() {31 LinkedList mockedList = mock(LinkedList.class);32 when(mockedList.get(anyInt())).thenThrow(new RuntimeException()).thenReturn("element");33 System.out.println(mockedList.get(9));34 System.out.println(mockedList.get(999));35 }36 public void test6() {37 LinkedList mockedList = mock(LinkedList.class);38 when(mockedList.get(anyInt())).thenThrow(new RuntimeException()).thenReturn("element");39 System.out.println(mockedList.get(9));40 System.out.println(mockedList.get(999));41 System.out.println(mockedList.get(999));42 }43 public void test7() {44 LinkedList mockedList = mock(LinkedList.class);45 when(mockedList.get(anyInt())).thenThrow(new RuntimeException()).thenReturn("element");46 System.out.println(mockedList.get(9));47 System.out.println(mockedList.get(999));48 System.out.println(mockedList.get(999));49 System.out.println(mockedList.get(999));50 }51 public void test8() {52 LinkedList mockedList = mock(LinkedList.class);53 when(mockedList.get(anyInt
atLeastOnce
Using AI Code Generation
1import org.junit.Test;2import org.mockito.Mockito;3import java.util.List;4public class MockitoExample {5 public void test() {6 List mockedList = Mockito.mock(List.class);7 Mockito.when(mockedList.get(0)).thenReturn("first");8 mockedList.get(0);9 Mockito.verify(mockedList).get(0);10 Mockito.verify(mockedList, Mockito.times(1)).get(0);11 Mockito.verify(mockedList, Mockito.never()).get(0);12 Mockito.verify(mockedList, Mockito.atLeastOnce()).get(0);13 Mockito.verify(mockedList, Mockito.atLeast(1)).get(0);14 Mockito.verify(mockedList, Mockito.atMost(1)).get(0);15 Mockito.verify(mockedList, Mockito.only()).get(0);16 }17}18list.get(0);19-> at MockitoExample.test(MockitoExample.java:22)20-> at List.get(List.java:0)21list.get(0);22-> at MockitoExample.test(MockitoExample.java:22)23-> at List.get(List.java:0)24list.get(0);25-> at MockitoExample.test(MockitoExample.java:22)26-> at List.get(List.java:0)27-> at MockitoExample.test(MockitoExample.java:22)28-> at List.get(List.java:0)29list.get(0);30-> at MockitoExample.test(MockitoExample.java:22)31-> at List.get(List.java:0)
atLeastOnce
Using AI Code Generation
1import static org.mockito.Mockito.*;2import org.mockito.Mockito;3public class 1 {4 public static void main(String[] args) {5 List mockList = mock(List.class);6 mockList.add("one");7 mockList.clear();8 verify(mockList).add("one");9 verify(mockList).clear();10 }11}
atLeastOnce
Using AI Code Generation
1import org.mockito.Mockito;2public class MockitoExample {3 public static void main(String args[]) {4 List mockedList = Mockito.mock(List.class);5 mockedList.add("one");6 mockedList.clear();7 Mockito.verify(mockedList).add("one");8 Mockito.verify(mockedList).clear();9 }10}
atLeastOnce
Using AI Code Generation
1import org.mockito.Mockito;2import org.mockito.InOrder;3import org.mockito.ArgumentCaptor;4import org.mockito.verification.VerificationMode;5public class 1 {6 public static void main(String[] args) {7 VerificationMode mode = Mockito.atLeastOnce();8 }9}
atLeastOnce
Using AI Code Generation
1import static org.mockito.Mockito.*;2public class 1 {3 public static void main(String[] args) {4 List mockList = mock(List.class);5 mockList.add("one");6 mockList.clear();7 verify(mockList).add("one");8 verify(mockList).clear();9 }10}11mockList.clear();12-> at 1.main(1.java:13)13-> at 1.main(1.java:13)14-> at 1.main(1.java:12)15import static org.mockito.Mockito.*;16public class 2 {17 public static void main(String[] args) {18 List mockList = mock(List.class);19 mockList.add("one");20 verify(mockList).add("one");21 verify(mockList, atLeastOnce()).clear();22 }23}24-> at 2.main(2.java:13)25-> at 2.main(2.java:12)26import static org.mockito.Mockito.*;27public class 3 {28 public static void main(String[] args) {29 List mockList = mock(List.class);30 mockList.add("one");
atLeastOnce
Using AI Code Generation
1import org.mockito.Mockito;2import org.mockito.InOrder;3import org.junit.Test;4import static org.junit.Assert.assertEquals;5import static org.mockito.Mockito.*;6public class TestClass{7 public void test(){8 TestClass mockTest = mock(TestClass.class);9 mockTest.add("this is add method");10 mockTest.add("this is add method");11 verify(mockTest, atLeastOnce()).add("this is add method");12 }13 public void add(String str){14 System.out.println(str);15 }16}17AtLeastOnce() method of Mockito class18import org.mockito.Mockito;19import org.mockito.InOrder;20import org.junit.Test;21import static org.junit.Assert.assertEquals;22import static org.mockito.Mockito.*;23public class TestClass{24 public void test(){25 TestClass mockTest = mock(TestClass.class);26 mockTest.add("this is add method");27 verify(mockTest, atLeastOnce()).add("this is add method");28 }29 public void add(String str){30 System.out.println(str);31 }32}33AtMost() method of Mockito class34import org.mockito.Mockito;35import org.mockito.InOrder;36import org.junit.Test;37import static org.junit.Assert.assertEquals;38import static org.mockito.Mockito.*;39public class TestClass{40 public void test(){41 TestClass mockTest = mock(TestClass.class);42 mockTest.add("this is add method");43 mockTest.add("
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!