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

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

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

Assert.assertNotNull介绍

[英]Asserts that an object isn't null. If it is an AssertionError is thrown.
[中]断言对象不是null。如果是断言,则抛出断言错误。

代码示例

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

@Test
public void verifyAnnotationAutowiredFields() {
  assertNull("The nonrequiredLong property should NOT have been autowired.", this.nonrequiredLong);
  assertNotNull("The application context should have been autowired.", this.applicationContext);
  assertNotNull("The pet field should have been autowired.", this.pet);
  assertEquals("Dogbert", this.pet.getName());
}

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

@Test
public void mergeListWithInnerBeanAsListElement() throws Exception {
  TestBean bean = (TestBean) this.beanFactory.getBean("childWithListOfRefs");
  List list = bean.getSomeList();
  assertNotNull(list);
  assertEquals(3, list.size());
  assertNotNull(list.get(2));
  assertTrue(list.get(2) instanceof TestBean);
}

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

@Test
public void mergeListWithInnerBeanAsListElementInConstructor() throws Exception {
  TestBean bean = (TestBean) this.beanFactory.getBean("childWithListOfRefsInConstructor");
  List list = bean.getSomeList();
  assertNotNull(list);
  assertEquals(3, list.size());
  assertNotNull(list.get(2));
  assertTrue(list.get(2) instanceof TestBean);
}

代码示例来源: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 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 resolveMultipartFileArray() throws Exception {
  Object actual = resolver.resolveArgument(paramMultipartFileArray, null, webRequest, null);
  assertNotNull(actual);
  assertTrue(actual instanceof MultipartFile[]);
  MultipartFile[] parts = (MultipartFile[]) actual;
  assertEquals(2, parts.length);
  assertEquals(parts[0], multipartFile1);
  assertEquals(parts[1], multipartFile2);
}

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

@Test
public void loadContextHierarchy() {
  assertNotNull("child ApplicationContext", context);
  assertNull("parent ApplicationContext", context.getParent());
  assertEquals("foo-level-1", foo);
  assertEquals("bar", bar);
}

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

@Test
public void ofEmptyOptional() {
  ResponseEntity<Integer> responseEntity = ResponseEntity.of(Optional.empty());
  assertNotNull(responseEntity);
  assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
  assertNull(responseEntity.getBody());
}

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

@Test
public void loadContextHierarchy() {
  assertNotNull("child ApplicationContext", context);
  assertNull("parent ApplicationContext", context.getParent());
  assertEquals("foo-level-1", foo);
  assertEquals("bar", bar);
}

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

@Test
public void convertFromStreamToRawList() throws NoSuchFieldException {
  Stream<Integer> stream = Arrays.asList(1, 2, 3).stream();
  TypeDescriptor listOfStrings = new TypeDescriptor(Types.class.getField("rawList"));
  Object result = this.conversionService.convert(stream, listOfStrings);
  assertNotNull("Converted object must not be null", result);
  assertTrue("Converted object must be a list", result instanceof List);
  @SuppressWarnings("unchecked")
  List<Object> content = (List<Object>) result;
  assertEquals(1, content.get(0));
  assertEquals(2, content.get(1));
  assertEquals(3, content.get(2));
  assertEquals("Wrong number of elements", 3, content.size());
}

代码示例来源: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 mergeMapWithInnerBeanAsMapEntryValue() throws Exception {
  TestBean bean = (TestBean) this.beanFactory.getBean("childWithMapOfRefs");
  Map map = bean.getSomeMap();
  assertNotNull(map);
  assertEquals(2, map.size());
  assertNotNull(map.get("Rob"));
  assertTrue(map.get("Rob") instanceof TestBean);
  assertEquals("Sally", ((TestBean) map.get("Rob")).getName());
}

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

@Test
public void mergeMapWithInnerBeanAsMapEntryValueInConstructor() throws Exception {
  TestBean bean = (TestBean) this.beanFactory.getBean("childWithMapOfRefsInConstructor");
  Map map = bean.getSomeMap();
  assertNotNull(map);
  assertEquals(2, map.size());
  assertNotNull(map.get("Rob"));
  assertTrue(map.get("Rob") instanceof TestBean);
  assertEquals("Sally", ((TestBean) map.get("Rob")).getName());
}

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

@Test
public void testSunnyDaySetValue() throws Exception {
  CustomCollectionEditor editor = new CustomCollectionEditor(ArrayList.class);
  editor.setValue(new int[] {0, 1, 2});
  Object value = editor.getValue();
  assertNotNull(value);
  assertTrue(value instanceof ArrayList);
  List<?> list = (List<?>) value;
  assertEquals("There must be 3 elements in the converted collection", 3, list.size());
  assertEquals(new Integer(0), list.get(0));
  assertEquals(new Integer(1), list.get(1));
  assertEquals(new Integer(2), list.get(2));
}

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

@Test
public void resolveConfigAttributesWithMetaAnnotationAndLocations() {
  Class<MetaLocationsFoo> testClass = MetaLocationsFoo.class;
  List<ContextConfigurationAttributes> attributesList = resolveContextConfigurationAttributes(testClass);
  assertNotNull(attributesList);
  assertEquals(1, attributesList.size());
  assertAttributes(attributesList.get(0),
      testClass, new String[] {"/foo.xml"}, EMPTY_CLASS_ARRAY, ContextLoader.class, true);
}

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

@Test
public void resolveConfigAttributesWithLocalAnnotationAndLocations() {
  List<ContextConfigurationAttributes> attributesList = resolveContextConfigurationAttributes(LocationsFoo.class);
  assertNotNull(attributesList);
  assertEquals(1, attributesList.size());
  assertLocationsFooAttributes(attributesList.get(0));
}

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

@Test
public void resolveConfigAttributesWithMetaAnnotationAndLocationsAndOverrides() {
  Class<MetaLocationsFooWithOverrides> testClass = MetaLocationsFooWithOverrides.class;
  List<ContextConfigurationAttributes> attributesList = resolveContextConfigurationAttributes(testClass);
  assertNotNull(attributesList);
  assertEquals(1, attributesList.size());
  assertAttributes(attributesList.get(0),
      testClass, new String[] {"/foo.xml"}, EMPTY_CLASS_ARRAY, ContextLoader.class, true);
}

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

@Test
public void resolveConfigAttributesWithLocalAnnotationAndClasses() {
  List<ContextConfigurationAttributes> attributesList = resolveContextConfigurationAttributes(ClassesFoo.class);
  assertNotNull(attributesList);
  assertEquals(1, attributesList.size());
  assertClassesFooAttributes(attributesList.get(0));
}

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

@Test
@Override
public void loadContextHierarchy() {
  assertNotNull("child ApplicationContext", context);
  assertNotNull("parent ApplicationContext", context.getParent());
  assertNull("grandparent ApplicationContext", context.getParent().getParent());
  assertEquals("parent", parent);
  assertEquals("parent + test user", user);
  assertEquals("from TestUserConfig", beanFromTestUserConfig);
  assertNull("Bean from UserConfig should not be present.", beanFromUserConfig);
}

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

@Test
public void resolveConfigAttributesWithBareAnnotations() {
  Class<BareAnnotations> testClass = BareAnnotations.class;
  List<ContextConfigurationAttributes> attributesList = resolveContextConfigurationAttributes(testClass);
  assertNotNull(attributesList);
  assertEquals(1, attributesList.size());
  assertAttributes(attributesList.get(0),
      testClass, EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, ContextLoader.class, true);
}

相关文章