Java Code Examples for org.mockito.Mockito#verify()
The following examples show how to use
org.mockito.Mockito#verify() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestXUserREST.java From ranger with Apache License 2.0 | 6 votes |
@Test public void test54createXAuditMapVxResourceNull() { VXAuditMap testvXAuditMap = createVXAuditMapObj(); testvXAuditMap.setResourceId(null); Mockito.when(xResourceService.readResource(testvXAuditMap.getResourceId())).thenReturn(null); Mockito.when(restErrorUtil.createRESTException(Mockito.anyString(), (MessageEnums)Mockito.any())).thenThrow(new WebApplicationException()); thrown.expect(WebApplicationException.class); VXAuditMap retvXAuditMap= xUserRest.createXAuditMap(testvXAuditMap); assertEquals(testvXAuditMap.getId(),retvXAuditMap.getId()); assertEquals(testvXAuditMap.getClass(),retvXAuditMap.getClass()); assertNotNull(retvXAuditMap); Mockito.verify(xUserMgr).createXAuditMap(testvXAuditMap); Mockito.verify(xResourceService).readResource(testvXAuditMap.getResourceId()); Mockito.verify(restErrorUtil.createRESTException(Mockito.anyString(), (MessageEnums)Mockito.any())); }
Example 2
Source File: TestXUserREST.java From ranger with Apache License 2.0 | 6 votes |
@Test public void test50getXAuditMapVXAuditMapNull() { VXAuditMap testvXAuditMap = createVXAuditMapObj(); Mockito.when(xUserMgr.getXAuditMap(testvXAuditMap.getResourceId())).thenReturn(testvXAuditMap); Mockito.when(restErrorUtil.createRESTException(Mockito.anyString(), (MessageEnums)Mockito.any())).thenThrow(new WebApplicationException()); thrown.expect(WebApplicationException.class); VXAuditMap retVXAuditMap=xUserRest.getXAuditMap(testvXAuditMap.getResourceId()); assertEquals(testvXAuditMap.getId(),retVXAuditMap.getId()); assertEquals(testvXAuditMap.getClass(),retVXAuditMap.getClass()); assertNotNull(retVXAuditMap); Mockito.verify(xUserMgr).getXAuditMap(testvXAuditMap.getResourceId()); Mockito.verify(xResourceService).readResource(null); Mockito.verify(restErrorUtil.createRESTException(Mockito.anyString(), (MessageEnums)Mockito.any())); }
Example 3
Source File: ServiceResponseDecoderTest.java From Poseidon with Apache License 2.0 | 6 votes |
/** * Success case - in case of 200 * @throws Exception */ @Test public void testDecodeHttpResponse() throws Exception { HttpResponse mockHttpResponse = mock(HttpResponse.class); StatusLine mockStatusLine = mock(StatusLine.class); HttpEntity mockEntity = mock(HttpEntity.class); InputStream stream = mock(InputStream.class); mockStatic(IOUtils.class); when(mockStatusLine.getStatusCode()).thenReturn(200); when(mockHttpResponse.getStatusLine()).thenReturn(mockStatusLine); when(mockHttpResponse.getEntity()).thenReturn(mockEntity); when(mockEntity.getContent()).thenReturn(stream); BDDMockito.when(IOUtils.toString(stream)).thenReturn("success"); when(mockJavaType.getRawClass()).thenReturn(responseClass); ServiceResponseDecoder decoder = spy(new ServiceResponseDecoder(mockMapper, mockJavaType, mockErrorType, mockLogger , exceptions, collectedHeaders)); ServiceResponse response = decoder.decode(mockHttpResponse); assertEquals("success", response.getDataList().get(0)); Mockito.verify(mockLogger, Mockito.never()); }
Example 4
Source File: AbstractInteropTest.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
/** * Wrapper around {@link Mockito#verify}, to keep log spam down on failure. */ private static <T> T verify(T mock, VerificationMode mode) { try { return Mockito.verify(mock, mode); } catch (final AssertionError e) { String msg = e.getMessage(); if (msg.length() >= 256) { // AssertionError(String, Throwable) only present in Android API 19+ throw new AssertionError(msg.substring(0, 256)) { @Override public synchronized Throwable getCause() { return e; } }; } throw e; } }
Example 5
Source File: TestVarStrategy.java From JVoiceXML with GNU Lesser General Public License v2.1 | 6 votes |
/** * Test method for * {@link VarStrategy#execute(org.jvoicexml.interpreter.VoiceXmlInterpreterContext, org.jvoicexml.interpreter.VoiceXmlInterpreter, org.jvoicexml.interpreter.FormInterpretationAlgorithm, org.jvoicexml.interpreter.FormItem, org.jvoicexml.xml.VoiceXmlNode)} * . * * @exception Exception * Test failed. */ @Test public void testExecuteUndefined() throws Exception { final String name = "test"; final Block block = createBlock(); final Var var = block.appendChild(Var.class); var.setName(name); final VarStrategy strategy = new VarStrategy(); try { executeTagStrategy(var, strategy); } catch (JVoiceXMLEvent e) { Assert.fail(e.getMessage()); } final DataModel model = getDataModel(); Mockito.verify(model.createVariable(name)); }
Example 6
Source File: CommandRule.java From claudb with MIT License | 5 votes |
@SuppressWarnings("unchecked") public <T> T verify(Class<T> type) { if (type.equals(ServerContext.class)) { return (T) Mockito.verify(server); } else if (type.equals(DBServerContext.class)) { return (T) Mockito.verify(server); } else if (type.equals(Session.class)) { return (T) Mockito.verify(session); } throw new IllegalArgumentException(); }
Example 7
Source File: TestXUserREST.java From ranger with Apache License 2.0 | 5 votes |
@Test public void test57updateXAuditMapNull() { VXAuditMap testvXAuditMap = createVXAuditMapObj(); Mockito.when(restErrorUtil.createRESTException(Mockito.anyString(), (MessageEnums)Mockito.any())).thenThrow(new WebApplicationException()); thrown.expect(WebApplicationException.class); VXAuditMap retvXAuditMap=xUserRest.updateXAuditMap(testvXAuditMap); assertNull(retvXAuditMap); Mockito.verify(xUserMgr).updateXAuditMap(testvXAuditMap); Mockito.verify(xResourceService).readResource(null); Mockito.verify(restErrorUtil.createRESTException(Mockito.anyString(), (MessageEnums)Mockito.any())); }
Example 8
Source File: CommandRule.java From resp-server with MIT License | 5 votes |
@SuppressWarnings("unchecked") public <T> T verify(Class<T> type) { if (type.equals(ServerContext.class)) { return (T) Mockito.verify(server); } else if (type.equals(Session.class)) { return (T) Mockito.verify(session); } throw new IllegalArgumentException(); }
Example 9
Source File: ServiceResponseDecoderTest.java From Poseidon with Apache License 2.0 | 5 votes |
@Test public void testCollectedHeaders() throws Exception { HttpResponse mockHttpResponse = mock(HttpResponse.class); StatusLine mockStatusLine = mock(StatusLine.class); HttpEntity mockEntity = mock(HttpEntity.class); InputStream stream = mock(InputStream.class); mockStatic(IOUtils.class); collectedHeaders.put("one", new ConcurrentLinkedQueue<>()); Header headerOne = new BasicHeader("one", "1"); Header headerOneAgain = new BasicHeader("one", "3"); Header headerTwo = new BasicHeader("two", "2"); Header[] responseHeaders = new Header[] { headerOne, headerTwo, headerOneAgain }; when(mockStatusLine.getStatusCode()).thenReturn(200); when(mockHttpResponse.getStatusLine()).thenReturn(mockStatusLine); when(mockHttpResponse.getEntity()).thenReturn(mockEntity); when(mockHttpResponse.getAllHeaders()).thenReturn(responseHeaders); when(mockEntity.getContent()).thenReturn(stream); BDDMockito.when(IOUtils.toString(stream)).thenReturn("success"); when(mockJavaType.getRawClass()).thenReturn(responseClass); ServiceResponseDecoder decoder = spy(new ServiceResponseDecoder(mockMapper, mockJavaType, mockErrorType, mockLogger , exceptions, collectedHeaders)); ServiceResponse response = decoder.decode(mockHttpResponse); assertEquals("success", response.getDataList().get(0)); assertEquals(2, response.getHeaders().size()); assertEquals("3", response.getHeaders().get("one")); assertEquals("2", response.getHeaders().get("two")); assertEquals(1, collectedHeaders.size()); assertEquals(2, collectedHeaders.get("one").size()); assertTrue(collectedHeaders.get("one").contains("1")); assertTrue(collectedHeaders.get("one").contains("3")); Mockito.verify(mockLogger, Mockito.never()); }
Example 10
Source File: ServiceResponseDecoderTest.java From Poseidon with Apache License 2.0 | 5 votes |
@Test public void testHeaders() throws Exception { HttpResponse mockHttpResponse = mock(HttpResponse.class); StatusLine mockStatusLine = mock(StatusLine.class); HttpEntity mockEntity = mock(HttpEntity.class); InputStream stream = mock(InputStream.class); mockStatic(IOUtils.class); Header headerOne = new BasicHeader("one", "1"); Header headerTwo = new BasicHeader("two", "2"); Header[] responseHeaders = new Header[] { headerOne, headerTwo }; when(mockStatusLine.getStatusCode()).thenReturn(200); when(mockHttpResponse.getStatusLine()).thenReturn(mockStatusLine); when(mockHttpResponse.getEntity()).thenReturn(mockEntity); when(mockHttpResponse.getAllHeaders()).thenReturn(responseHeaders); when(mockEntity.getContent()).thenReturn(stream); BDDMockito.when(IOUtils.toString(stream)).thenReturn("success"); when(mockJavaType.getRawClass()).thenReturn(responseClass); ServiceResponseDecoder decoder = spy(new ServiceResponseDecoder(mockMapper, mockJavaType, mockErrorType, mockLogger , exceptions, collectedHeaders)); ServiceResponse response = decoder.decode(mockHttpResponse); assertEquals("success", response.getDataList().get(0)); assertEquals(2, response.getHeaders().size()); assertEquals("1", response.getHeaders().get("one")); assertEquals("2", response.getHeaders().get("two")); assertEquals(0, collectedHeaders.size()); Mockito.verify(mockLogger, Mockito.never()); }
Example 11
Source File: NSDictionaryHelperTest.java From gdx-fireapp with Apache License 2.0 | 5 votes |
@Test public void toMap() { // Given NSDictionary nsDictionary = Mockito.mock(NSDictionary.class); Set set = Mockito.spy(new HashSet()); Mockito.when(nsDictionary.keySet()).thenReturn(set); // When Object result = NSDictionaryHelper.toMap(nsDictionary); // Then Assert.assertNotNull(result); Mockito.verify(nsDictionary.keySet(), VerificationModeFactory.times(1)); }
Example 12
Source File: AbstractAPIManagerTestCase.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testConstructor() throws Exception { ServiceReferenceHolderMockCreator holderMockCreator = new ServiceReferenceHolderMockCreator(1); ServiceReferenceHolderMockCreator.initContextService(); holderMockCreator.initRegistryServiceMockCreator(false, new Object()); RegistryAuthorizationManager registryAuthorizationManager = Mockito.mock(RegistryAuthorizationManager.class); Mockito.doThrow(UserStoreException.class).doNothing().when(registryAuthorizationManager) .authorizeRole(Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); PowerMockito.whenNew(RegistryAuthorizationManager.class).withAnyArguments() .thenReturn(registryAuthorizationManager); PowerMockito.mockStatic(RegistryUtils.class); PowerMockito.when(RegistryUtils.getAbsolutePath((RegistryContext) Mockito.any(), Mockito.anyString())) .thenReturn("/test"); try { new AbstractAPIManager(null) { @Override public String getGraphqlSchema(APIIdentifier apiId) throws APIManagementException { return null; } }; Assert.fail("User store exception not thrown for error scenario"); } catch (APIManagementException e) { Assert.assertTrue(e.getMessage().contains("Error while setting the permissions")); } PowerMockito.mockStatic(APIUtil.class); PowerMockito.doNothing().when(APIUtil.class, "loadTenantRegistry", Mockito.anyInt()); PowerMockito.mockStatic(MultitenantUtils.class); PowerMockito.when(MultitenantUtils.getTenantDomain(Mockito.anyString())).thenReturn(SAMPLE_TENANT_DOMAIN_1); String userName = "admin"; Mockito.verify( holderMockCreator.getRegistryServiceMockCreator().getMock().getConfigSystemRegistry(Mockito.anyInt()), Mockito.atLeastOnce()); }
Example 13
Source File: Mocker.java From mocker with Apache License 2.0 | 4 votes |
public T times(Action1<T> verify, int i) { T mock = mock(); verify.call(mock); return Mockito.verify(mock, Mockito.times(i)); }
Example 14
Source File: Mocker.java From mocker with Apache License 2.0 | 4 votes |
public T never(Action1<T> verify) { T mock = mock(); verify.call(mock); return Mockito.verify(mock, Mockito.never()); }
Example 15
Source File: TestCommons.java From rapidoid with Apache License 2.0 | 4 votes |
protected <T> T verify(T mock) { return Mockito.verify(mock); }
Example 16
Source File: WithMockito.java From mockito-java8 with Apache License 2.0 | 4 votes |
/** * Delegates call to {@link Mockito#verify(Object)}. */ default <T> T verify(T mock) { return Mockito.verify(mock, times(1)); }
Example 17
Source File: WithMockito.java From mockito-java8 with Apache License 2.0 | 4 votes |
/** * Delegates call to {@link Mockito#verify(Object, VerificationMode)}. */ default <T> T verify(T mock, VerificationMode mode) { return Mockito.verify(mock, mode); }
Example 18
Source File: WithMockito.java From Patterdale with Apache License 2.0 | 4 votes |
default <T> T verify(T mock) { return Mockito.verify(mock); }
Example 19
Source File: AbstractSinglePlayersTest.java From codenjoy with GNU General Public License v3.0 | 4 votes |
protected EventListener verify(int index) { return Mockito.verify(listener(index)); }
Example 20
Source File: PanacheMock.java From quarkus with Apache License 2.0 | 4 votes |
public static <T> T verify(Class<T> klass) { return Mockito.verify(getMock(klass)); }