org.junit.Assert.assertSame()方法的使用及代码示例

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

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

Assert.assertSame介绍

[英]Asserts that two objects refer to the same object. If they are not the same, an AssertionError without a message is thrown.
[中]断言两个对象引用同一个对象。如果它们不相同,则抛出一个没有消息的AssertionError。

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testCollectionInjectionFromSameConfigurationClass() {
  ApplicationContext ctx = new AnnotationConfigApplicationContext(CollectionInjectionConfiguration.class);
  CollectionInjectionConfiguration bean = ctx.getBean(CollectionInjectionConfiguration.class);
  assertNotNull(bean.testBeans);
  assertEquals(1, bean.testBeans.size());
  assertSame(ctx.getBean(TestBean.class), bean.testBeans.get(0));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void orderOnImplementation() {
  this.context = new AnnotationConfigApplicationContext(
      UserServiceTwo.class, UserServiceOne.class, UserServiceCollector.class);
  UserServiceCollector bean = this.context.getBean(UserServiceCollector.class);
  assertSame(context.getBean("serviceOne", UserService.class), bean.userServices.get(0));
  assertSame(context.getBean("serviceTwo", UserService.class), bean.userServices.get(1));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void collectionMapNotGenericTarget() throws Exception {
  Map<String, List<String>> map = new HashMap<>();
  map.put("1", Arrays.asList("9", "12"));
  map.put("2", Arrays.asList("37", "23"));
  assertTrue(conversionService.canConvert(Map.class, Map.class));
  assertSame(map, conversionService.convert(map, Map.class));
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void badException() {
  Throwable e = new BadException();
  assertSame(e, new CompositeException(e).getCause().getCause());
  assertSame(e, new CompositeException(new RuntimeException(e)).getCause().getCause().getCause());
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void properties() {
  Timed<Integer> timed = new Timed<Integer>(1, 5, TimeUnit.SECONDS);
  assertEquals(1, timed.value().intValue());
  assertEquals(5, timed.time());
  assertEquals(5000, timed.time(TimeUnit.MILLISECONDS));
  assertSame(TimeUnit.SECONDS, timed.unit());
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void noHeadRetentionSize() {
  ReplaySubject<Integer> source = ReplaySubject.createWithSize(1);
  source.onNext(1);
  source.onNext(2);
  SizeBoundReplayBuffer<Integer> buf = (SizeBoundReplayBuffer<Integer>)source.buffer;
  assertNotNull(buf.head.value);
  source.cleanupBuffer();
  assertNull(buf.head.value);
  Object o = buf.head;
  source.cleanupBuffer();
  assertSame(o, buf.head);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testCollectionArgumentOnBeanMethod() {
  ApplicationContext ctx = new AnnotationConfigApplicationContext(CollectionArgumentConfiguration.class, TestBean.class);
  CollectionArgumentConfiguration bean = ctx.getBean(CollectionArgumentConfiguration.class);
  assertNotNull(bean.testBeans);
  assertEquals(1, bean.testBeans.size());
  assertSame(ctx.getBean(TestBean.class), bean.testBeans.get(0));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testInterfaceProxiesCanBeOrderedThroughAnnotations() {
  Object proxy1 = new ProxyFactory(new A()).getProxy();
  Object proxy2 = new ProxyFactory(new B()).getProxy();
  List<Object> list = new ArrayList<>(2);
  list.add(proxy1);
  list.add(proxy2);
  AnnotationAwareOrderComparator.sort(list);
  assertSame(proxy2, list.get(0));
  assertSame(proxy1, list.get(1));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testTranslatesIllegalStateException() {
  IllegalStateException ise = new IllegalStateException();
  DataAccessException dex = EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(ise);
  assertSame(ise, dex.getCause());
  assertTrue(dex instanceof InvalidDataAccessApiUsageException);
}

代码示例来源:origin: ReactiveX/RxJava

@SuppressWarnings("unchecked")
@Test
public void emptyArray() {
  assertSame(Flowable.empty(), Flowable.concatArrayDelayError());
}

代码示例来源:origin: spring-projects/spring-framework

private void assertOrder(List<?> actual, Object... expected) {
  for (int i = 0; i < actual.size(); i++) {
    assertSame("Wrong instance at index '" + i + "'", expected[i], actual.get(i));
  }
  assertEquals("Wrong number of items", expected.length, actual.size());
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void addInterceptorsWithCustomPathMatcher() {
  PathMatcher pathMatcher = Mockito.mock(PathMatcher.class);
  this.registry.addInterceptor(interceptor1).addPathPatterns("/path1/**").pathMatcher(pathMatcher);
  MappedInterceptor mappedInterceptor = (MappedInterceptor) this.registry.getInterceptors().get(0);
  assertSame(pathMatcher, mappedInterceptor.getPathMatcher());
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void source() {
  Maybe<Integer> m = Maybe.just(1);
  Single<Integer> s = m.toSingle();
  assertTrue(s.getClass().toString(), s instanceof HasUpstreamMaybeSource);
  assertSame(m, (((HasUpstreamMaybeSource<?>)s).source()));
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void source() {
  Observable<Integer> source = Observable.range(1, 3);
  assertSame(source, (((HasUpstreamObservableSource<?>)source.replay())).source());
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testVarargOnBeanMethod() {
  ApplicationContext ctx = new AnnotationConfigApplicationContext(VarargConfiguration.class, TestBean.class);
  VarargConfiguration bean = ctx.getBean(VarargConfiguration.class);
  assertNotNull(bean.testBeans);
  assertEquals(1, bean.testBeans.length);
  assertSame(ctx.getBean(TestBean.class), bean.testBeans[0]);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void customViewResolver() {
  InternalResourceViewResolver viewResolver = new InternalResourceViewResolver("/", ".jsp");
  this.registry.viewResolver(viewResolver);
  assertSame(viewResolver, this.registry.getViewResolvers().get(0));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void collectionToObjectInteraction() throws Exception {
  List<List<String>> list = new ArrayList<>();
  list.add(Arrays.asList("9", "12"));
  list.add(Arrays.asList("37", "23"));
  conversionService.addConverter(new CollectionToObjectConverter(conversionService));
  assertTrue(conversionService.canConvert(List.class, List.class));
  assertSame(list, conversionService.convert(list, List.class));
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testDontWrapSerializedSubjectAgain() {
  PublishProcessor<Object> s = PublishProcessor.create();
  FlowableProcessor<Object> s1 = s.toSerialized();
  FlowableProcessor<Object> s2 = s1.toSerialized();
  assertSame(s1, s2);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testMapInjectionFromSameConfigurationClass() {
  ApplicationContext ctx = new AnnotationConfigApplicationContext(MapInjectionConfiguration.class);
  MapInjectionConfiguration bean = ctx.getBean(MapInjectionConfiguration.class);
  assertNotNull(bean.testBeans);
  assertEquals(1, bean.testBeans.size());
  assertSame(ctx.getBean(Runnable.class), bean.testBeans.get("testBean"));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void convertAndSendWithSimpMessageHeaders() {
  MessageHeaderAccessor accessor = new MessageHeaderAccessor();
  accessor.setHeader("key", "value");
  accessor.setLeaveMutable(true);
  MessageHeaders headers = accessor.getMessageHeaders();
  this.template.convertAndSend("channel", "data", headers);
  List<Message<byte[]>> messages = this.messageChannel.getMessages();
  Message<byte[]> message = messages.get(0);
  assertSame(headers, message.getHeaders());
  assertFalse(accessor.isMutable());
}

相关文章