StringTokenizerTest refactor (#1611)
* TokenizerRefactor * TokenizerRefactor * TokenizerRefactor
This commit is contained in:
committed by
maibin
parent
13a42ea281
commit
60c2edaaeb
@@ -1,47 +0,0 @@
|
||||
package com.baeldung.stringtokenizer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class ApplicationTest {
|
||||
|
||||
Application application = new Application();
|
||||
List<String> expectedTokensForString = new ArrayList<String>();
|
||||
List<String> expectedTokensForFile = new ArrayList<String>();
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
expectedTokensForString.add("Welcome");
|
||||
expectedTokensForString.add("to");
|
||||
expectedTokensForString.add("baeldung.com");
|
||||
|
||||
expectedTokensForFile.add("1");
|
||||
expectedTokensForFile.add("IND");
|
||||
expectedTokensForFile.add("India");
|
||||
expectedTokensForFile.add("2");
|
||||
expectedTokensForFile.add("MY");
|
||||
expectedTokensForFile.add("Malaysia");
|
||||
expectedTokensForFile.add("3");
|
||||
expectedTokensForFile.add("AU");
|
||||
expectedTokensForFile.add("Australia");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_thenGetListOfString() {
|
||||
String str = "Welcome,to,baeldung.com";
|
||||
List<String> actualTokens = application.getTokens(str);
|
||||
assertEquals(expectedTokensForString, actualTokens);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenFile_thenGetListOfString() {
|
||||
List<String> actualTokens = application.getTokensFromFile("data.csv", "|");
|
||||
assertEquals(expectedTokensForFile, actualTokens);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.baeldung.stringtokenizer;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TokenizerTest {
|
||||
|
||||
private final MyTokenizer myTokenizer = new MyTokenizer();
|
||||
private final List<String> expectedTokensForString = Arrays.asList("Welcome", "to", "baeldung.com");
|
||||
private final List<String> expectedTokensForFile = Arrays.asList("1", "IND", "India", "2", "MY", "Malaysia", "3", "AU", "Australia");
|
||||
|
||||
@Test
|
||||
public void givenString_thenGetListOfString() {
|
||||
String str = "Welcome,to,baeldung.com";
|
||||
List<String> actualTokens = myTokenizer.getTokens(str);
|
||||
assertEquals(expectedTokensForString, actualTokens);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenFile_thenGetListOfString() {
|
||||
List<String> actualTokens = myTokenizer.getTokensFromFile("data.csv", "|");
|
||||
assertEquals(expectedTokensForFile, actualTokens);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user