Merge branch 'master' into bael-965
This commit is contained in:
@@ -8,31 +8,46 @@ import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class CourseServiceTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void givenCourse_whenSetValuesUsingPropertyUtil_thenReturnSetValues()
|
||||
throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
|
||||
throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
|
||||
Course course = new Course();
|
||||
String name = "Computer Science";
|
||||
List<String> codes = Arrays.asList("CS", "CS01");
|
||||
CourseService.setValues(course, name, codes);
|
||||
|
||||
|
||||
Assert.assertEquals(name, course.getName());
|
||||
Assert.assertEquals(2, course.getCodes().size());
|
||||
Assert.assertEquals("CS", course.getCodes().get(0));
|
||||
|
||||
|
||||
CourseService.setIndexedValue(course, 1, "CS02");
|
||||
Assert.assertEquals("CS02", course.getCodes().get(1));
|
||||
|
||||
|
||||
Student student = new Student();
|
||||
String studentName = "Joe";
|
||||
student.setName(studentName);
|
||||
|
||||
|
||||
CourseService.setMappedValue(course, "ST-1", student);
|
||||
Assert.assertEquals(student, course.getEnrolledStudent("ST-1"));
|
||||
|
||||
|
||||
String accessedStudentName = CourseService.getNestedValue(course, "ST-1", "name");
|
||||
Assert.assertEquals(studentName, accessedStudentName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenCopyProperties_whenCopyCourseToCourseEntity_thenCopyPropertyWithSameName()
|
||||
throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
|
||||
Course course = new Course();
|
||||
course.setName("Computer Science");
|
||||
course.setCodes(Arrays.asList("CS"));
|
||||
course.setEnrolledStudent("ST-1", new Student());
|
||||
|
||||
CourseEntity courseEntity = new CourseEntity();
|
||||
|
||||
CourseService.copyProperties(course, courseEntity);
|
||||
Assert.assertEquals(course.getName(), courseEntity.getName());
|
||||
Assert.assertEquals(course.getCodes(), courseEntity.getCodes());
|
||||
Assert.assertNull(courseEntity.getStudent("ST-1"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.baeldung.text;
|
||||
|
||||
import org.apache.commons.text.diff.EditScript;
|
||||
import org.apache.commons.text.diff.StringsComparator;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DiffTest {
|
||||
|
||||
@Test
|
||||
public void whenEditScript_thenCorrect() {
|
||||
StringsComparator cmp = new StringsComparator("ABCFGH", "BCDEFG");
|
||||
EditScript<Character> script = cmp.getScript();
|
||||
int mod = script.getModifications();
|
||||
|
||||
Assert.assertEquals(4, mod);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.baeldung.text;
|
||||
|
||||
import org.apache.commons.text.similarity.LongestCommonSubsequence;
|
||||
import org.apache.commons.text.similarity.LongestCommonSubsequenceDistance;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class LongestCommonSubsequenceTest {
|
||||
|
||||
@Test
|
||||
public void whenCompare_thenCorrect() {
|
||||
LongestCommonSubsequence lcs = new LongestCommonSubsequence();
|
||||
int countLcs = lcs.apply("New York", "New Hampshire");
|
||||
|
||||
Assert.assertEquals(5, countLcs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCalculateDistance_thenCorrect() {
|
||||
LongestCommonSubsequenceDistance lcsd = new LongestCommonSubsequenceDistance();
|
||||
int countLcsd = lcsd.apply("New York", "New Hampshire");
|
||||
|
||||
Assert.assertEquals(11, countLcsd);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.baeldung.text;
|
||||
|
||||
import org.apache.commons.text.StrBuilder;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class StrBuilderTest {
|
||||
|
||||
@Test
|
||||
public void whenReplaced_thenCorrect() {
|
||||
StrBuilder strBuilder = new StrBuilder("example StrBuilder!");
|
||||
strBuilder.replaceAll("example", "new");
|
||||
|
||||
Assert.assertEquals(new StrBuilder("new StrBuilder!"), strBuilder);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCleared_thenEmpty() {
|
||||
StrBuilder strBuilder = new StrBuilder("example StrBuilder!");
|
||||
strBuilder.clear();
|
||||
|
||||
Assert.assertEquals(new StrBuilder(""), strBuilder);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.text;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.text.StrSubstitutor;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class StrSubstitutorTest {
|
||||
|
||||
@Test
|
||||
public void whenSubstituted_thenCorrect() {
|
||||
Map<String, String> substitutes = new HashMap<>();
|
||||
substitutes.put("name", "John");
|
||||
substitutes.put("college", "University of Stanford");
|
||||
String templateString = "My name is ${name} and I am a student at the ${college}.";
|
||||
StrSubstitutor sub = new StrSubstitutor(substitutes);
|
||||
String result = sub.replace(templateString);
|
||||
|
||||
Assert.assertEquals("My name is John and I am a student at the University of Stanford.", result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.baeldung.text;
|
||||
|
||||
import org.apache.commons.text.translate.UnicodeEscaper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class UnicodeEscaperTest {
|
||||
|
||||
@Test
|
||||
public void whenTranslate_thenCorrect() {
|
||||
UnicodeEscaper ue = UnicodeEscaper.above(0);
|
||||
String result = ue.translate("ABCD");
|
||||
|
||||
Assert.assertEquals("\\u0041\\u0042\\u0043\\u0044", result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.text;
|
||||
|
||||
import org.apache.commons.text.WordUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class WordUtilsTest {
|
||||
|
||||
@Test
|
||||
public void whenCapitalized_thenCorrect() {
|
||||
String toBeCapitalized = "to be capitalized!";
|
||||
String result = WordUtils.capitalize(toBeCapitalized);
|
||||
|
||||
Assert.assertEquals("To Be Capitalized!", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenContainsWords_thenCorrect() {
|
||||
boolean containsWords = WordUtils.containsAllWords("String to search", "to", "search");
|
||||
|
||||
Assert.assertTrue(containsWords);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user