Equals() Vs Contentequals() Method in Java (#11598)
* Application source code for the Baeldung article "HTTP PUT vs POST method in REST API" * update indention in pom file, update code in Address class * update indention * rename application * update pom * source code for article "Connection timeout vs read timeout" * Source code for Baeldung article BAEL-4896 * update code * code for article "String Equals() Vs Contentequals() Method in Java" * update code with tests * code update * update test methods * remove upper case and wrong sequence test * remove wrong sequence and upper case string variables
This commit is contained in:
parent
e10f813a93
commit
cf49235b4e
|
@ -0,0 +1,30 @@
|
|||
package com.baeldung.equalsvscontentequals;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class StringEqualsVsContentEqualsUnitTest {
|
||||
|
||||
String actualString = "baeldung";
|
||||
String identicalString = "baeldung";
|
||||
CharSequence identicalStringInstance = "baeldung";
|
||||
CharSequence identicalStringBufferInstance = new StringBuffer("baeldung");
|
||||
|
||||
@Test
|
||||
public void whenIdenticalTestString_thenBothTrue() {
|
||||
assertTrue(actualString.equals(identicalString));
|
||||
assertTrue(actualString.contentEquals(identicalString));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSameContentButDifferentType_thenEqualsIsFalseAndContentEqualsIsTrue() {
|
||||
assertTrue(actualString.equals(identicalStringInstance));
|
||||
assertTrue(actualString.contentEquals(identicalStringInstance));
|
||||
|
||||
assertFalse(actualString.equals(identicalStringBufferInstance));
|
||||
assertTrue(actualString.contentEquals(identicalStringBufferInstance));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue