@Test public void testPutNewValue() { assertThat(mapCache.put("key", "value")).isNull(); assertThat(mapCache.get("key")).isEqualTo("value"); // ensure key/value is cached assertThat(mapCache.put("key", "new value")).isEqualTo("value"); assertThat(mapCache.get("key")).isEqualTo("new value"); }
public void testToOptionalMany() { try { Stream.of(1, 2, 3, 4, 5, 6).collect(MoreCollectors.toOptional()); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { assertThat(expected.getMessage()).contains("1, 2, 3, 4, 5, ..."); } }
@Test public void addPackageSetsStorage() throws Exception { shadowPackageManager.addPackage("test.package"); PackageInfo packageInfo = packageManager.getPackageInfo("test.package", 0); assertThat(packageInfo.applicationInfo.sourceDir).isNotNull(); assertThat(new File(packageInfo.applicationInfo.sourceDir).exists()).isTrue(); assertThat(packageInfo.applicationInfo.publicSourceDir) .isEqualTo(packageInfo.applicationInfo.sourceDir); }
@Test public void testRemoveEqualKeyWithDifferentReference() { String fooReference1 = new String("foo"); String fooReference2 = new String("foo"); assertThat(fooReference1).isNotSameAs(fooReference2); assertThat(mapCache.put(fooReference1, "bar")).isNull(); assertThat(mapCache.get(fooReference1)).isEqualTo("bar"); // ensure first reference is cached assertThat(mapCache.remove(fooReference2)).isEqualTo("bar"); assertThat(mapCache.get(fooReference1)).isNull(); }
public void testGetClassPathUrls() throws Exception { String oldPathSeparator = PATH_SEPARATOR.value(); String oldClassPath = JAVA_CLASS_PATH.value(); System.setProperty(PATH_SEPARATOR.key(), ":"); System.setProperty( JAVA_CLASS_PATH.key(), Joiner.on(":") .join( "relative/path/to/some.jar", "/absolute/path/to/some.jar", "relative/path/to/class/root", "/absolute/path/to/class/root")); try { ImmutableList<URL> urls = ClassPath.Scanner.parseJavaClassPath(); assertThat(urls.get(0).getProtocol()).isEqualTo("file"); assertThat(urls.get(0).getAuthority()).isNull(); assertThat(urls.get(0).getPath()).endsWith("/relative/path/to/some.jar"); assertThat(urls.get(1)).isEqualTo(new URL("file:///absolute/path/to/some.jar")); assertThat(urls.get(2).getProtocol()).isEqualTo("file"); assertThat(urls.get(2).getAuthority()).isNull(); assertThat(urls.get(2).getPath()).endsWith("/relative/path/to/class/root"); assertThat(urls.get(3)).isEqualTo(new URL("file:///absolute/path/to/class/root")); assertThat(urls).hasSize(4); } finally { System.setProperty(PATH_SEPARATOR.key(), oldPathSeparator); System.setProperty(JAVA_CLASS_PATH.key(), oldClassPath); } }
@Test public void nonResizedRequestsAreTransformedWhenAlwaysTransformIsSet() { Request input = new Request.Builder(IMAGE_URI).build(); Request output = alwaysResizeTransformer.transformRequest(input); assertThat(output).isNotSameAs(input); assertThat(output.hasSize()).isFalse(); String expected = Thumbor.create(HOST).buildImage(IMAGE).toUrl(); assertThat(output.uri.toString()).isEqualTo(expected); }
@Test public void testInheritStyle() { style.inherit(createAncestorStyle()); assertWithMessage("id must not be inherited").that(style.getId()).isNull(); assertThat(style.isUnderline()).isTrue(); assertThat(style.isLinethrough()).isTrue(); assertThat(style.getStyle()).isEqualTo(STYLE_BOLD_ITALIC); assertThat(style.getFontFamily()).isEqualTo(FONT_FAMILY); assertThat(style.getFontColor()).isEqualTo(WHITE); assertWithMessage("do not inherit backgroundColor").that(style.hasBackgroundColor()).isFalse(); }
@Test public void testPlaylistWithClosedCaption() throws IOException { HlsMasterPlaylist playlist = parseMasterPlaylist(PLAYLIST_URI, PLAYLIST_WITH_CC); assertThat(playlist.muxedCaptionFormats).hasSize(1); Format closedCaptionFormat = playlist.muxedCaptionFormats.get(0); assertThat(closedCaptionFormat.sampleMimeType).isEqualTo(MimeTypes.APPLICATION_CEA708); assertThat(closedCaptionFormat.accessibilityChannel).isEqualTo(4); assertThat(closedCaptionFormat.language).isEqualTo("es"); }
@Test public void submitRunnable_shouldRunStuffOnBackgroundThread() throws Exception { Future<String> future = executorService.submit(runnable, "foo"); assertThat(transcript).isEmpty(); assertThat(future.isDone()).isFalse(); ShadowApplication.runBackgroundTasks(); assertThat(transcript).containsExactly("background event ran"); assertThat(future.isDone()).isTrue(); assertThat(future.get()).isEqualTo("foo"); }
@Test public void shouldMakeTextCorrectly() throws Exception { Toast toast = Toast.makeText(context, "short toast", Toast.LENGTH_SHORT); assertThat(toast).isNotNull(); assertThat(toast.getDuration()).isEqualTo(Toast.LENGTH_SHORT); toast.show(); assertThat(ShadowToast.getLatestToast()).isSameAs(toast); assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo("short toast"); assertThat(ShadowToast.showedToast("short toast")).isTrue(); }
@Test public void setDefaultFingerprints() { assertThat(shadowOf(manager).getEnrolledFingerprints()).isEmpty(); shadowOf(manager).setDefaultFingerprints(1); assertThat(manager.getEnrolledFingerprints().get(0).getName().toString()) .isEqualTo("Fingerprint 0"); assertThat(shadowOf(manager).getFingerprintId(0)).isEqualTo(0); assertThat(manager.hasEnrolledFingerprints()).isTrue(); shadowOf(manager).setDefaultFingerprints(0); assertThat(manager.getEnrolledFingerprints()).isEmpty(); assertThat(manager.hasEnrolledFingerprints()).isFalse(); }
assertThat(transpose).isEqualTo(expectedTranspose); assertThat(transpose(transpose)).isSameAs(directedGraph); AbstractNetworkTest.validateNetwork(transpose); assertThat(transpose.edgesConnecting(N1, N2)).isEmpty(); assertThat(transpose.edgeConnecting(N1, N2).isPresent()).isFalse(); assertThat(transpose.edgeConnectingOrNull(N1, N2)).isNull(); assertThat(directedGraph.inDegree(node)).isSameAs(transpose.outDegree(node)); assertThat(directedGraph.outDegree(node)).isSameAs(transpose.inDegree(node)); assertThat(transpose.edgesConnecting(N1, N2)).containsExactly(E21); assertThat(transpose.edgeConnecting(N1, N2).get()).isEqualTo(E21); assertThat(transpose.edgeConnectingOrNull(N1, N2)).isEqualTo(E21); AbstractNetworkTest.validateNetwork(transpose);
@Test public void testSelfLoop() { EndpointPair<String> unordered = EndpointPair.unordered("node", "node"); assertThat(unordered.isOrdered()).isFalse(); assertThat(unordered).containsExactly("node", "node"); assertThat(unordered.nodeU()).isEqualTo("node"); assertThat(unordered.nodeV()).isEqualTo("node"); assertThat(unordered.adjacentNode("node")).isEqualTo("node"); assertThat(unordered.toString()).isEqualTo("[node, node]"); }
@Test public void testHandleNulls() { mapCache.put("foo", "bar"); mapCache.put("non-null key", null); mapCache.put(null, "non-null value"); assertThat(mapCache.get("foo")).isEqualTo("bar"); assertThat(mapCache.get("non-null key")).isNull(); assertThat(mapCache.get(null)).isEqualTo("non-null value"); assertThat(mapCache.containsKey("foo")).isTrue(); assertThat(mapCache.containsKey("bar")).isFalse(); assertThat(mapCache.containsKey("non-null key")).isTrue(); assertThat(mapCache.containsKey(null)).isTrue(); // Test again - in reverse order. assertThat(mapCache.get(null)).isEqualTo("non-null value"); assertThat(mapCache.get("non-null key")).isNull(); assertThat(mapCache.get("foo")).isEqualTo("bar"); } }
assertThat(graphString).contains("isDirected: " + graph.isDirected()); assertThat(graphString).contains("allowsSelfLoops: " + graph.allowsSelfLoops()); assertThat(nodeString).contains(node.toString()); assertThat(node).isNotEqualTo(adjacentNode); assertThat( graph.predecessors(node).contains(adjacentNode) || graph.successors(node).contains(adjacentNode)) .isTrue(); assertThat(graph.successors(predecessor)).contains(node); assertThat(graph.hasEdgeConnecting(predecessor, node)).isTrue(); assertThat(graph.incidentEdges(node)).contains(EndpointPair.of(graph, predecessor, node)); allEndpointPairs.add(EndpointPair.of(graph, node, successor)); assertThat(graph.predecessors(successor)).contains(node); assertThat(graph.hasEdgeConnecting(node, successor)).isTrue(); assertThat(graph.incidentEdges(node)).contains(EndpointPair.of(graph, node, successor));
@Test public void testOrderedEndpointPair() { EndpointPair<String> ordered = EndpointPair.ordered("source", "target"); assertThat(ordered.isOrdered()).isTrue(); assertThat(ordered).containsExactly("source", "target").inOrder(); assertThat(ordered.source()).isEqualTo("source"); assertThat(ordered.target()).isEqualTo("target"); assertThat(ordered.nodeU()).isEqualTo("source"); assertThat(ordered.nodeV()).isEqualTo("target"); assertThat(ordered.adjacentNode("source")).isEqualTo("target"); assertThat(ordered.adjacentNode("target")).isEqualTo("source"); assertThat(ordered.toString()).isEqualTo("<source -> target>"); }
@Test public void shouldSetTextWithIdCorrectly() throws Exception { Toast toast = Toast.makeText(context, "short toast", Toast.LENGTH_SHORT); toast.setText(R.string.hello); toast.show(); assertThat(ShadowToast.getLatestToast()).isSameAs(toast); assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo("Hello"); assertThat(ShadowToast.showedToast("Hello")).isTrue(); }
public void testCheckArgument_nullMessageWithArgs_failure() { try { Preconditions.checkArgument(false, null, "b", "d"); fail("no exception thrown"); } catch (IllegalArgumentException e) { assertThat(e).hasMessageThat().isEqualTo("null [b, d]"); } }
@Test public void testAssignIdForKeyAndGetKeyForId() { final String key1 = "key1"; final String key2 = "key2"; int id1 = index.assignIdForKey(key1); int id2 = index.assignIdForKey(key2); assertThat(index.getKeyForId(id1)).isEqualTo(key1); assertThat(index.getKeyForId(id2)).isEqualTo(key2); assertThat(id1 != id2).isTrue(); assertThat(index.assignIdForKey(key1)).isEqualTo(id1); assertThat(index.assignIdForKey(key2)).isEqualTo(id2); }
@Test public void int64WrapperNull() { Value v = Value.int64(null); assertThat(v.getType()).isEqualTo(Type.int64()); assertThat(v.isNull()).isTrue(); assertThat(v.toString()).isEqualTo(NULL_STRING); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("null value"); v.getInt64(); }