com.google.common.truth.Subject.isEqualTo()方法的使用及代码示例

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

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

Subject.isEqualTo介绍

[英]Fails if the subject is not equal to the given object. For the purposes of this comparison, two objects are equal if any of the following is true:

  • they are equal according to Objects#equal
  • they are arrays and are considered equal by the appropriate Arrays#equalsoverload
  • they are boxed integer types ( Byte, Short, Character, Integer, or Long) and they are numerically equal when converted to Long.
    [中]如果主体与给定对象不相等,则失败。在本次比较中,如果以下任何一项为真,则两个对象相等:
    *根据对象,它们是相等的
    *它们是数组,被适当的数组#equalsoverload视为相等
    *它们是装箱整数类型(字节、短字符、字符、整数或长字符),在转换为长字符时在数字上是相等的。

代码示例

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

public void testToGenericType_staticMemberClass() throws Exception {
 Method getStaticAnonymousClassMethod =
   TypeTokenTest.class.getDeclaredMethod("getStaticAnonymousClass", Object.class);
 ParameterizedType javacReturnType =
   (ParameterizedType) getStaticAnonymousClassMethod.getGenericReturnType();
 ParameterizedType parameterizedType =
   (ParameterizedType) TypeToken.toGenericType(GenericClass.class).getType();
 assertThat(parameterizedType.getOwnerType()).isEqualTo(javacReturnType.getOwnerType());
}

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

@Test
public void testLoadBitmap_asDrawable() {
 Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
 requestManager
   .load(bitmap)
   .into(target);
 ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class);
 verify(target).onResourceReady(captor.capture(), any(Transition.class));
 BitmapDrawable drawable = (BitmapDrawable) captor.getValue();
 assertThat(drawable.getBitmap()).isEqualTo(bitmap);
}

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

@Test
public void getDefaultTransitionOptions_withNoOptionsRegistered_returnsDefaultOptions() {
 assertThat(context.getDefaultTransitionOptions(Object.class))
   .isEqualTo(GlideContext.DEFAULT_TRANSITION_OPTIONS);
}

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

public void testGetSubtype_subtypeSameAsDeclaringType() throws Exception {
 class Bar<T> {}
 class SubBar<T> extends Bar<T> {
  @SuppressWarnings("unused")
  Bar<T> delegate;
  TypeToken<SubBar<T>> fieldTypeAsSubBar() {
   return new TypeToken<SubBar<T>>() {};
  }
 }
 Field delegateField = SubBar.class.getDeclaredField("delegate");
 // barType is Bar<T>, a ParameterizedType with no generic arguments specified
 TypeToken<?> barType = TypeToken.of(delegateField.getGenericType());
 assertThat(barType.getSubtype(SubBar.class)).isEqualTo(new SubBar<Void>().fieldTypeAsSubBar());
}

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

@Test
public void testGetCurrentFrameReturnsFirstFrameWHenNoLoadHasCompleted() {
 assertThat(loader.getCurrentFrame()).isEqualTo(firstFrame);
}

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

public void testToByteArrayAndFromByteArrayRoundTrip() {
 for (PairedStats pairedStats : ALL_PAIRED_STATS) {
  byte[] pairedStatsByteArray = pairedStats.toByteArray();
  // Round trip to byte array and back
  assertThat(PairedStats.fromByteArray(pairedStatsByteArray)).isEqualTo(pairedStats);
 }
}

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

@Test
public void copyOf_directedGraph() {
 Graph<Integer> directedGraph = buildDirectedGraph();
 Graph<Integer> copy = copyOf(directedGraph);
 assertThat(copy).isEqualTo(directedGraph);
}

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

public void testToByteArrayAndFromByteArrayRoundTrip() {
 for (Stats stats : ALL_STATS) {
  byte[] statsByteArray = stats.toByteArray();
  // Round trip to byte array and back
  assertThat(Stats.fromByteArray(statsByteArray)).isEqualTo(stats);
 }
}

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

@Test
public void copyOf_undirectedGraph() {
 Graph<Integer> undirectedGraph = buildUndirectedGraph();
 Graph<Integer> copy = copyOf(undirectedGraph);
 assertThat(copy).isEqualTo(undirectedGraph);
}

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

static void assertStronglyEquivalent(ValueGraph<?, ?> graphA, ValueGraph<?, ?> graphB) {
 // Properties not covered by equals()
 assertThat(graphA.allowsSelfLoops()).isEqualTo(graphB.allowsSelfLoops());
 assertThat(graphA.nodeOrder()).isEqualTo(graphB.nodeOrder());
 assertThat(graphA).isEqualTo(graphB);
}

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

@Test
public void copyOf_directedValueGraph() {
 ValueGraph<Integer, String> directedGraph = buildDirectedValueGraph();
 ValueGraph<Integer, String> copy = copyOf(directedGraph);
 assertThat(copy).isEqualTo(directedGraph);
}

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

@GwtIncompatible // Iterables.filter(Iterable, Class)
public void testFilterByType_forEach() throws Exception {
 HasBoth hasBoth1 = new HasBoth();
 HasBoth hasBoth2 = new HasBoth();
 Iterable<TypeA> alist = Lists.newArrayList(hasBoth1, new TypeA(), hasBoth2, new TypeA());
 Iterable<TypeB> blist = Iterables.filter(alist, TypeB.class);
 Iterator<TypeB> expectedIterator = Arrays.<TypeB>asList(hasBoth1, hasBoth2).iterator();
 blist.forEach(b -> assertThat(b).isEqualTo(expectedIterator.next()));
 assertThat(expectedIterator.hasNext()).isFalse();
}

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

@Test
public void copyOf_undirectedValueGraph() {
 ValueGraph<Integer, String> undirectedGraph = buildUndirectedValueGraph();
 ValueGraph<Integer, String> copy = copyOf(undirectedGraph);
 assertThat(copy).isEqualTo(undirectedGraph);
}

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

static void assertStronglyEquivalent(Graph<?> graphA, Graph<?> graphB) {
 // Properties not covered by equals()
 assertThat(graphA.allowsSelfLoops()).isEqualTo(graphB.allowsSelfLoops());
 assertThat(graphA.nodeOrder()).isEqualTo(graphB.nodeOrder());
 assertThat(graphA).isEqualTo(graphB);
}

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

@Test
public void copyOf_directedNetwork() {
 Network<Integer, String> directedGraph = buildDirectedNetwork();
 Network<Integer, String> copy = copyOf(directedGraph);
 assertThat(copy).isEqualTo(directedGraph);
}

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

static void assertStronglyEquivalent(Network<?, ?> networkA, Network<?, ?> networkB) {
 // Properties not covered by equals()
 assertThat(networkA.allowsParallelEdges()).isEqualTo(networkB.allowsParallelEdges());
 assertThat(networkA.allowsSelfLoops()).isEqualTo(networkB.allowsSelfLoops());
 assertThat(networkA.nodeOrder()).isEqualTo(networkB.nodeOrder());
 assertThat(networkA.edgeOrder()).isEqualTo(networkB.edgeOrder());
 assertThat(networkA).isEqualTo(networkB);
}

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

@Test
public void copyOf_undirectedNetwork() {
 Network<Integer, String> undirectedGraph = buildUndirectedNetwork();
 Network<Integer, String> copy = copyOf(undirectedGraph);
 assertThat(copy).isEqualTo(undirectedGraph);
}

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

public void testCatching() throws Exception {
 FluentFuture<?> f =
   FluentFuture.from(immediateFailedFuture(new RuntimeException()))
     .catching(
       Throwable.class,
       new Function<Throwable, Class<?>>() {
        @Override
        public Class<?> apply(Throwable input) {
         return input.getClass();
        }
       },
       directExecutor());
 assertThat(f.get()).isEqualTo(RuntimeException.class);
}

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

@Test
 public void getDefaultTransitionOptions_withSuperClassRegistered_returnsSuperClassOptions() {
  DrawableTransitionOptions expected = new DrawableTransitionOptions();
  transitionOptions.put(Drawable.class, expected);
  assertThat(context.getDefaultTransitionOptions(BitmapDrawable.class))
    .isEqualTo(expected);
  assertThat(context.getDefaultTransitionOptions(GifDrawable.class))
    .isEqualTo(expected);
 }
}

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

public void testCatchingAsync() throws Exception {
 FluentFuture<?> f =
   FluentFuture.from(immediateFailedFuture(new RuntimeException()))
     .catchingAsync(
       Throwable.class,
       new AsyncFunction<Throwable, Class<?>>() {
        @Override
        public ListenableFuture<Class<?>> apply(Throwable input) {
         return Futures.<Class<?>>immediateFuture(input.getClass());
        }
       },
       directExecutor());
 assertThat(f.get()).isEqualTo(RuntimeException.class);
}

相关文章