APISonar


org.mockito.Mockito.mock

> org > mockito > Mockito > mock
org APIs mockito APIs Mockito APIs mock APIs

Example 1
private InetAddress mockAddr(String reverseTo) {
    InetAddress mock = Mockito.mock(InetAddress.class);
    Mockito.doReturn(reverseTo).when(mock).getCanonicalHostName();
    return mock;
  }
Example 2
public void shouldReplaceObjectMethods() {
        Object mock = Mockito.mock(ObjectMethodsOverridden.class);
        Object otherMock = Mockito.mock(ObjectMethodsOverridden.class);

        assertThat(mock).isEqualTo(mock);
        assertThat(mock).isNotEqualTo(otherMock);
        assertThat(mock.hashCode()).isNotEqualTo(otherMock.hashCode());

        assertThat(mock.toString()).contains("Mock for ObjectMethodsOverridden");
    }
Example 3
public void mockBeanUtilsObject() {

    new MockUp<BeanUtils>() {
      @Mock
      ApplicationContext getContext() {
        return Mockito.mock(ApplicationContext.class);
      }

      @SuppressWarnings("unchecked")
      @Mock
      <T> T getBean(String name) {
        return (T) new Object();
      }
    };
  }
Example 4
public void testAddRemove()  throws Exception {
        RxPresenter presenter = new RxPresenter();
        Subscription mock = Mockito.mock(Subscription.class);
        when(mock.isUnsubscribed()).thenReturn(false);
        presenter.add(mock);
        presenter.remove(mock);
        verify(mock, atLeastOnce()).isUnsubscribed();
        verify(mock, times(1)).unsubscribe();
        presenter.onDestroy();
        verifyNoMoreInteractions(mock);
    }
Example 5
public void should_get_mock_settings() {
        List<?> mock = Mockito.mock(List.class);
        assertNotNull(MockUtil.getMockSettings(mock));
    }
Example 6
public void testMockingMockito() throws Exception {
    RateLimiter mock = Mockito.mock(RateLimiter.class);
    doTestMocking(mock);
  }
Example 7
public void should_throw_expected_exception() {
        final DoThrowTMockClass mock = Mockito.mock(DoThrowTMockClass.class);
        doThrow(RuntimeException.class).when(mock).doSomething();
        mock.doSomething();
    }
Example 8
public void heartbeatCallsPeriodicHeartbeat() throws Exception {
    BlockWorkerClient mock = Mockito.mock(BlockWorkerClient.class);
    BlockWorkerClientHeartbeatExecutor heartbeatExecutor =
        new BlockWorkerClientHeartbeatExecutor(mock);

    heartbeatExecutor.heartbeat();
    heartbeatExecutor.close();

    Mockito.verify(mock).periodicHeartbeat();
  }
Example 9
public ClientStatsContext createStatsContext() {
        ClientStatsContext mock = Mockito.mock(ClientStatsContext.class);
        doReturn(mock).when(mock).fetchAndResetBaseline();
        doReturn(Mockito.mock(ClientStats.class)).when(mock).getStats();
        return mock;
    }
Example 10
private void mockGenerateCRLs() {
    new MockUp<CertificateFactory>() {
      @SuppressWarnings("unchecked")
      @Mock
      public final Collection<? extends CRL> generateCRLs(InputStream inStream) throws CRLException {
        return Mockito.mock(Collection.class);
      }
    };
  }
Example 11
public void testAddView() {
        AnyKeyboardView mock = Mockito.mock(AnyKeyboardView.class);
        mUnderTest.addView(mock);

        Assert.assertEquals(3, mUnderTest.getChildCount());
        Assert.assertSame(mock, mUnderTest.getChildAt(2));

        Mockito.verify(mock, Mockito.never()).setKeyboardTheme(any());
        Mockito.verify(mock, Mockito.never()).setThemeOverlay(any());
    }
Example 12
public void testPoll() throws Exception {
        holderRule.pollNow();

        @SuppressWarnings("unchecked")
        final PooledConnection<String, String> mock = Mockito.mock(PooledConnection.class);
        Mockito.when(mock.isUsable()).thenReturn(true);

        PooledConnection<String, String> added = holderRule.addAConnection();

        holderRule.pollNow(added);

        holderRule.pollNow(); // Poll removes the item.
    }
Example 13
private <T> MockData<T> createMethodInvocationControl(Class<T> type, Method[] methods, Object delegator, MockSettings mockSettings) {
        final T mock = Mockito.mock(type, mockSettings != null ? mockSettings : Mockito.withSettings());
    
        cacheMockClass(mock.getClass());
        
        return new MockData<T>(new MockitoMethodInvocationControl(delegator, mock, methods), mock);
    }
Example 14
private static QJournalProtocol mockProxy(WrapEveryCall<Object> wrapper)
      throws IOException {
    QJournalProtocol mock = Mockito.mock(QJournalProtocol.class,
        Mockito.withSettings()
          .defaultAnswer(wrapper)
          .extraInterfaces(Closeable.class));
    return mock;
  }
Example 15
private FilterConfig mockConfig(String username) {
    FilterConfig mock = Mockito.mock(FilterConfig.class);
    Mockito.doReturn(username).when(mock).getInitParameter(
            ServerConfigurationKeys.HBASE_HTTP_STATIC_USER);
    return mock;
  }
Example 16
public void should_mock_final_class_with_using_mockito_inline_mock_creator() {
        
        assumeTrue("Test make seances only for Mockito 2", MockitoVersion.isMockito2());
        
        FinalClass mock = Mockito.mock(FinalClass.class);
        
        String value = "Why me?";
        
        when(mock.ask()).thenReturn(value);
        
        assertThat(mock.ask())
            .as("Mock for final class works")
            .isEqualTo(value);
    }
Example 17
public void read_when_null() throws SQLException {

    DataReader mock = Mockito.mock(DataReader.class);
    Mockito.when(mock.getArray()).thenReturn(null);

    ScalarType<?> scalarType = ScalarTypeArrayList.factory().typeFor(Long.class);
    scalarType.read(mock);
  }
Example 18
private BluetoothLeDevice createDevice(final String mac, long rssiTime, int rssi) {
        final BluetoothLeDevice mock = Mockito.mock(BluetoothLeDevice.class);

        Mockito.when(mock.getAddress()).thenReturn(mac);
        Mockito.when(mock.getTimestamp()).thenReturn(rssiTime);
        Mockito.when(mock.getRssi()).thenReturn(rssi);

        return mock;
    }
Example 19
public void createFromMockClass() throws Exception {
    RemoteBlockWriter mock = Mockito.mock(RemoteBlockWriter.class);
    Configuration.set(PropertyKey.USER_BLOCK_REMOTE_WRITER_CLASS, mock.getClass().getName());
    Assert.assertTrue(RemoteBlockWriter.Factory.create().getClass().equals(mock.getClass()));
  }
Example 20
public void getServiceType() throws Exception {
        DataSourceMonitor mock = Mockito.mock(DataSourceMonitor.class);
        when(mock.getServiceType()).thenReturn(null);

        DataSourceMonitorWrapper dataSourceMonitorWrapper = new DataSourceMonitorWrapper(1, mock);
        Assert.assertEquals(ServiceType.UNKNOWN, dataSourceMonitorWrapper.getServiceType());
    }
Example 21
private ViewController notRenderedComponent() {
        ViewController mock = Mockito.mock(ViewController.class);
        when(mock.isRendered()).then(__ -> false);
        return mock;
    }
Example 22
public void shouldReturnEmptyCollections() {
        CollectionsServer mock = Mockito.mock(CollectionsServer.class);

        assertTrue(mock.list().isEmpty());
        assertTrue(mock.linkedList().isEmpty());
        assertTrue(mock.map().isEmpty());
        assertTrue(mock.hashSet().isEmpty());
    }
Example 23
public void mockEntityBean() {

    final DOrg mock = Mockito.mock(DOrg.class);
    mock.setName("junk");
    mock.save();

    final PersistentFile mock1 = Mockito.mock(PersistentFile.class);
    mock1.setName("foo");
  }
Example 24
public void findWithRawSelenium() {
        WebElement mock = Mockito.mock(WebElement.class);

        FluentWebElement el = search.el(mock);

        assertThat(el.getElement()).isSameAs(mock);
    }
Example 25
public void addJar() {
        // Mock resource loader
        final DataSourceResourceLoader resourceLoader = Mockito.mock(DataSourceResourceLoader.class);
        Mockito.when(resourceLoader.addJar(Mockito.anyString())).thenReturn(false, true);

        // Test adding jars
        final MockDataSetOptionsAccess mock = new MockDataSetOptionsAccess(resourceLoader);

        mock.addJar("file1.jar");
        mock.addJar("file2.jar");
        Assert.assertEquals(1, mock.getOptions().getJars().size());
        Assert.assertEquals("file2.jar", mock.getOptions().getJars().get(0));
    }