BAEL-1070 - CharSequence vs String in Java (#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.
This commit is contained in:
ahmetcetin39 2017-08-23 16:37:50 +03:00 committed by Zeger Hendrikse
parent 18b1334ff1
commit b6674f68dc
1 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,47 @@
package com.baeldung.string;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
public class CharSequenceVsStringUnitTest {
@Test
public void givenUsingString_whenInstantiatingString_thenWrong() {
CharSequence firstString = "bealdung";
String secondString = "baeldung";
assertNotEquals(firstString, secondString);
}
@Test
public void givenIdenticalCharSequences_whenCastToString_thenEqual() {
CharSequence charSequence1 = "baeldung_1";
CharSequence charSequence2 = "baeldung_2";
assertTrue(charSequence1.toString().compareTo(charSequence2.toString()) > 0);
}
@Test
public void givenString_whenAppended_thenUnmodified() {
String test = "a";
int firstAddressOfTest = System.identityHashCode(test);
test += "b";
int secondAddressOfTest = System.identityHashCode(test);
assertEquals(firstAddressOfTest, secondAddressOfTest);
}
@Test
public void givenStringBuilder_whenAppended_thenModified() {
StringBuilder test = new StringBuilder();
test.append("a");
int firstAddressOfTest = System.identityHashCode(test);
test.append("b");
int secondAddressOfTest = System.identityHashCode(test);
assertEquals(firstAddressOfTest, secondAddressOfTest);
}
}