JAVA EXAMPLE PROGRAMS

JAVA EXAMPLE PROGRAMS

Publish Your Article Here

Program: Assertion method Assert.assertNotNull() example.


Java Class: org.junit.Assert

Assert class provides a set of assertion methods useful for writing tests.

Assert.assertNotNull() methods checks that the object is null or not. If it is null then it throws an AssertionError.


package com.java2novice.junit.tests;

import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.*;
import org.junit.Test;

public class MyAssertNotNullTest {

	public String getPropValue(final String key){
		Map appProps = new HashMap();
		appProps.put("key1", "value 1");
		appProps.put("key2", "value 2");
		appProps.put("key3", "value 3");
		return appProps.get(key);
	}
	
	@Test
	public void test(){
		MyAssertNotNullTest msnt = new MyAssertNotNullTest();
		assertNotNull(msnt.getPropValue("key1"));
	}
}

<< Previous Program | Next Program >>
blog comments powered by Disqus

Java JUnit Examples

  1. Simple JUnit test using @Test annotation.
  2. List of JUnit annotations.
  3. Assertion method Assert.assertArrayEquals() example.
  4. How to do JUnit test for comapring two list of user defined objects?
  5. Assertion method Assert.assertEquals() example.
  6. Assertion method Assert.assertFalse() example.
  7. Assertion method Assert.assertTrue() example.
  8. Assertion method Assert.assertNotNull() example.
  9. Assertion method Assert.assertNull() example.
  10. Assertion method Assert.assertNotSame() example.
  11. Assertion method Assert.assertSame() example.
Knowledge Centre
Preemptive scheduling Vs Time slicing?
Preemptive scheduling: The highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence.

Time slicing: A task executes for a predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines which task should execute next, based on priority and other factors.
Famous Quotations
Education is what remains after one has forgotten what one has learned in school.
-- Albert Einstein

About Author

Most Visited Pages

Other Interesting Sites

Reference: Java™ Platform Standard Ed. 7 - API Specification | Java is registered trademark of Oracle.
Privacy Policy | Copyright © 2017 by Nataraja Gootooru. All Rights Reserved.