org.mockito.internal.matchers.Any Java Examples

The following examples show how to use org.mockito.internal.matchers.Any. 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: MarketplaceContextFilterTest.java    From development with Apache License 2.0 6 votes vote down vote up
@Test
public void doFilter_givenUrlMidIsValid() throws Exception {
    final String mId = "fdfb4933";
    fakeRequest(mId, null);
    when(mpSvcMock.getMarketplaceById(mId)).thenReturn(new VOMarketplace());

    mpCtxFilter.doFilter(requestMock, responseMock, chainMock);

    verify(sessionMock, times(1)).setAttribute(
            Matchers.eq(Constants.REQ_PARAM_MARKETPLACE_ID),
            Matchers.eq(mId));
    // no MPL portal request, thus no redirect required
    verify(responseMock, never()).sendRedirect(
            Matchers.contains(Marketplace.PUBLIC_CATALOG_SITE));
    // if mId given, do not use fallback via subscription key or cookie
    verify(mpSvcMock, never()).getMarketplaceForSubscription(
            Matchers.anyLong(), Matchers.anyString());
    verify(requestMock, times(1)).getCookies();
    verify(sessionMock, never()).setAttribute(
            Constants.REQ_PARAM_MARKETPLACE_ID, Any.class);

    assertEquals(mId, sessionMid);
}
 
Example #2
Source File: MarketplaceContextFilterTest.java    From development with Apache License 2.0 6 votes vote down vote up
@Test
public void doFilter_noValidMidInGivenUrl_mIdStoredInCookie()
        throws Exception {
    final String cookieId = fakeSetCookieMid(
            Constants.REQ_PARAM_MARKETPLACE_ID, "myMpId");
    fakeUserLogin("myOrgId");
    fakeCreateMarketplace(cookieId);

    mpCtxFilter.doFilter(requestMock, responseMock, chainMock);

    verify(sessionMock, atLeastOnce()).setAttribute(
            Constants.REQ_PARAM_MARKETPLACE_ID, cookieId);

    verify(sessionMock, never()).setAttribute(
            Constants.REQ_PARAM_MARKETPLACE_ID, Any.class);

    assertEquals(cookieId, sessionMid);
}
 
Example #3
Source File: MarketplaceContextFilterTest.java    From development with Apache License 2.0 6 votes vote down vote up
@Test
public void doFilter_MpRedirect() throws Exception {
    when(requestMock.getServletPath()).thenReturn(
            BaseBean.MARKETPLACE_REDIRECT);

    mpCtxFilter.doFilter(requestMock, responseMock, chainMock);

    // MPL portal request, thus no redirect required
    verify(responseMock, times(1)).sendRedirect(
            Matchers.contains(Marketplace.MARKETPLACE_ROOT));
    // if mId given, do not use fallback via subscription key or cookie
    verify(mpSvcMock, never()).getMarketplaceForSubscription(
            Matchers.anyLong(), Matchers.anyString());
    verify(requestMock, times(1)).getCookies();
    verify(sessionMock, never()).setAttribute(
            Constants.REQ_PARAM_MARKETPLACE_ID, Any.class);
}
 
Example #4
Source File: MarketplaceContextFilterTest.java    From development with Apache License 2.0 6 votes vote down vote up
@Test
public void doFilter_noValidMidInGivenUrl_previousmIdStoredInCookieButMpDeletedMeanwhile()
        throws Exception {
    final String cookieId = fakeSetCookieMid(
            Constants.REQ_PARAM_MARKETPLACE_ID, "myMpId");
    fakeUserLogin("myOrgId");
    fakeCreateMarketplace(cookieId);
    when(mpSvcMock.getMarketplaceById(cookieId)).thenThrow(
            new ObjectNotFoundException());
    when(mpSvcMock.getMarketplaceById("myOrgId")).thenThrow(
            new ObjectNotFoundException());

    mpCtxFilter.doFilter(requestMock, responseMock, chainMock);

    verify(sessionMock, never()).setAttribute(
            Constants.REQ_PARAM_MARKETPLACE_ID, cookieId);

    verify(sessionMock, never()).setAttribute(
            Constants.REQ_PARAM_MARKETPLACE_ID, Any.class);

    assertEquals(null, sessionMid);
}
 
Example #5
Source File: CompositeClientTransactionTests.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
@Before
public void before() {
    GattUtils utilsMock = mock(GattUtils.class);
    LowEnergyAclListener lowEnergyAclListenerMock = mock(LowEnergyAclListener.class);
    BluetoothAdapter adapterMock = mock(BluetoothAdapter.class);
    BluetoothRadioStatusListener bluetoothRadioStatusListenerMock = mock(BluetoothRadioStatusListener.class);
    BitGattDependencyProvider dependencyProviderMock = mock(BitGattDependencyProvider.class);
    Context mockContext = mock(Context.class);

    when(mockContext.getSystemService(Any.class)).thenReturn(null);
    when(mockContext.getApplicationContext()).thenReturn(mockContext);
    doReturn(bluetoothRadioStatusListenerMock).when(dependencyProviderMock).getNewBluetoothRadioStatusListener(any(), eq(false));
    doReturn(utilsMock).when(dependencyProviderMock).getNewGattUtils();
    doReturn(lowEnergyAclListenerMock).when(dependencyProviderMock).getNewLowEnergyAclListener();
    doReturn(adapterMock).when(utilsMock).getBluetoothAdapter(mockContext);
    doReturn(true).when(adapterMock).isEnabled();

    Looper mockMainThreadLooper = mock(Looper.class);
    Thread mockMainThread = mock(Thread.class);
    when(mockMainThread.getName()).thenReturn("Irvin's mock thread");
    when(mockMainThreadLooper.getThread()).thenReturn(mockMainThread);
    Context ctx = mock(Context.class);
    when(ctx.getApplicationContext()).thenReturn(ctx);
    when(ctx.getMainLooper()).thenReturn(mockMainThreadLooper);


    Handler mockHandler = mock(Handler.class);
    doAnswer(handlerPostAnswer).when(mockHandler).post(any(Runnable.class));
    doAnswer(handlerPostAnswer).when(mockHandler).postDelayed(any(Runnable.class), anyLong());
    when(mockHandler.getLooper()).thenReturn(mockMainThreadLooper);
    conn = spy(new GattConnection(device, ctx.getMainLooper()));
    conn.setMockMode(true);
    when(conn.getMainHandler()).thenReturn(mockHandler);
    conn.setState(GattState.IDLE);
    FitbitGatt.getInstance().setAsyncOperationThreadWatchdog(mock(LooperWatchdog.class));
    FitbitGatt.getInstance().registerGattEventListener(new NoOpGattCallback());
    FitbitGatt.getInstance().setDependencyProvider(dependencyProviderMock);
    FitbitGatt.getInstance().startGattClient(ctx);
    FitbitGatt.getInstance().putConnectionIntoDevices(device, conn);
}
 
Example #6
Source File: MarketplaceContextFilterTest.java    From development with Apache License 2.0 5 votes vote down vote up
@Test
public void doFilter_noMidInGivenUrl() throws Exception {
    mpCtxFilter.doFilter(requestMock, responseMock, chainMock);

    verify(mpSvcMock, never()).getMarketplaceById(any(String.class));
    verify(sessionMock, never()).setAttribute(
            Constants.REQ_PARAM_MARKETPLACE_ID, Any.class);
}
 
Example #7
Source File: MarketplaceContextFilterTest.java    From development with Apache License 2.0 5 votes vote down vote up
@Test
public void doFilter_noValidMidInGivenUrl_noSessionMid_MPLcontext()
        throws Exception {
    fakeUserLogin("myOrgId");
    fakeRequest(null, "/marketplace/index.jsf");

    mpCtxFilter.doFilter(requestMock, responseMock, chainMock);

    verify(sessionMock, never()).setAttribute(
            Constants.REQ_PARAM_MARKETPLACE_ID, Any.class);
}
 
Example #8
Source File: MocksSerializationTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void shouldSerializeObjectMock() throws Exception {
    // given
    Any mock = mock(Any.class);

    // when
    ByteArrayOutputStream serialized = serializeMock(mock);

    // then
    deserializeMock(serialized, Any.class);
}
 
Example #9
Source File: MocksSerializationTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void shouldSerializeRealPartialMock() throws Exception {
    // given
    Any mock = mock(Any.class, withSettings().serializable());
    when(mock.matches(anyObject())).thenCallRealMethod();

    // when
    ByteArrayOutputStream serialized = serializeMock(mock);

    // then
    Any readObject = deserializeMock(serialized, Any.class);
    readObject.matches("");
}
 
Example #10
Source File: MocksSerializationForAnnotationTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void should_serialize_object_mock() throws Exception {
    // when
    ByteArrayOutputStream serialized = serializeMock(any);

    // then
    deserializeMock(serialized, Any.class);
}
 
Example #11
Source File: MocksSerializationForAnnotationTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void should_serialize_real_partial_mock() throws Exception {
    // given
    when(anyMock.matches(anyObject())).thenCallRealMethod();

    // when
    ByteArrayOutputStream serialized = serializeMock(anyMock);

    // then
    Any readObject = deserializeMock(serialized, Any.class);
    readObject.matches("");
}
 
Example #12
Source File: MocksSerializationTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void should_serialize_object_mock() throws Exception {
    // given
    Any mock = mock(Any.class);

    // when
    ByteArrayOutputStream serialized = serializeMock(mock);

    // then
    deserializeMock(serialized, Any.class);
}
 
Example #13
Source File: MocksSerializationTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void should_serialize_real_partial_mock() throws Exception {
    // given
    Any mock = mock(Any.class, withSettings().serializable());
    when(mock.matches(anyObject())).thenCallRealMethod();

    // when
    ByteArrayOutputStream serialized = serializeMock(mock);

    // then
    Any readObject = deserializeMock(serialized, Any.class);
    readObject.matches("");
}