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:
Mainak Majumder 2022-01-03 02:59:00 +01:00 committed by GitHub
parent e10f813a93
commit cf49235b4e
1 changed files with 30 additions and 0 deletions

View File

@ -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));
}
}