@Test public void testSyncEnabledCached() throws IOException { HackerNewsItem hnItem = mock(HackerNewsItem.class); Call<HackerNewsItem> call = mock(Call.class); when(call.execute()).thenReturn(Response.success(hnItem)); when(TestRestServiceFactory.hnRestService.cachedItem(any())).thenReturn(call); syncScheduler.scheduleSync(service, "1"); adapter.onPerformSync(mock(Account.class), getLastSyncExtras(), null, null, null); // cache hit, should not try network or defer verify(TestRestServiceFactory.hnRestService).cachedItem(any()); verify(TestRestServiceFactory.hnRestService, never()).networkItem(any()); assertThat(syncPreferences.getAll()).isEmpty(); }
@Test public void testSyncEnabledWifi() throws IOException { Call<HackerNewsItem> call = mock(Call.class); when(call.execute()).thenThrow(IOException.class); when(TestRestServiceFactory.hnRestService.cachedItem(any())).thenReturn(call); when(TestRestServiceFactory.hnRestService.networkItem(any())).thenReturn(call); syncScheduler.scheduleSync(service, "1"); adapter.onPerformSync(mock(Account.class), getLastSyncExtras(), null, null, null); // should try cache before network verify(TestRestServiceFactory.hnRestService).cachedItem(any()); verify(TestRestServiceFactory.hnRestService).networkItem(any()); assertThat(syncPreferences.getAll()).isEmpty(); // on network response should try children verify(call).enqueue(callbackCapture.capture()); HackerNewsItem item = mock(HackerNewsItem.class); when(item.getKids()).thenReturn(new long[]{2L, 3L}); callbackCapture.getValue().onResponse(null, Response.success(item)); verify(TestRestServiceFactory.hnRestService, times(3)).cachedItem(any()); }
@Test public void testSyncEnabledAnyConnection() throws IOException { Call<HackerNewsItem> call = mock(Call.class); when(call.execute()).thenThrow(IOException.class); when(TestRestServiceFactory.hnRestService.cachedItem(any())).thenReturn(call); when(TestRestServiceFactory.hnRestService.networkItem(any())).thenReturn(call); PreferenceManager.getDefaultSharedPreferences(service) .edit() .putString(service.getString(R.string.pref_offline_data), service.getString(R.string.offline_data_default)) .apply(); setNetworkType(ConnectivityManager.TYPE_MOBILE); syncScheduler.scheduleSync(service, "1"); adapter.onPerformSync(mock(Account.class), getLastSyncExtras(), null, null, null); // should try cache, then network verify(TestRestServiceFactory.hnRestService).cachedItem(any()); verify(TestRestServiceFactory.hnRestService).networkItem(any()); assertThat(syncPreferences.getAll()).isEmpty(); }
@Test public void getAll() { expect(cache.getAll(asSet(1))).isEmpty(); changesOf(0, 1, 0, 0); cache.put(1, "a"); cache.put(2, "b"); changesOf(0, 0, 2, 0); expect(cache.getAll(asSet(1, 2, 3))).containsKeys(1, 2); changesOf(2, 1, 0, 0); }
@Test(groups = "short") public void should_fail_if_host_is_not_connected() { // given a statement with host explicitly set that for which we have no active pool. Host host4 = TestUtils.findHost(cluster, 4); Statement statement = new SimpleStatement("select * system.local").setHost(host4); try { // when statement is executed session.execute(statement); fail("Query should have failed"); } catch (NoHostAvailableException e) { // then the request should fail with a NHAE and no host was tried. assertThat(e.getErrors()).isEmpty(); } finally { verifyNoLbpInteractions(); } } }
assertThat(e.getFailuresMap()).hasSize(1).containsValue(0); } else { assertThat(e.getFailuresMap()).isEmpty();
assertThat(e.getFailuresMap()).hasSize(1).containsValue(1); } else { assertThat(e.getFailuresMap()).isEmpty();
assertThat(function.getSimpleName()).isEqualTo("pi"); assertThat(function.getReturnType()).isEqualTo(DataType.cdouble()); assertThat(function.getArguments()).isEmpty(); assertThat(function.getLanguage()).isEqualTo("java"); assertThat(function.getBody()).isEqualTo("return Math.PI;");
assertThat(snapshot.getAllStats()).isEmpty(); LatencyAwarePolicy.Snapshot.Stats stats = snapshot.getStats(retrieveSingleHost(cluster)); assertThat(stats).isNull();
assertThat(table.getOptions().getExtensions()).isEmpty(); // default assertThat(table.getOptions().getMemtableFlushPeriodInMs()).isEqualTo(1000); assertThat(table.asCQLQuery()) assertThat(table.getOptions().getExtensions()).isEmpty(); // default assertThat(table.getOptions().getMemtableFlushPeriodInMs()).isEqualTo(1000); assertThat(table.asCQLQuery()) assertThat(table.getOptions().getMaxIndexInterval()).isEqualTo(2048); assertThat(table.getOptions().getExtensions()).isEmpty(); assertThat(table.getOptions().getMemtableFlushPeriodInMs()).isEqualTo(1000); assertThat(table.asCQLQuery()) assertThat(table.getOptions().getMaxIndexInterval()).isNull(); assertThat(table.getOptions().getExtensions()).isEmpty(); assertThat(table.getOptions().getMemtableFlushPeriodInMs()).isEqualTo(1000); assertThat(table.asCQLQuery()) assertThat(table.getOptions().getMaxIndexInterval()).isNull(); assertThat(table.getOptions().getExtensions()).isEmpty(); assertThat(table.asCQLQuery()) .contains("read_repair_chance = 0.5")
@Test public void nullableConcurrentHashMapPutAllIgnoresNulls() throws Exception { Map<String, String> values = new LinkedHashMap<>(); values.put(null, null); values.put("foo", null); values.put(null, "bar"); Map<String, String> map = new Utils.NullableConcurrentHashMap<>(); map.putAll(values); assertThat(map).isEmpty(); }
@Test public void nullableConcurrentHashMapPutIgnoresNulls() throws Exception { Map<String, String> map = new Utils.NullableConcurrentHashMap<>(); map.put(null, null); map.put("foo", null); map.put(null, "bar"); assertThat(map).isEmpty(); }
@Test public void emptyMap() throws Exception { assertThat(valueMap).hasSize(0).isEmpty(); }
@Test public void toStringMap() { assertThat(valueMap.toStringMap()).isEmpty(); valueMap.put("foo", "bar"); assertThat(valueMap.toStringMap()) // .isEqualTo(new ImmutableMap.Builder<String, Object>().put("foo", "bar").build()); }
@Test public void canParseToEmptyMap() throws Exception { GenericType<Map<String, String>> type = new GenericType<Map<String, String>>() {}; assertThat(parser.parse("null", type)) .isInstanceOf(Map.class) .isEmpty(); }
@Test public void createEmptySnapshot() throws IOException { StatsSnapshot snapshot = stats.createSnapshot(); assertThat(snapshot.timestamp).isNotZero(); assertThat(snapshot.flushCount).isZero(); assertThat(snapshot.flushEventCount).isZero(); assertThat(snapshot.integrationOperationCount).isZero(); assertThat(snapshot.integrationOperationDuration).isZero(); assertThat(snapshot.integrationOperationAverageDuration).isZero(); assertThat(snapshot.integrationOperationDurationByIntegration).isEmpty(); } }
public void testNotPresentWhenDeleting() throws Exception { for (String regionId : regions) { DeleteStaticLargeObjectResponse resp = getApi().getStaticLargeObjectApi(regionId, defaultContainerName).delete(UUID.randomUUID().toString()); assertThat(resp.status()).isEqualTo("200 OK"); assertThat(resp.deleted()).isZero(); assertThat(resp.notFound()).isEqualTo(1); assertThat(resp.errors()).isEmpty(); } }
@Test public void testExplodeTestMethodsUseDataProviderShouldReturnMultipleDataProviderFrameworkMethodIfDataConverterReturnsMultipleRows() throws Throwable { // Given: List<Object[]> dataConverterResult = listOfArrays(new Object[] { 11, "22", 33L }, new Object[] { 44, "55", 66L }, new Object[] { 77, "88", 99L }); doReturn(dataConverterResult).when(dataConverter).convert(any(), any(Boolean.class), any(Class[].class), any(DataProvider.class)); doReturn(dataProvider).when(dataProviderMethod).getAnnotation(DataProvider.class); doReturn("%c").when(dataProvider).format(); doReturn(false).when(dataProvider).cache(); // When: List<FrameworkMethod> result = underTest.explodeTestMethod(testMethod, dataProviderMethod); // Then: assertThat(TestGenerator.dataProviderDataCache).isEmpty(); assertDataProviderFrameworkMethods(result, dataConverterResult, "%c"); verify(dataProviderMethod).invokeExplosively(null); }
protected void assertDelete(String regionId, String containerName, String name) { DeleteStaticLargeObjectResponse resp = getApi().getStaticLargeObjectApi(regionId, containerName).delete(name); assertThat(resp.status()).isEqualTo("200 OK"); assertThat(resp.deleted()).isEqualTo(3); assertThat(resp.notFound()).isZero(); assertThat(resp.errors()).isEmpty(); assertEquals(getApi().getContainerApi(regionId).get(containerName).getObjectCount(), Long.valueOf(0)); }
@Test(groups = "short") public void should_fail_if_host_is_not_connected() { // given a statement with host explicitly set that for which we have no active pool. Host host4 = TestUtils.findHost(cluster, 4); Statement statement = new SimpleStatement("select * system.local").setHost(host4); try { // when statement is executed session.execute(statement); fail("Query should have failed"); } catch (NoHostAvailableException e) { // then the request should fail with a NHAE and no host was tried. assertThat(e.getErrors()).isEmpty(); } finally { verifyNoLbpInteractions(); } } }