BAEL-972 - Apache Commons Text
This commit is contained in:
		
							parent
							
								
									ee8bf9f711
								
							
						
					
					
						commit
						94fc522f7f
					
				| @ -76,6 +76,11 @@ | |||||||
|             <artifactId>commons-lang3</artifactId> |             <artifactId>commons-lang3</artifactId> | ||||||
|             <version>${commons-lang.version}</version> |             <version>${commons-lang.version}</version> | ||||||
|         </dependency> |         </dependency> | ||||||
|  |         <dependency> | ||||||
|  |    			<groupId>org.apache.commons</groupId> | ||||||
|  |    			<artifactId>commons-text</artifactId> | ||||||
|  |    			<version>${commons-text.version}</version> | ||||||
|  | 		</dependency> | ||||||
|         <dependency> |         <dependency> | ||||||
|             <groupId>org.jasypt</groupId> |             <groupId>org.jasypt</groupId> | ||||||
|             <artifactId>jasypt</artifactId> |             <artifactId>jasypt</artifactId> | ||||||
| @ -292,6 +297,7 @@ | |||||||
|         <multiverse.version>0.7.0</multiverse.version> |         <multiverse.version>0.7.0</multiverse.version> | ||||||
|         <cglib.version>3.2.4</cglib.version> |         <cglib.version>3.2.4</cglib.version> | ||||||
|         <commons-lang.version>3.5</commons-lang.version> |         <commons-lang.version>3.5</commons-lang.version> | ||||||
|  |         <commons-text.version>1.1</commons-text.version> | ||||||
|         <jasypt.version>1.9.2</jasypt.version> |         <jasypt.version>1.9.2</jasypt.version> | ||||||
|         <javatuples.version>1.2</javatuples.version> |         <javatuples.version>1.2</javatuples.version> | ||||||
|         <javaassist.version>3.21.0-GA</javaassist.version> |         <javaassist.version>3.21.0-GA</javaassist.version> | ||||||
|  | |||||||
							
								
								
									
										18
									
								
								libraries/src/test/java/com/baeldung/text/DiffTest.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								libraries/src/test/java/com/baeldung/text/DiffTest.java
									
									
									
									
									
										Normal file
									
								
							| @ -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); | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										23
									
								
								libraries/src/test/java/com/baeldung/text/WordUtilsTest.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								libraries/src/test/java/com/baeldung/text/WordUtilsTest.java
									
									
									
									
									
										Normal file
									
								
							| @ -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); | ||||||
|  |     } | ||||||
|  | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user