Refine search
void verifyCallCount(int expected) { assertThat(applyCount).isEqualTo(expected); } }
@Test public void testRead_readWithZeroes_doesNotThrow() throws IOException { ByteArrayInputStream inner = new ByteArrayInputStream(new byte[] {0, 0, 0}); InputStream is = ContentLengthInputStream.obtain(inner, 3); assertThat(is.read()).isEqualTo(0); assertThat(is.read()).isEqualTo(0); assertThat(is.read()).isEqualTo(0); assertThat(is.read()).isEqualTo(-1); }
@Test public void testRead_readWithHighValues_doesNotThrow() throws IOException { ByteArrayInputStream inner = new ByteArrayInputStream(new byte[] {(byte) 0xF0, (byte) 0xA0, (byte) 0xFF}); InputStream is = ContentLengthInputStream.obtain(inner, 3); assertThat(is.read()).isEqualTo(0xF0); assertThat(is.read()).isEqualTo(0xA0); assertThat(is.read()).isEqualTo(0xFF); assertThat(is.read()).isEqualTo(-1); } }
void verifyCallCount(int expected) { assertThat(count).isEqualTo(expected); } }
@Test public void testAvailable_withRead_returnsContentLengthOffsetByRead() throws IOException { int contentLength = 999; InputStream is = ContentLengthInputStream.obtain(wrapped, String.valueOf(contentLength)); when(wrapped.read()).thenReturn(1); assertThat(is.read()).isEqualTo(1); assertThat(is.available()).isEqualTo(contentLength - 1); }
@GwtIncompatible // Reader private static void testStreamingDecodes(BaseEncoding encoding, String encoded, String decoded) throws IOException { byte[] bytes = decoded.getBytes(UTF_8); InputStream decodingStream = encoding.decodingStream(new StringReader(encoded)); for (int i = 0; i < bytes.length; i++) { assertThat(decodingStream.read()).isEqualTo(bytes[i] & 0xFF); } assertThat(decodingStream.read()).isEqualTo(-1); decodingStream.close(); }
@Test public void testAvailable_handlesReadValueOfZero() throws IOException { int contentLength = 999; InputStream is = ContentLengthInputStream.obtain(wrapped, String.valueOf(contentLength)); when(wrapped.read()).thenReturn(0); assertThat(is.read()).isEqualTo(0); assertThat(is.available()).isEqualTo(contentLength - 1); }
public void testIndexOf_specialValues() { ImmutableDoubleArray iia = ImmutableDoubleArray.of(-0.0, 0.0, Double.MAX_VALUE, Double.POSITIVE_INFINITY, Double.NaN); assertThat(iia.indexOf(-0.0)).isEqualTo(0); assertThat(iia.indexOf(0.0)).isEqualTo(1); assertThat(iia.indexOf(Double.MAX_VALUE)).isEqualTo(2); assertThat(iia.indexOf(Double.POSITIVE_INFINITY)).isEqualTo(3); assertThat(iia.indexOf(Double.NaN)).isEqualTo(4); }
@Test public void testAvailable_withReadBytes_returnsContentLengthOffsetByNumberOfBytes() throws IOException { int contentLength = 678; InputStream is = ContentLengthInputStream.obtain(wrapped, String.valueOf(contentLength)); int read = 100; when(wrapped.read(any(byte[].class), anyInt(), anyInt())).thenReturn(read); assertThat(is.read(new byte[500], 0, 0)).isEqualTo(read); assertThat(is.available()).isEqualTo(contentLength - read); }
public void testOnlyElementSingleton() { assertThat(Stream.of(1).collect(MoreCollectors.onlyElement())).isEqualTo(1); }
@Test public void inDegree_oneEdge() { addEdge(N1, N2, E12); assertThat(network.inDegree(N2)).isEqualTo(1); // Edge direction handled correctly assertThat(network.inDegree(N1)).isEqualTo(0); }
@GwtIncompatible // digs into internals of the non-GWT implementation public void testMaximumSize_largerThanInt() { CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder().initialCapacity(512).maximumSize(Long.MAX_VALUE); LocalCache<?, ?> cache = ((LocalCache.LocalManualCache<?, ?>) builder.build()).localCache; assertThat(cache.segments.length * cache.segments[0].table.length()).isEqualTo(512); }
@Test public void outDegree_oneEdge() { putEdge(N1, N2); assertThat(graph.outDegree(N1)).isEqualTo(1); assertThat(graph.outDegree(N2)).isEqualTo(1); }
public void testForEachPair_parallel() { Stream<String> streamA = IntStream.range(0, 100000).mapToObj(String::valueOf).parallel(); Stream<Integer> streamB = IntStream.range(0, 100000).mapToObj(i -> i).parallel(); AtomicInteger count = new AtomicInteger(0); Streams.forEachPair( streamA, streamB, (a, b) -> { count.incrementAndGet(); Truth.assertThat(a.equals(String.valueOf(b))).isTrue(); }); Truth.assertThat(count.get()).isEqualTo(100000); // of course, this test doesn't prove that anything actually happened in parallel... }
@Test public void inDegree_oneEdge() { addEdge(N1, N2, E12); assertThat(network.inDegree(N2)).isEqualTo(1); assertThat(network.inDegree(N1)).isEqualTo(1); }
public void testZip_closeIsPropagated() { AtomicInteger lettersCloseCount = new AtomicInteger(); Stream<String> letters = Stream.of("a", "b", "c").onClose(lettersCloseCount::incrementAndGet); AtomicInteger numbersCloseCount = new AtomicInteger(); Stream<Integer> numbers = Stream.of(1, 2, 3).onClose(numbersCloseCount::incrementAndGet); Stream<String> zipped = Streams.zip(letters, numbers, (a, b) -> a + ":" + b); zipped.close(); Truth.assertThat(lettersCloseCount.get()).isEqualTo(1); Truth.assertThat(numbersCloseCount.get()).isEqualTo(1); }
@Test public void outDegree_oneEdge() { addEdge(N1, N2, E12); assertThat(network.outDegree(N1)).isEqualTo(1); // Edge direction handled correctly assertThat(network.outDegree(N2)).isEqualTo(0); }
public void testLastIndexOf() { ImmutableLongArray iia = ImmutableLongArray.of(1, 1, 2, 3, 5, 8); assertThat(iia.lastIndexOf(1)).isEqualTo(1); assertThat(iia.lastIndexOf(8)).isEqualTo(5); assertThat(iia.lastIndexOf(4)).isEqualTo(-1); assertThat(ImmutableLongArray.of(13).lastIndexOf(13)).isEqualTo(0); assertThat(ImmutableLongArray.of().lastIndexOf(21)).isEqualTo(-1); assertThat(iia.subArray(1, 5).lastIndexOf(1)).isEqualTo(0); }
@Test public void outDegree_oneEdge() { addEdge(N1, N2, E12); assertThat(network.outDegree(N1)).isEqualTo(1); assertThat(network.outDegree(N2)).isEqualTo(1); }
public void testGet_good() { ImmutableIntArray iia = ImmutableIntArray.of(0, 1, 3); assertThat(iia.get(0)).isEqualTo(0); assertThat(iia.get(2)).isEqualTo(3); assertThat(iia.subArray(1, 3).get(1)).isEqualTo(3); }