Skip to content

Commit b6674f6

Browse files
ahmetcetin39zhendrikse
authored andcommitted
BAEL-1070 - CharSequence vs String in Java (eugenp#2451)
* Different types of bean injection classes are added. * JUnit Tests for Zoo and Forest Class * Necessary dependency is added to pom.xml * Updated pom.xml Carried dependency to into another dependency tag. * dependency added. * dependency is carried. * dependency is added. * A test dependency is added. * dependency is changed. * Dependency is changed. * Test classes are changed and moved. * test correction * correction * String vs CharSequence * unnecesseray files are deleted. * correction * Assert statemenet is changed from java to junit * Assert is changed. * changed the name of the test methods.
1 parent 18b1334 commit b6674f6

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.baeldung.string;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.assertEquals;
6+
import static org.junit.Assert.assertNotEquals;
7+
import static org.junit.Assert.assertTrue;
8+
9+
public class CharSequenceVsStringUnitTest {
10+
11+
@Test
12+
public void givenUsingString_whenInstantiatingString_thenWrong() {
13+
CharSequence firstString = "bealdung";
14+
String secondString = "baeldung";
15+
16+
assertNotEquals(firstString, secondString);
17+
}
18+
19+
@Test
20+
public void givenIdenticalCharSequences_whenCastToString_thenEqual() {
21+
CharSequence charSequence1 = "baeldung_1";
22+
CharSequence charSequence2 = "baeldung_2";
23+
24+
assertTrue(charSequence1.toString().compareTo(charSequence2.toString()) > 0);
25+
}
26+
27+
@Test
28+
public void givenString_whenAppended_thenUnmodified() {
29+
String test = "a";
30+
int firstAddressOfTest = System.identityHashCode(test);
31+
test += "b";
32+
int secondAddressOfTest = System.identityHashCode(test);
33+
34+
assertEquals(firstAddressOfTest, secondAddressOfTest);
35+
}
36+
37+
@Test
38+
public void givenStringBuilder_whenAppended_thenModified() {
39+
StringBuilder test = new StringBuilder();
40+
test.append("a");
41+
int firstAddressOfTest = System.identityHashCode(test);
42+
test.append("b");
43+
int secondAddressOfTest = System.identityHashCode(test);
44+
45+
assertEquals(firstAddressOfTest, secondAddressOfTest);
46+
}
47+
}

0 commit comments

Comments
 (0)