private static void verifyLogging( Log log, VerificationMode mode ) { verify( log, mode ).info( anyString(), Mockito.<Object[]>anyVararg() ); }
return new String[] {(String) invocationOnMock.getArguments()[1]}; }).when(yarnConf).getStrings(anyString(), Mockito.<String> anyVararg());
case "error": if (hasThrowableParam(method)) { verify(mockLogger, times(1)).error(any(Throwable.class), anyString(), anyVararg()); } else { verify(mockLogger, times(1)).error(anyString(), Matchers.<Object[]>anyVararg()); case "warn": if (hasThrowableParam(method)) { verify(mockLogger, times(1)).warn(any(Throwable.class), anyString(), anyVararg()); } else { verify(mockLogger, times(1)).warn(anyString(), Matchers.<Object[]>anyVararg()); case "info": if (hasThrowableParam(method)) { verify(mockLogger, times(1)).info(any(Throwable.class), anyString(), anyVararg()); } else { verify(mockLogger, times(1)).info(anyString(), Matchers.<Object[]>anyVararg()); case "debug": if (hasThrowableParam(method)) { verify(mockLogger, times(1)).debug(any(Throwable.class), anyString(), anyVararg()); } else { verify(mockLogger, times(1)).debug(anyString(), Matchers.<Object[]>anyVararg()); case "trace": if (hasThrowableParam(method)) { verify(mockLogger, times(1)).trace(any(Throwable.class), anyString(), anyVararg()); } else { verify(mockLogger, times(1)).trace(anyString(), anyVararg());
private void givenThereIsADevice(String exchangeCode, String exchangeName, String exchangePostcode, String hostname, String serialNumber, DeviceType type, int availablePorts) { Map<String, Object> details = detailsForDevice(exchangeCode, exchangeName, exchangePostcode, hostname, serialNumber, type, availablePorts); when(jdbcTemplate.queryForMap(anyString(), anyVararg())).thenReturn(details); }
private void givenThereIsntADevice() { when(jdbcTemplate.queryForMap(anyString(), anyVararg())).thenThrow(new IncorrectResultSizeDataAccessException(1)); }
@Before public void setUp() throws Exception { appContext = mock(AppContext.class); subAppContext = mock(SubAppContext.class); componentProvider = mock(ComponentProvider.class); doReturn(mock(DummyRule.class)).when(componentProvider).newInstance(any(Class.class), anyVararg()); view = mock(ContentSubAppView.class); workbench = mock(BrowserPresenter.class); ActionbarPresenter actionbarPresenter = mock(ActionbarPresenter.class); when(workbench.getActionbarPresenter()).thenReturn(actionbarPresenter); subAppEventBus = mock(EventBus.class); this.subApp = new DummyContentSubApp(null, subAppContext, view, workbench, subAppEventBus); }
@Test public void shouldSetMovedPermanentlyStatusOfLogic() throws Exception { when(config.getApplicationPath()).thenReturn("http://myapp.com"); Method method = Resource.class.getDeclaredMethod("method"); when(router.urlFor(eq(Resource.class), eq(method), Mockito.anyVararg())).thenReturn("/resource/method"); status.movedPermanentlyTo(Resource.class).method(); verify(response).setStatus(301); verify(response).addHeader("Location", "http://myapp.com/resource/method"); }
/******************************************************************************************************************* * ******************************************************************************************************************/ @BeforeMethod public void setup() { ContextManager.Locator.set(null); context = new ClassPathXmlApplicationContext("DefaultStructureEditorPresentationControlTestBeans.xml"); underTest = context.getBean(DefaultStructureEditorPresentationControl.class); presentation = context.getBean(StructureEditorPresentation.class); siteNode = mock(SiteNode.class); properties = mock(ResourceProperties.class); presentable = mock(Presentable.class); pm = mock(PresentationModel.class); when(siteNode.getProperties()).thenReturn(properties); when(presentable.createPresentationModel(anyVararg())).thenReturn(pm); when(properties.as(eq(Presentable))).thenReturn(presentable); }
@Before public void setup() { final TranslationService translationService = mock(TranslationService.class); doAnswer(invocationOnMock -> invocationOnMock.getArguments()[0]) .when(translationService).format(any(), anyVararg()); preference = spy(new PortablePreferenceMockPortableGeneratedImpl()); formView = mock(DefaultPreferenceForm.View.class); formPresenter = new DefaultPreferenceForm(formView, translationService); Map<String, String> params = new HashMap<>(); params.put("id", "preference-id"); formPresenter.onStartup(new DefaultPlaceRequest("preferenceForm", params)); }
@Before public void setup() { final TranslationService translationService = mock(TranslationService.class); doAnswer(invocationOnMock -> invocationOnMock.getArguments()[0]) .when(translationService).format(any(), anyVararg()); preference = spy(new PortablePreferenceMockPortableGeneratedImpl()); formView = mock(DefaultPreferenceForm.View.class); formPresenter = new DefaultPreferenceForm(formView, translationService); Map<String, String> params = new HashMap<>(); params.put("id", "preference-id"); formPresenter.onStartup(new DefaultPlaceRequest("preferenceForm", params)); }
@Test public void testUseIOServiceToDeleteSubModule() { when(path.getFileName()).thenReturn("pom.xml"); when(path.toURI()).thenReturn("file://space/project1/subproject/pom.xml"); when(ioService.exists(any())).thenReturn(true); when(resourceResolver.resolveModule(any(Path.class))).thenReturn(module); when(pomService.load(any())).thenReturn(mock(POM.class)); Repository repo = mock(Repository.class); when(repoService.getRepository(path)).thenReturn(repo); String alias = "repo-alias"; when(repo.getAlias()).thenReturn(alias); Space space = new Space("space"); when(repo.getSpace()).thenReturn(space); abstractProjectService.delete(path, ""); verify(repoService, times(0)).removeRepository(any(), any()); verify(ioService).delete(eq(Paths.get("file://space/project1/subproject")), anyVararg()); } }
@Test public void testUseIOServiceToDeleteSubModule() { when(path.getFileName()).thenReturn("pom.xml"); when(path.toURI()).thenReturn("file://space/project1/subproject/pom.xml"); when(ioService.exists(any())).thenReturn(true); when(resourceResolver.resolveModule(any(Path.class))).thenReturn(module); when(pomService.load(any())).thenReturn(mock(POM.class)); Repository repo = mock(Repository.class); when(repoService.getRepository(path)).thenReturn(repo); String alias = "repo-alias"; when(repo.getAlias()).thenReturn(alias); Space space = new Space("space"); when(repo.getSpace()).thenReturn(space); abstractProjectService.delete(path, ""); verify(repoService, times(0)).removeRepository(any(), any()); verify(ioService).delete(eq(Paths.get("file://space/project1/subproject")), anyVararg()); } }
@Test public void testGetActionBoard() { //Given Board mockBoard = new Board(); mockBoard.setId("idBoard"); when(httpClient.get(anyString(), any(Class.class), (String[]) anyVararg())).thenReturn(mockBoard); //When Board actionBoard = trello.getActionBoard("idBoard"); //Then assertThat(actionBoard).isNotNull(); assertThat(actionBoard.getId()).isEqualTo("idBoard"); verify(httpClient).get(eq("https://api.trello.com/1/actions/{actionId}/board?key={applicationKey}&token={userToken}"), eq(Board.class), eq("idBoard"), eq(""), eq("")); }
@Test public void testGetActionMemberCreator() { //Given Member mockMember = new Member(); mockMember.setId("idMember"); when(httpClient.get(anyString(), any(Class.class), (String[]) anyVararg())).thenReturn(mockMember); //When Member actionMember = trello.getActionMemberCreator("idMember"); //Then assertThat(actionMember).isNotNull(); assertThat(actionMember.getId()).isEqualTo("idMember"); verify(httpClient).get(eq("https://api.trello.com/1/actions/{actionId}/memberCreator?key={applicationKey}&token={userToken}"), eq(Member.class), eq("idMember"), eq(""), eq("")); }
@Test public void testGetActionList() { //Given TList mockList = new TList(); mockList.setId("idList"); when(httpClient.get(anyString(), any(Class.class), (String[]) anyVararg())).thenReturn(mockList); //When TList actionList = trello.getActionList("idList"); //Then assertThat(actionList).isNotNull(); assertThat(actionList.getId()).isEqualTo("idList"); verify(httpClient).get(eq("https://api.trello.com/1/actions/{actionId}/list?key={applicationKey}&token={userToken}"), eq(TList.class), eq("idList"), eq(""), eq("")); }
@Test public void testGetActionMember() { //Given Member mockMember = new Member(); mockMember.setId("idMember"); when(httpClient.get(anyString(), any(Class.class), (String[]) anyVararg())).thenReturn(mockMember); //When Member actionMember = trello.getActionMember("idMember"); //Then assertThat(actionMember).isNotNull(); assertThat(actionMember.getId()).isEqualTo("idMember"); verify(httpClient).get(eq("https://api.trello.com/1/actions/{actionId}/member?key={applicationKey}&token={userToken}"), eq(Member.class), eq("idMember"), eq(""), eq("")); }
@Test public void testGetActionCard() { //Given Card mockCard = new Card(); mockCard.setId("idCard"); when(httpClient.get(anyString(), any(Class.class), (String[]) anyVararg())).thenReturn(mockCard); //When Card actionCard = trello.getActionCard("idCard"); //Then assertThat(actionCard).isNotNull(); assertThat(actionCard.getId()).isEqualTo("idCard"); verify(httpClient).get(eq("https://api.trello.com/1/actions/{actionId}/card?key={applicationKey}&token={userToken}"), eq(Card.class), eq("idCard"), eq(""), eq("")); }
@Test public void moveNodeIntoNode() throws Exception { //GIVEN definition.setMoveLocation(MoveLocation.INSIDE); when(provider.newInstance(any(Class.class), anyVararg())).thenReturn(action); //WHEN executor.execute(MOVE_ACTION_NAME); //THEN assertThat(node3.getJcrItem(), hasNode(NODE_NAME_1)); assertThat(node3.getJcrItem(), hasNode(NODE_NAME_2)); verify(adminCentralEventBusMock, times(1)).fireEvent(any(ContentChangedEvent.class)); }
@Test public void movePropertyIntoNode() throws Exception { //GIVEN action = new MoveNodeAction(definition, Arrays.asList(property1), node1, adminCentralEventBusMock, mock(UiContext.class), callback, new TreeViewDropHandler(null, null)); definition.setMoveLocation(MoveLocation.INSIDE); when(provider.newInstance(any(Class.class), anyVararg())).thenReturn(action); //WHEN executor.execute(MOVE_ACTION_NAME); //THEN assertThat(node1.getJcrItem(), hasProperty(PROPERTY_NAME_1)); assertThat(node2.getJcrItem(), not(hasProperty(PROPERTY_NAME_1))); verify(adminCentralEventBusMock, times(1)).fireEvent(any(ContentChangedEvent.class)); }
@Test public void testGetActionById() { //Given Action mockAction = new Action(); mockAction.setId("idAction"); mockAction.setType("createCard"); when(httpClient.get(anyString(), any(Class.class), (String[]) anyVararg())).thenReturn(mockAction); //When Action action = trello.getAction("idAction"); //Then assertThat(action).isNotNull(); assertThat(action.getId()).isEqualTo("idAction"); assertThat(action.getType()).isEqualTo("createCard"); verify(httpClient).get(eq("https://api.trello.com/1/actions/{actionId}?key={applicationKey}&token={userToken}"), eq(Action.class), eq("idAction"), eq(""), eq("")); verifyNoMoreInteractions(httpClient); }