本文整理了Java中org.junit.Assert.assertNotSame()
方法的一些代码示例,展示了Assert.assertNotSame()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Assert.assertNotSame()
方法的具体详情如下:
包路径:org.junit.Assert
类名称:Assert
方法名:assertNotSame
[英]Asserts that two objects do not refer to the same object. If they do refer to the same object, an AssertionError without a message is thrown.
[中]断言两个对象不引用同一个对象。如果它们引用同一个对象,则会抛出一个没有消息的AssertionError。
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testWithFinalFactoryBeanAsReturnType() {
ApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithFinalFactoryBeanAsReturnType.class);
assertEquals("x", context.getBean(Bar.class).foo.toString());
// not same due to fallback to raw FinalFactoryBean instance with repeated getObject() invocations
assertNotSame(context.getBean(FooInterface.class), context.getBean(Bar.class).foo);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testAliasThatOverridesParent() {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(FQ_SIMPLE_CONTEXT);
Object someMs = ctx.getBean("someMessageSource");
ClassPathXmlApplicationContext child = new ClassPathXmlApplicationContext(
new String[] {ALIAS_THAT_OVERRIDES_PARENT_CONTEXT}, ctx);
Object myMs = child.getBean("myMessageSource");
Object someMs2 = child.getBean("someMessageSource");
assertSame(myMs, someMs2);
assertNotSame(someMs, someMs2);
assertOneMessageSourceOnly(child, myMs);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void verifyContextDirty() {
assertContextCacheStatistics("verifyContextWasDirtied()", 1, 0, 2);
assertNotNull("The application context should have been autowired.", this.applicationContext);
assertNotSame("The application context should have been 'dirtied'.",
SpringRunnerContextCacheTests.dirtiedApplicationContext, this.applicationContext);
SpringRunnerContextCacheTests.dirtiedApplicationContext = this.applicationContext;
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testClone() throws Exception {
final Object test = SerializationUtils.clone(iMap);
assertNotNull(test);
assertTrue(test instanceof HashMap<?,?>);
assertNotSame(test, iMap);
final HashMap<?, ?> testMap = (HashMap<?, ?>) test;
assertEquals(iString, testMap.get("FOO"));
assertNotSame(iString, testMap.get("FOO"));
assertEquals(iInteger, testMap.get("BAR"));
assertNotSame(iInteger, testMap.get("BAR"));
assertEquals(iMap, testMap);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void convertCannotOptimizeArray() {
conversionService.addConverter(new Converter<Byte, Byte>() {
@Override
public Byte convert(Byte source) {
return (byte) (source + 1);
}
});
byte[] byteArray = new byte[] {1, 2, 3};
byte[] converted = conversionService.convert(byteArray, byte[].class);
assertNotSame(byteArray, converted);
assertTrue(Arrays.equals(new byte[] {2, 3, 4}, converted));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testDefaultIoSchedulerIsInitializedLazily() {
// unsafe default Scheduler Callable should not be evaluated
try {
RxJavaPlugins.setInitIoSchedulerHandler(initReplaceWithImmediate);
RxJavaPlugins.initIoScheduler(unsafeDefault);
} finally {
RxJavaPlugins.reset();
}
// make sure the reset worked
assertNotSame(ImmediateThinScheduler.INSTANCE, Schedulers.io());
}
代码示例来源:origin: spring-projects/spring-framework
private void lookupOverrideMethodsWithSetterInjection(BeanFactory xbf,
String beanName, boolean singleton) {
OverrideOneMethod oom = (OverrideOneMethod) xbf.getBean(beanName);
if (singleton) {
assertSame(oom, xbf.getBean(beanName));
}
else {
assertNotSame(oom, xbf.getBean(beanName));
}
TestBean jenny1 = oom.getPrototypeDependency();
assertEquals("Jenny", jenny1.getName());
TestBean jenny2 = oom.getPrototypeDependency();
assertEquals("Jenny", jenny2.getName());
assertNotSame(jenny1, jenny2);
// Check that the bean can invoke the overridden method on itself
// This differs from Spring's AOP support, which has a distinct notion
// of a "target" object, meaning that the target needs explicit knowledge
// of AOP proxying to invoke an advised method on itself.
TestBean jenny3 = oom.invokesOverriddenMethodOnSelf();
assertEquals("Jenny", jenny3.getName());
assertNotSame(jenny1, jenny3);
// Now try protected method, and singleton
TestBean dave1 = oom.protectedOverrideSingleton();
assertEquals("David", dave1.getName());
TestBean dave2 = oom.protectedOverrideSingleton();
assertEquals("David", dave2.getName());
assertSame(dave1, dave2);
}
代码示例来源:origin: spring-projects/spring-framework
public void testEvict(CacheableService<?> service) throws Exception {
Object o1 = new Object();
Object r1 = service.cache(o1);
Object r2 = service.cache(o1);
assertSame(r1, r2);
service.invalidate(o1);
Object r3 = service.cache(o1);
Object r4 = service.cache(o1);
assertNotSame(r1, r3);
assertSame(r3, r4);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void createFromNativeHeaderMap() {
MultiValueMap<String, String> inputNativeHeaders = new LinkedMultiValueMap<>();
inputNativeHeaders.add("foo", "bar");
inputNativeHeaders.add("bar", "baz");
NativeMessageHeaderAccessor headerAccessor = new NativeMessageHeaderAccessor(inputNativeHeaders);
Map<String, Object> actual = headerAccessor.toMap();
assertEquals(actual.toString(), 1, actual.size());
assertNotNull(actual.get(NativeMessageHeaderAccessor.NATIVE_HEADERS));
assertEquals(inputNativeHeaders, actual.get(NativeMessageHeaderAccessor.NATIVE_HEADERS));
assertNotSame(inputNativeHeaders, actual.get(NativeMessageHeaderAccessor.NATIVE_HEADERS));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void resolveResourceInternal() {
Resource expected = new ClassPathResource("test/bar.css", getClass());
Resource actual = this.chain.resolveResource(null, "bar.css", this.locations);
assertNotSame(expected, actual);
assertEquals(expected, actual);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void overrideIoScheduler() {
try {
RxJavaPlugins.setIoSchedulerHandler(replaceWithImmediate);
assertSame(ImmediateThinScheduler.INSTANCE, Schedulers.io());
} finally {
RxJavaPlugins.reset();
}
// make sure the reset worked
assertNotSame(ImmediateThinScheduler.INSTANCE, Schedulers.io());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void localResources() throws Exception {
this.resourceFactory.setUseGlobalResources(false);
this.resourceFactory.afterPropertiesSet();
ConnectionProvider connectionProvider = this.resourceFactory.getConnectionProvider();
LoopResources loopResources = this.resourceFactory.getLoopResources();
assertNotSame(HttpResources.get(), connectionProvider);
assertNotSame(HttpResources.get(), loopResources);
// The below does not work since ConnectionPoolProvider simply checks if pool is empty.
// assertFalse(connectionProvider.isDisposed());
assertFalse(loopResources.isDisposed());
this.resourceFactory.destroy();
assertTrue(connectionProvider.isDisposed());
assertTrue(loopResources.isDisposed());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void preflightRequestWithoutCorsConfigurationProvider() throws Exception {
String origin = "http://domain2.com";
ServerWebExchange exchange = createExchange(HttpMethod.OPTIONS, "/welcome.html", origin);
Object actual = this.handlerMapping.getHandler(exchange).block();
assertNotNull(actual);
assertNotSame(this.welcomeController, actual);
assertNull(exchange.getResponse().getHeaders().getFirst(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testDefaultSingleSchedulerIsInitializedLazily() {
// unsafe default Scheduler Callable should not be evaluated
try {
RxJavaPlugins.setInitSingleSchedulerHandler(initReplaceWithImmediate);
RxJavaPlugins.initSingleScheduler(unsafeDefault);
} finally {
RxJavaPlugins.reset();
}
// make sure the reset worked
assertNotSame(ImmediateThinScheduler.INSTANCE, Schedulers.single());
}
代码示例来源:origin: spring-projects/spring-framework
public void testEvictWKey(CacheableService<?> service) throws Exception {
Object o1 = new Object();
Object r1 = service.cache(o1);
Object r2 = service.cache(o1);
assertSame(r1, r2);
service.evict(o1, null);
Object r3 = service.cache(o1);
Object r4 = service.cache(o1);
assertNotSame(r1, r3);
assertSame(r3, r4);
}
代码示例来源:origin: spring-projects/spring-framework
private void testReturnValueHandlers(Object bean) {
assertNotNull(bean);
Object value = new DirectFieldAccessor(bean).getPropertyValue("customReturnValueHandlers");
assertNotNull(value);
assertTrue(value instanceof List);
@SuppressWarnings("unchecked")
List<HandlerMethodReturnValueHandler> handlers = (List<HandlerMethodReturnValueHandler>) value;
assertEquals(2, handlers.size());
assertEquals(TestHandlerMethodReturnValueHandler.class, handlers.get(0).getClass());
assertEquals(TestHandlerMethodReturnValueHandler.class, handlers.get(1).getClass());
assertNotSame(handlers.get(0), handlers.get(1));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void resolveResourceInternal() {
Resource expected = new ClassPathResource("test/bar.css", getClass());
MockServerWebExchange exchange = MockServerWebExchange.from(get(""));
Resource actual = this.chain.resolveResource(exchange, "bar.css", this.locations).block(TIMEOUT);
assertNotSame(expected, actual);
assertEquals(expected, actual);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void configurationWithPrototypeScopedBeans() {
BeanFactory factory = initBeanFactory(ConfigWithPrototypeBean.class);
TestBean foo = factory.getBean("foo", TestBean.class);
ITestBean bar = factory.getBean("bar", ITestBean.class);
ITestBean baz = factory.getBean("baz", ITestBean.class);
assertSame(foo.getSpouse(), bar);
assertNotSame(bar.getSpouse(), baz);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testPerTarget() throws SecurityException, NoSuchMethodException {
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
ajexp.setExpression(AspectJExpressionPointcutTests.MATCH_ALL_METHODS);
InstantiationModelAwarePointcutAdvisorImpl ajpa = new InstantiationModelAwarePointcutAdvisorImpl(
ajexp, TestBean.class.getMethod("getAge"), af,
new SingletonMetadataAwareAspectInstanceFactory(new PerTargetAspect(), "someBean"),
1, "someBean");
assertNotSame(Pointcut.TRUE, ajpa.getAspectMetadata().getPerClausePointcut());
assertTrue(ajpa.getAspectMetadata().getPerClausePointcut() instanceof AspectJExpressionPointcut);
assertTrue(ajpa.isPerInstance());
assertTrue(ajpa.getAspectMetadata().getPerClausePointcut().getClassFilter().matches(TestBean.class));
assertFalse(ajpa.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(
TestBean.class.getMethod("getAge"), TestBean.class));
assertTrue(ajpa.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(
TestBean.class.getMethod("getSpouse"), TestBean.class));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testLazyLoading() {
try {
Person tony = new Person();
tony.setFirstName("Tony");
tony.setLastName("Blair");
tony.setDriversLicense(new DriversLicense("8439DK"));
sharedEntityManager.persist(tony);
setComplete();
endTransaction();
startNewTransaction();
sharedEntityManager.clear();
Person newTony = entityManagerFactory.createEntityManager().getReference(Person.class, tony.getId());
assertNotSame(newTony, tony);
endTransaction();
assertNotNull(newTony.getDriversLicense());
newTony.getDriversLicense().getSerialNumber();
}
finally {
deleteFromTables("person", "drivers_license");
}
}
内容来源于网络,如有侵权,请联系作者删除!