Skip to content

Commit

Permalink
Merge pull request eugenp#16790 from sk1418/impr-charSeq-vs-str
Browse files Browse the repository at this point in the history
[impr-charSeq-vs-str] str equality
  • Loading branch information
theangrydev authored Jun 7, 2024
2 parents 000da73 + ab3bcf3 commit 7f77dc2
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package com.baeldung.charsequence;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

import static org.junit.Assert.*;

public class CharSequenceVsStringUnitTest {

@Test
public void givenUsingString_whenInstantiatingString_thenWrong() {
CharSequence firstString = "bealdung";
String secondString = "baeldung";
public void givenSameValue_whenInstantiatingStringWithConstructor_thenDifferentObjects() {
String string1 = "baeldung";
String string2 = "baeldung";

assertEquals(string1, string2);
assertSame(string1, string2);

assertNotEquals(firstString, secondString);
String string3 = new String("baeldung");
assertEquals(string1, string3);
assertNotSame(string1, string3);
}

@Test
Expand Down Expand Up @@ -83,4 +86,4 @@ public void givenCharSequence_whenConvertingUsingValueOf_thenCorrect() {
assertEquals("null", String.valueOf(charSequence3));
}

}
}

0 comments on commit 7f77dc2

Please sign in to comment.