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 testExecSQL() throws Exception { database.execSQL("INSERT INTO table_name (id, name) VALUES(1234, 'Chuck');"); Cursor cursor = database.rawQuery("SELECT COUNT(*) FROM table_name", null); assertThat(cursor).isNotNull(); assertThat(cursor.moveToNext()).isTrue(); assertThat(cursor.getInt(0)).isEqualTo(1); cursor = database.rawQuery("SELECT * FROM table_name", null); assertThat(cursor).isNotNull(); assertThat(cursor.moveToNext()).isTrue(); assertThat(cursor.getInt(cursor.getColumnIndex("id"))).isEqualTo(1234); assertThat(cursor.getString(cursor.getColumnIndex("name"))).isEqualTo("Chuck"); }
public void testOnlyElementNull() { assertThat(Stream.of((Object) null).collect(MoreCollectors.onlyElement())).isNull(); }
@Test public void immutableValueGraph() { MutableValueGraph<String, Integer> mutableValueGraph = ValueGraphBuilder.directed().build(); mutableValueGraph.addNode("A"); ImmutableValueGraph<String, Integer> immutableValueGraph = ImmutableValueGraph.copyOf(mutableValueGraph); assertThat(immutableValueGraph.asGraph()).isInstanceOf(ImmutableGraph.class); assertThat(immutableValueGraph).isNotInstanceOf(MutableValueGraph.class); assertThat(immutableValueGraph).isEqualTo(mutableValueGraph); mutableValueGraph.addNode("B"); assertThat(immutableValueGraph).isNotEqualTo(mutableValueGraph); }
public void testCreate() { Subscriber s1 = Subscriber.create(bus, this, getTestSubscriberMethod("recordingMethod")); assertThat(s1).isInstanceOf(Subscriber.SynchronizedSubscriber.class); // a thread-safe method should not create a synchronized subscriber Subscriber s2 = Subscriber.create(bus, this, getTestSubscriberMethod("threadSafeMethod")); assertThat(s2).isNotInstanceOf(Subscriber.SynchronizedSubscriber.class); }
@Test public void createWithNoPlaceholderAnimation() { PicassoDrawable pd = new PicassoDrawable(context, bitmap, null, DISK, false, false); assertThat(pd.getBitmap()).isSameAs(bitmap); assertThat(pd.placeholder).isNull(); assertThat(pd.animating).isTrue(); }
@Test public void edgeOrder_default() { MutableNetwork<Integer, String> network = NetworkBuilder.directed().build(); addEdges(network); assertThat(network.edgeOrder()).isEqualTo(ElementOrder.insertion()); assertThat(network.edges()).containsExactly("i", "e", "p").inOrder(); assertThat(network.nodeOrder()).isEqualTo(ElementOrder.insertion()); // default }
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);
public void testBuilderGenerics_SelfComparable() { // testing simple creation ImmutableSortedSet.Builder<SelfComparableExample> natural = ImmutableSortedSet.naturalOrder(); assertThat(natural).isNotNull(); ImmutableSortedSet.Builder<SelfComparableExample> reverse = ImmutableSortedSet.reverseOrder(); assertThat(reverse).isNotNull(); }
@Test public void float64Wrapper() { Value v = Value.float64(Double.valueOf(1.23)); assertThat(v.getType()).isEqualTo(Type.float64()); assertThat(v.isNull()).isFalse(); assertThat(v.getFloat64()).isWithin(0.0001).of(1.23); assertThat(v.toString()).isEqualTo("1.23"); }
private static void assertAction(DownloadAction action, String type, int version, byte[] data) { assertThat(action).isInstanceOf(FakeDownloadAction.class); assertThat(action.type).isEqualTo(type); assertThat(((FakeDownloadAction) action).version).isEqualTo(version); assertThat(((FakeDownloadAction) action).data).isEqualTo(data); }
@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(); }
@Test public void load_withShapeDrawableResourceId_asBitmap_withValidSize_returnsNonNullBitmap() throws ExecutionException, InterruptedException { Bitmap bitmap = Glide.with(context) .asBitmap() .load(ResourceIds.drawable.shape_drawable) .submit(100, 200) .get(); assertThat(bitmap).isNotNull(); assertThat(bitmap.getWidth()).isEqualTo(100); assertThat(bitmap.getHeight()).isEqualTo(200); }
@Test public void string() { Value v = Value.string("abc"); assertThat(v.getType()).isEqualTo(Type.string()); assertThat(v.isNull()).isFalse(); assertThat(v.getString()).isEqualTo("abc"); }
@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(); }
@Test public void stringNull() { Value v = Value.string(null); assertThat(v.getType()).isEqualTo(Type.string()); assertThat(v.isNull()).isTrue(); assertThat(v.toString()).isEqualTo(NULL_STRING); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("null value"); v.getString(); }
@Test public void bytesNull() { Value v = Value.bytes(null); assertThat(v.getType()).isEqualTo(Type.bytes()); assertThat(v.isNull()).isTrue(); assertThat(v.toString()).isEqualTo(NULL_STRING); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("null value"); v.getBytes(); }
@Test public void dateNull() { Value v = Value.date(null); assertThat(v.getType()).isEqualTo(Type.date()); assertThat(v.isNull()).isTrue(); assertThat(v.toString()).isEqualTo(NULL_STRING); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("null value"); v.getDate(); }
@Test public void boolWrapper() { Value v = Value.bool(Boolean.FALSE); assertThat(v.getType()).isEqualTo(Type.bool()); assertThat(v.isNull()).isFalse(); assertThat(v.getBool()).isFalse(); assertThat(v.toString()).isEqualTo("false"); }
@Test public void boolWrapperNull() { Value v = Value.bool(null); assertThat(v.getType()).isEqualTo(Type.bool()); assertThat(v.isNull()).isTrue(); assertThat(v.toString()).isEqualTo(NULL_STRING); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("null value"); v.getBool(); }