com.google.common.truth.Subject类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(113)

本文整理了Java中com.google.common.truth.Subject类的一些代码示例,展示了Subject类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Subject类的具体详情如下:
包路径:com.google.common.truth.Subject
类名称:Subject

Subject介绍

[英]An object that lets you perform checks on the value under test. For example, Subjectcontains #isEqualTo(Object) and #isInstanceOf(Class), and StringSubjectcontains StringSubject#startsWith.

To create a Subject instance, most users will call an Truth#assertThat method. For information about other ways to create an instance, see this FAQ entry.

For people extending Truth

For information about writing a custom Subject, see our doc on extensions.
[中]一个对象,用于检查被测值。例如,Subjectcontains#isEqualTo(对象)和#isInstanceOf(类),StringSubjectcontains StringSubject#StartWith。
要创建主题实例,大多数用户都会调用Truth#assertThat方法。有关创建实例的其他方法的信息,请参见this FAQ entry
####为了人们传播真理
有关编写自定义主题的信息,请参阅our doc on extensions

代码示例

代码示例来源:origin: google/guava

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);
 }
}

代码示例来源:origin: robolectric/robolectric

@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");
}

代码示例来源:origin: google/guava

public void testOnlyElementNull() {
 assertThat(Stream.of((Object) null).collect(MoreCollectors.onlyElement())).isNull();
}

代码示例来源:origin: google/guava

@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);
}

代码示例来源:origin: google/guava

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);
}

代码示例来源:origin: square/picasso

@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();
}

代码示例来源:origin: google/guava

@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
}

代码示例来源:origin: google/guava

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);

代码示例来源:origin: google/guava

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();
}

代码示例来源:origin: googleapis/google-cloud-java

@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");
}

代码示例来源:origin: google/ExoPlayer

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);
}

代码示例来源:origin: robolectric/robolectric

@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();
}

代码示例来源:origin: bumptech/glide

@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);
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void string() {
 Value v = Value.string("abc");
 assertThat(v.getType()).isEqualTo(Type.string());
 assertThat(v.isNull()).isFalse();
 assertThat(v.getString()).isEqualTo("abc");
}

代码示例来源:origin: googleapis/google-cloud-java

@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();
}

代码示例来源:origin: googleapis/google-cloud-java

@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();
}

代码示例来源:origin: googleapis/google-cloud-java

@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();
}

代码示例来源:origin: googleapis/google-cloud-java

@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();
}

代码示例来源:origin: googleapis/google-cloud-java

@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");
}

代码示例来源:origin: googleapis/google-cloud-java

@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();
}

相关文章