JAVA EXAMPLE PROGRAMS

JAVA EXAMPLE PROGRAMS

Publish Your Article Here

Program: Assertion method Assert.assertNotSame() example.


Java Class: org.junit.Assert

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

Assert.assertNotSame() methods checks that two objects do not refer to the same object. If they do refer to the same object, an AssertionError is thrown.


package com.java2novice.junit.tests;

import static org.junit.Assert.*;

import java.util.HashMap;
import java.util.Map;

import org.junit.Test;

public class MyAssertNotSameTest {

	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 isSameReferenceTest(){
		
		MyAssertNotSameTest msnt = new MyAssertNotSameTest();
		assertNotSame(msnt.getPropValue("key1"), msnt.getPropValue("key2"));
	}
}

<< 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
Can we override static method?
We cannot override static methods. Static methods are belogs to class, not belongs to object. Inheritance will not be applicable for class members
Famous Quotations
Be yourself; everyone else is already taken.
-- Oscar Wilde

About Author

I'm Nataraja Gootooru, programmer by profession and passionate about technologies. All examples given here are as simple as possible to help beginners. The source code is compiled and tested in my dev environment.

If you come across any mistakes or bugs, please email me to java2novice@gmail.com or you can comment on the page.

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.