assertSame() Method Example
package com.javaguides.junit5.assertions;
import static org.junit.Assert.assertSame;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;
public class JUnit5AssertSameExample {
private String processMap(final String key){
final Map<String, String> map = new HashMap<>();
map.put("key1", "value1");
map.put("key2", "value2");
map.put("key3", "value3");
map.put("key4", "value4");
map.put("key5", "value5");
map.put("key6", "value6");
map.put("key7", "value7");
map.put("key8", "value8");
return map.get(key);
}
@Test
public void checkSameReferenceTest(){
final JUnit5AssertSameExample example = new JUnit5AssertSameExample();
assertSame(example.processMap("key1"), example.processMap("key1"));
}
}
Output
Reference
Continue Learning with Java Guides
Want to take your programming skills to the next level? Explore my practical Udemy courses on Java, Spring Boot, Microservices, Full-Stack Development, Docker, and Generative AI. You can also follow my structured learning roadmaps to become a professional developer.
By Ramesh Fadatare - Udemy Instructor Partner
Comments
Post a Comment
Leave Comment