diff --git a/.gitignore b/.gitignore
index a1c2a23..60b4fc1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -21,3 +21,9 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
+
+# IntelliJ configuration
+.idea/
+
+# Maven build directory
+target/
diff --git a/pom.xml b/pom.xml
index 7365645..12bf806 100644
--- a/pom.xml
+++ b/pom.xml
@@ -12,12 +12,13 @@
spring-boot-starter-parent
2.3.3.RELEASE
-
-
+
+
pl.put.poznan
transformer
- 0.2.0-SNAPSHOT
-
+ 0.3.0-SNAPSHOT
+
+
github
@@ -26,10 +27,11 @@
+
11
-
+
@@ -48,12 +50,20 @@
-
+
com.jayway.jsonpath
json-path
test
+
+
+ com.google.guava
+ guava
+ 31.0.1-jre
+
+
+
@@ -64,11 +74,13 @@
maven-site-plugin
3.9.1
+
org.apache.maven.plugins
maven-project-info-reports-plugin
3.1.2
+
org.apache.maven.plugins
maven-javadoc-plugin
@@ -82,13 +94,14 @@
+
org.springframework.boot
spring-boot-maven-plugin
-
+
@@ -96,8 +109,8 @@
https://repo.spring.io/libs-release
-
-
+
+
spring-releases
diff --git a/src/main/java/pl/put/poznan/transformer/logic/Capitalize.java b/src/main/java/pl/put/poznan/transformer/logic/Capitalize.java
index ae80bbc..536f623 100644
--- a/src/main/java/pl/put/poznan/transformer/logic/Capitalize.java
+++ b/src/main/java/pl/put/poznan/transformer/logic/Capitalize.java
@@ -6,10 +6,21 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;
+/**
+ * Part of the decorator pattern.
+ * This class makes it possible to convert the result of other text transformations
+ * by changing first letters of every word to uppercase.
+ */
public class Capitalize extends TextDecorator {
+ /**
+ * @see TextDecorator#TextDecorator
+ */
public Capitalize(Transformer t) { super(t); }
+ /**
+ * Returns the result of the conversion.
+ */
@Override
public String GetText() {
String [] words = super.GetText().split("(?<=\\s)(?=\\S)");
diff --git a/src/main/java/pl/put/poznan/transformer/logic/FindInDictionary.java b/src/main/java/pl/put/poznan/transformer/logic/FindInDictionary.java
new file mode 100644
index 0000000..01a36a6
--- /dev/null
+++ b/src/main/java/pl/put/poznan/transformer/logic/FindInDictionary.java
@@ -0,0 +1,71 @@
+package pl.put.poznan.transformer.logic;
+
+import com.google.common.collect.BiMap;
+import com.google.common.collect.HashBiMap;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+public class FindInDictionary {
+ private final BiMap dictionary = HashBiMap.create();
+
+ private void load(){
+ String fileName = "src/main/resources/dictionary.csv";
+ Path pathToFile = Paths.get(fileName);
+ String line;
+ String[] elements;
+
+ try(BufferedReader reader = Files.newBufferedReader(pathToFile)){
+ line = reader.readLine();
+
+ while(line != null){
+ elements = line.split(",");
+ dictionary.put(elements[0], elements[1]);
+ line = reader.readLine();
+ }
+
+ } catch (IOException ioException){
+ ioException.printStackTrace();
+ }
+ }
+
+ public String findWordAndReplace(String shortcut){
+ String result = shortcut;
+ if(dictionary.containsKey(shortcut)){
+ result = dictionary.get(shortcut);
+ }
+ return result;
+ }
+
+ public String findShortcutAndReplace(String word){
+ String result = word;
+ if(dictionary.inverse().containsKey(word)){
+ result = dictionary.inverse().get(word);
+ }
+ return result;
+ }
+
+ public String getWord(String shortcut){
+ return dictionary.get(shortcut);
+ }
+
+ public String getShortcut(String word){
+ return dictionary.inverse().get(word);
+ }
+
+ public String[] getListOfShortcuts(){
+ return dictionary.keySet().toArray(new String[0]);
+ }
+
+ public String[] getListOfWords(){
+ return dictionary.inverse().keySet().toArray(new String[0]);
+ }
+
+ public FindInDictionary(){
+ this.load();
+ }
+
+}
diff --git a/src/main/java/pl/put/poznan/transformer/logic/Invert.java b/src/main/java/pl/put/poznan/transformer/logic/Invert.java
new file mode 100644
index 0000000..616ab2a
--- /dev/null
+++ b/src/main/java/pl/put/poznan/transformer/logic/Invert.java
@@ -0,0 +1,62 @@
+package pl.put.poznan.transformer.logic;
+
+import static java.lang.Character.isUpperCase;
+import static java.lang.Character.toUpperCase;
+
+public class Invert extends TextDecorator{
+
+ public Boolean[] findUpperLetters(String text){
+ Boolean[] upperLettersPositions = new Boolean[text.length()];
+
+ for(int i=0; i=0; i--){
+ result.append(text.charAt(i));
+ }
+
+ return result.toString();
+ }
+
+ private String reverse(String text){
+ String result;
+
+ result = text.toLowerCase();
+ result = changeOrder(result);
+ result = makeLettersGreatAgain(result,findUpperLetters(text));
+
+ return result;
+ }
+
+ public Invert(Transformer t){
+ super(t);
+ }
+
+ @Override
+ public String GetText() {
+ return reverse(super.GetText());
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/pl/put/poznan/transformer/logic/ReplaceFullWords.java b/src/main/java/pl/put/poznan/transformer/logic/ReplaceFullWords.java
new file mode 100644
index 0000000..89115fe
--- /dev/null
+++ b/src/main/java/pl/put/poznan/transformer/logic/ReplaceFullWords.java
@@ -0,0 +1,27 @@
+package pl.put.poznan.transformer.logic;
+
+import static pl.put.poznan.transformer.logic.TextTransformer.dictionary;
+
+public class ReplaceFullWords extends TextDecorator {
+
+
+ private String replace(String text){
+
+ String[] keySet = dictionary.getListOfWords();
+
+ for(String word : keySet){
+ if(text.contains(word)) {
+ text = text.replaceAll(word, dictionary.getShortcut(word));
+ }
+ }
+
+ return text;
+ }
+
+ public ReplaceFullWords(Transformer t) {super(t);}
+
+ @Override
+ public String GetText(){
+ return replace(super.GetText());
+ }
+}
diff --git a/src/main/java/pl/put/poznan/transformer/logic/ReplaceNumbers.java b/src/main/java/pl/put/poznan/transformer/logic/ReplaceNumbers.java
new file mode 100644
index 0000000..6ed1ab3
--- /dev/null
+++ b/src/main/java/pl/put/poznan/transformer/logic/ReplaceNumbers.java
@@ -0,0 +1,169 @@
+package pl.put.poznan.transformer.logic;
+import java.util.HashMap;
+
+
+import java.util.Objects;
+
+public class ReplaceNumbers extends TextDecorator {
+
+ private HashMap numbers = new HashMap();
+
+ private SplitToWords splitClass;
+
+ public ReplaceNumbers(Transformer t) {
+ super(t);
+ load();
+ splitClass = new SplitToWords();
+ }
+
+ private boolean isNumber(String s) {
+ return s.matches("-?\\d+(\\,\\d+)?");
+ }
+
+ private String toStr(String s, boolean zero) {
+ String[] ns = s.split("");
+ String result = "";
+ boolean isZero = true;
+
+ for (int i = ns.length-1; i>=0; i--) {
+ if(i==1){
+ if(Objects.equals(ns[ns.length - 1 - i], "1")) {
+ String search = ns[ns.length-1-i] + ns[ns.length-1-i+1];
+ isZero = false;
+ result += numbers.get(search) + " ";
+ i--;
+ }
+ else {
+ if (Objects.equals(ns[ns.length - 1 - i], "0")) {
+ if (zero && isZero) {
+ result += "zero ";
+ }
+ }
+ else {
+ String search = ns[ns.length-1-i] +"0".repeat(i);
+ isZero = false;
+ result += numbers.get(search) + " ";
+ }
+
+ }
+ }
+ else if (i==0) {
+ if (Objects.equals(ns[ns.length - 1 - i], "0")) {
+ if (isZero) {
+ result += "zero";
+ }
+ }
+ else {
+ String search = ns[ns.length-1-i] +"0".repeat(i);
+ isZero = false;
+ result += numbers.get(search);
+ }
+
+
+ }
+ else {
+ if (Objects.equals(ns[ns.length - 1 - i], "0")) {
+ if (isZero && zero) {
+ result += "zero ";
+ }
+ }
+ else {
+ String search = ns[ns.length-1-i] +"0".repeat(i);
+ isZero = false;
+ result += numbers.get(search) + " ";
+ }
+
+ }
+ }
+
+ return result.trim();
+ }
+
+ @Override
+ public String GetText() {
+ String[] tab = splitClass.split(super.GetText());
+ String newString = "";
+
+
+ for (String s : tab) {
+ if (isNumber(s)) {
+ String[] minusString = s.split("-");
+ String afMinString = null;
+ if(minusString.length == 2) {
+ newString += "minus ";
+ afMinString = minusString[1];
+ }
+ else {
+ afMinString = minusString[0];
+ }
+
+ String[] comma = afMinString.split(",");
+
+ newString += toStr(comma[0], false);
+ if(comma.length == 2) {
+ newString += " i ";
+ newString += toStr(comma[1], true);
+ if(comma[1].length() == 1) {
+ newString += " dziesiątych";
+ }
+ else if (comma[1].length() == 2) {
+ newString += " setnych";
+ }
+ else {
+ newString += " tysięcznych";
+ }
+ }
+ newString += " ";
+
+ } else {
+ newString += s + " ";
+ }
+ }
+
+ newString = newString.substring(0, newString.length() - 1);
+ //return newString.trim();
+ return newString;
+ }
+
+ private void load() {
+ numbers.put("0", "zero");
+ numbers.put("1", "jeden");
+ numbers.put("2", "dwa");
+ numbers.put("3", "trzy");
+ numbers.put("4", "cztery");
+ numbers.put("5", "pięć");
+ numbers.put("6", "sześć");
+ numbers.put("7", "siedem");
+ numbers.put("8", "osiem");
+ numbers.put("9", "dziewięć");
+ numbers.put("10", "dziesięć");
+ numbers.put("11", "jedenaście");
+ numbers.put("12", "dwanaście");
+ numbers.put("13", "trzynaście");
+ numbers.put("14", "czternaście");
+ numbers.put("15", "piętnaście");
+ numbers.put("16", "szesnaście");
+ numbers.put("17", "siedemnaście");
+ numbers.put("18", "osiemnaście");
+ numbers.put("19", "dziewiętnaście");
+ numbers.put("20", "dwadzieścia");
+ numbers.put("30", "trzydzieści");
+ numbers.put("40", "czterdzieści");
+ numbers.put("50", "pięćdziesiąt");
+ numbers.put("60", "sześćdziesiąt");
+ numbers.put("70", "siedemdziesiąt");
+ numbers.put("80", "osiemdziesiąt");
+ numbers.put("90", "dziewięćdziesiąt");
+ numbers.put("100", "sto");
+ numbers.put("200", "dwieście");
+ numbers.put("300", "trzysta");
+ numbers.put("400", "czterysta");
+ numbers.put("500", "pięćset");
+ numbers.put("600", "sześćset");
+ numbers.put("700", "siedemset");
+ numbers.put("800", "osiemset");
+ numbers.put("900", "dziewięćset");
+ numbers.put("1000", "tysiąc");
+
+ }
+}
diff --git a/src/main/java/pl/put/poznan/transformer/logic/ReplaceShortcuts.java b/src/main/java/pl/put/poznan/transformer/logic/ReplaceShortcuts.java
new file mode 100644
index 0000000..297fd62
--- /dev/null
+++ b/src/main/java/pl/put/poznan/transformer/logic/ReplaceShortcuts.java
@@ -0,0 +1,29 @@
+package pl.put.poznan.transformer.logic;
+
+import static pl.put.poznan.transformer.logic.TextTransformer.dictionary;
+import static pl.put.poznan.transformer.logic.TextTransformer.splitter;
+
+public class ReplaceShortcuts extends TextDecorator{
+
+ private String replace(String text){
+
+ String result;
+
+ String [] words = splitter.split(text);
+
+ for(int i = 0; i< words.length; i++){
+ words[i] = dictionary.findWordAndReplace(words[i]);
+ }
+
+ result = splitter.mergeToText(words);
+
+ return result;
+ }
+
+ public ReplaceShortcuts(Transformer t) {super(t);}
+
+ @Override
+ public String GetText(){
+ return replace(super.GetText());
+ }
+}
diff --git a/src/main/java/pl/put/poznan/transformer/logic/SplitToWords.java b/src/main/java/pl/put/poznan/transformer/logic/SplitToWords.java
new file mode 100644
index 0000000..c18fc93
--- /dev/null
+++ b/src/main/java/pl/put/poznan/transformer/logic/SplitToWords.java
@@ -0,0 +1,28 @@
+package pl.put.poznan.transformer.logic;
+
+import java.util.List;
+
+public class SplitToWords {
+
+ public String[] split(String text){
+
+ String[] result;
+
+ List list = List.of(text.split(" "));
+
+ //TODO - Detection and handling of punctuation marks
+
+ result = list.toArray(new String[0]);
+ return result;
+ }
+
+ public String mergeToText(String [] words){
+ StringBuilder result = new StringBuilder();
+ for(int i=0; iString modifiers,
+ * while preserving their execution order.
+ */
+public abstract class TextDecorator implements Transformer {
+
+ /**
+ * String
modifier, holder, or generator
+ */
protected Transformer transformer;
+ /**
+ * Prepends a given {@link Transformer} object to the execution order.
+ *
+ * @param t String
modifier, holder, or generator
+ */
protected TextDecorator(Transformer t){
this.transformer = t;
}
- @Override
+ /**
+ * By default, returns String
from nested {@link Transformer} object.
+ * This method should be overridden and then called using super.GetText()
,
+ * to apply additional String
modifications.
+ */
public String GetText() {
return transformer.GetText();
}
diff --git a/src/main/java/pl/put/poznan/transformer/logic/TextHolder.java b/src/main/java/pl/put/poznan/transformer/logic/TextHolder.java
index 2caae15..2095d90 100644
--- a/src/main/java/pl/put/poznan/transformer/logic/TextHolder.java
+++ b/src/main/java/pl/put/poznan/transformer/logic/TextHolder.java
@@ -1,13 +1,28 @@
package pl.put.poznan.transformer.logic;
+/**
+ * Part of the decorator pattern.
+ * This class is a storage container for a String
object.
+ */
public class TextHolder implements Transformer {
- private String InputText = null;
+ /**
+ * stored String
+ */
+ private final String InputText;
+ /**
+ * Wraps given String
in a new {@link TextHolder} object.
+ *
+ * @param text stored String
+ */
public TextHolder(String text) {
this.InputText = text;
}
+ /**
+ * Returns String
stored in {@link TextHolder#InputText}.
+ */
public String GetText() {
return this.InputText;
}
diff --git a/src/main/java/pl/put/poznan/transformer/logic/TextTransformer.java b/src/main/java/pl/put/poznan/transformer/logic/TextTransformer.java
index 3a05da8..23fa1e2 100644
--- a/src/main/java/pl/put/poznan/transformer/logic/TextTransformer.java
+++ b/src/main/java/pl/put/poznan/transformer/logic/TextTransformer.java
@@ -17,7 +17,7 @@
*/
public class TextTransformer {
/**
- * Valid transform names
+ * valid transform names
*/
private final String[] transforms;
@@ -30,8 +30,11 @@ public TextTransformer(String[] transforms){
this.transforms = transforms;
}
+ public static final FindInDictionary dictionary = new FindInDictionary();
+ public static final SplitToWords splitter = new SplitToWords();
+
/**
- * Applies transforms defined in {@link TextTransformer#transforms} to a given String
+ * Applies transforms defined in {@link TextTransformer#transforms} attribute on a given String
*
* @param text text scheduled for transformation
* @return transformed text
@@ -52,12 +55,16 @@ public String transform(String text){
resultTransformer = new Capitalize(resultTransformer);
break;
case "Invert":
+ resultTransformer = new Invert(resultTransformer);
break;
case "ReplaceNumbers":
+ resultTransformer = new ReplaceNumbers(resultTransformer);
break;
case "ReplaceShortcuts":
+ resultTransformer = new ReplaceShortcuts(resultTransformer);
break;
case "ReplaceFullWords":
+ resultTransformer = new ReplaceFullWords(resultTransformer);
break;
}
}
diff --git a/src/main/java/pl/put/poznan/transformer/logic/ToLower.java b/src/main/java/pl/put/poznan/transformer/logic/ToLower.java
index 99a0e57..5cdf534 100644
--- a/src/main/java/pl/put/poznan/transformer/logic/ToLower.java
+++ b/src/main/java/pl/put/poznan/transformer/logic/ToLower.java
@@ -2,12 +2,22 @@
import java.util.Locale;
+/**
+ * Part of the decorator pattern.
+ * This class makes it possible to convert the result of other text transformations to lowercase letters only.
+ */
public class ToLower extends TextDecorator {
+ /**
+ * @see TextDecorator#TextDecorator
+ */
public ToLower(Transformer t) {
super(t);
}
+ /**
+ * Returns the result of the lowercase conversion.
+ */
@Override
public String GetText() {
return super.GetText().toLowerCase(Locale.ENGLISH);
diff --git a/src/main/java/pl/put/poznan/transformer/logic/ToUpper.java b/src/main/java/pl/put/poznan/transformer/logic/ToUpper.java
index a1b5a08..e6fb5a4 100644
--- a/src/main/java/pl/put/poznan/transformer/logic/ToUpper.java
+++ b/src/main/java/pl/put/poznan/transformer/logic/ToUpper.java
@@ -2,10 +2,20 @@
import java.util.Locale;
+/**
+ * Part of the decorator pattern.
+ * This class makes it possible to convert the result of other text transformations to uppercase letters only.
+ */
public class ToUpper extends TextDecorator {
+ /**
+ * @see TextDecorator#TextDecorator
+ */
public ToUpper(Transformer t) { super(t); }
+ /**
+ * Returns the result of the uppercase conversion.
+ */
@Override
public String GetText() {
return super.GetText().toUpperCase(Locale.ENGLISH);
diff --git a/src/main/java/pl/put/poznan/transformer/logic/Transformer.java b/src/main/java/pl/put/poznan/transformer/logic/Transformer.java
index d717a4f..549a71c 100644
--- a/src/main/java/pl/put/poznan/transformer/logic/Transformer.java
+++ b/src/main/java/pl/put/poznan/transformer/logic/Transformer.java
@@ -1,5 +1,13 @@
package pl.put.poznan.transformer.logic;
+/**
+ * Part of the decorator pattern.
+ * This interface makes it possible to apply various modifications on Strings
.
+ */
public interface Transformer {
- public String GetText();
+
+ /**
+ * Implementors should return a result of their operations with this method.
+ */
+ String GetText();
}
diff --git a/src/main/resources/dictionary.csv b/src/main/resources/dictionary.csv
new file mode 100644
index 0000000..36683b6
--- /dev/null
+++ b/src/main/resources/dictionary.csv
@@ -0,0 +1,6 @@
+itd.,i tak dalej
+itp.,i tym podobne
+m.in.,między innymi
+prof.,profesor
+dr,doktor
+np.,na przykład
\ No newline at end of file
diff --git a/src/test/java/pl/put/poznan/transformer/logic/FindInDictionaryTest.java b/src/test/java/pl/put/poznan/transformer/logic/FindInDictionaryTest.java
new file mode 100644
index 0000000..867b288
--- /dev/null
+++ b/src/test/java/pl/put/poznan/transformer/logic/FindInDictionaryTest.java
@@ -0,0 +1,23 @@
+package pl.put.poznan.transformer.logic;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class FindInDictionaryTest {
+
+ @Test
+ void testFindInDictionary_ShortcutToWord_expectingSuccess(){
+ FindInDictionary dictionary = new FindInDictionary();
+ String shortcut = "itd.";
+ assertEquals(dictionary.findWordAndReplace(shortcut), "i tak dalej");
+ }
+
+ @Test
+ void testFindInDictionary_WordToShortcut_expectingSuccess(){
+ FindInDictionary dictionary = new FindInDictionary();
+ String word = "i tym podobne";
+ assertEquals(dictionary.findShortcutAndReplace(word), "itp.");
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/java/pl/put/poznan/transformer/logic/InvertTest.java b/src/test/java/pl/put/poznan/transformer/logic/InvertTest.java
new file mode 100644
index 0000000..39b208f
--- /dev/null
+++ b/src/test/java/pl/put/poznan/transformer/logic/InvertTest.java
@@ -0,0 +1,55 @@
+package pl.put.poznan.transformer.logic;
+
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.*;
+
+public class InvertTest{
+ private String text="MOIm zDAniEm to NIE ma TaK, że doBRZe albo że nie DOBrze!";
+
+ @Test
+ void testInvert_findUpperLettersPositions_expectingSuccess(){
+ Transformer mock = mock(Transformer.class);
+ Invert invert= new Invert(mock);
+
+ Boolean[] result;
+ result = invert.findUpperLetters(text);
+
+ StringBuilder resultString = new StringBuilder();
+ for(int i=0; i<57;i++){
+ resultString.append(result[i].toString());
+ resultString.append(",");
+ }
+
+ assertEquals(resultString.toString(), "true,true,true,false,false,false,true,true,false,false," +
+ "true,false,false,false,false,false,true,true,true,false,false,false,false,true,false,true," +
+ "false,false,false,false,false,false,false,true,true,true,false,false,false,false,false,false," +
+ "false,false,false,false,false,false,false,false,true,true,true,false,false,false,false,");
+ }
+
+ @Test
+ void testInvert_expectingSuccess(){
+ Transformer mock = mock(Transformer.class);
+ Invert invert= new Invert(mock);
+
+ when(mock.GetText()).thenReturn(text);
+
+ String result = invert.GetText();
+
+ assertEquals(result, "!EZrboD eiN eż oBLA ezrBoD eż ,kaT Am ein ot meinaDZ miom");
+ }
+
+ @Test
+ void testInvert_caseFromBacklog_expectingSuccess(){
+ Transformer mock = mock(Transformer.class);
+ Invert invert= new Invert(mock);
+
+ when(mock.GetText()).thenReturn("MirEk");
+
+ String result = invert.GetText();
+
+ assertEquals(result, "KerIm");
+ }
+}
diff --git a/src/test/java/pl/put/poznan/transformer/logic/ReplaceNumbersTest.java b/src/test/java/pl/put/poznan/transformer/logic/ReplaceNumbersTest.java
new file mode 100644
index 0000000..0e0b628
--- /dev/null
+++ b/src/test/java/pl/put/poznan/transformer/logic/ReplaceNumbersTest.java
@@ -0,0 +1,16 @@
+package pl.put.poznan.transformer.logic;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class ReplaceNumbersTest {
+
+ @Test
+ void getText() {
+ String test = "Po -5,25 zł";
+ TextTransformer transformer = new TextTransformer(new String[]{"ReplaceNumbers"});
+ String result = transformer.transform(test);
+ assertEquals("Po minus pięć i dwadzieścia pięć setnych zł",result);
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/pl/put/poznan/transformer/logic/ReplaceShortcutsAndWordsTest.java b/src/test/java/pl/put/poznan/transformer/logic/ReplaceShortcutsAndWordsTest.java
new file mode 100644
index 0000000..fe67ee0
--- /dev/null
+++ b/src/test/java/pl/put/poznan/transformer/logic/ReplaceShortcutsAndWordsTest.java
@@ -0,0 +1,34 @@
+package pl.put.poznan.transformer.logic;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class ReplaceShortcutsAndWordsTest {
+
+ @Test
+ void replaceShortcutsTest_noPunctuationMarks(){
+ Transformer mock = mock(Transformer.class);
+ ReplaceShortcuts replacer = new ReplaceShortcuts(mock);
+
+ String text = "Siała prof. baba m.in. mak itp. nie wiedziała jak a dziad wiedział nie powiedział itd. a to było tak";
+ when(mock.GetText()).thenReturn(text);
+
+ String result = replacer.GetText();
+ assertEquals(result, "Siała profesor baba między innymi mak i tym podobne nie wiedziała jak a dziad wiedział nie powiedział i tak dalej a to było tak");
+ }
+
+ @Test
+ void replaceWordsTest_noPunctuationMarks(){
+ Transformer mock = mock(Transformer.class);
+ ReplaceFullWords replacer = new ReplaceFullWords(mock);
+
+ String text = "Siała doktor baba na przykład mak i tym podobne nie wiedziała jak a dziad wiedział nie powiedział i tak dalej a to było tak";
+ when(mock.GetText()).thenReturn(text);
+
+ String result = replacer.GetText();
+ assertEquals(result, "Siała dr baba np. mak itp. nie wiedziała jak a dziad wiedział nie powiedział itd. a to było tak");
+ }
+}
diff --git a/src/test/java/pl/put/poznan/transformer/logic/SplitToWordsTest.java b/src/test/java/pl/put/poznan/transformer/logic/SplitToWordsTest.java
new file mode 100644
index 0000000..a277fea
--- /dev/null
+++ b/src/test/java/pl/put/poznan/transformer/logic/SplitToWordsTest.java
@@ -0,0 +1,40 @@
+package pl.put.poznan.transformer.logic;
+
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.Mockito.*;
+
+public class SplitToWordsTest {
+ private String text;
+ private SplitToWords splitter;
+ private String[] result;
+
+ @Test
+ void testSplitToWords_splitWithoutPunctuationMarks_ExpectingSuccess(){
+ text = "Siała baba mak nie wiedziała jak a dziad wiedział nie powiedział a to było tak";
+ splitter = new SplitToWords();
+
+ result = splitter.split(text);
+ String[] actual = {"Siała", "baba", "mak" , "nie", "wiedziała", "jak", "a", "dziad",
+ "wiedział", "nie", "powiedział","a", "to", "było", "tak"};
+
+ assertArrayEquals(result, actual);
+ }
+
+ /*@Test
+ void testSplitToWords_splitWithPunctuationMarks_ExpectingSuccess(){
+ text = "Siała baba mak, nie wiedziała jak, a dziad wiedział, nie powiedział, a to było tak!";
+ splitter = new SplitToWords();
+
+ result = splitter.split(text);
+ String[] actual = {"Siała", "baba", "mak" , ",", "nie", "wiedziała", "jak", ",", "a", "dziad",
+ "wiedział", ",", "nie", "powiedział", ",", "a", "to", "było", "tak"};
+
+ assertArrayEquals(result, actual);
+ }*/
+}
diff --git a/src/test/java/pl/put/poznan/transformer/logic/TextTransformerTest.java b/src/test/java/pl/put/poznan/transformer/logic/TextTransformerTest.java
index 9c9d631..5a435a5 100644
--- a/src/test/java/pl/put/poznan/transformer/logic/TextTransformerTest.java
+++ b/src/test/java/pl/put/poznan/transformer/logic/TextTransformerTest.java
@@ -35,4 +35,37 @@ void testTransform_noTransformationGiven_ExpectingUneditedInput() {
assertEquals(result, "MOIm zDAniEm to NIE ma TaK, że doBRZe albo że nie DOBrze!");
}
+
+ @Test
+ void testTransform_invertGiven_ExpectingSuccess() {
+ String[] transforms = {"Invert"};
+ transformer = new TextTransformer(transforms);
+ String result = transformer.transform(text);
+
+ assertEquals(result, "!EZrboD eiN eż oBLA ezrBoD eż ,kaT Am ein ot meinaDZ miom");
+ }
+
+ @Test
+ void testTransform_replaceNumbers_ExpectingSuccess() {
+ String test = "Po -5,25 zł";
+ TextTransformer transformer = new TextTransformer(new String[]{"ReplaceNumbers"});
+ String result = transformer.transform(test);
+ assertEquals("Po minus pięć i dwadzieścia pięć setnych zł",result);
+ }
+
+ @Test
+ void testTransform_replaceNumbers_Zero_ExpectingSuccess() {
+ String test = "Po -005,25 zł";
+ TextTransformer transformer = new TextTransformer(new String[]{"ReplaceNumbers"});
+ String result = transformer.transform(test);
+ assertEquals("Po minus pięć i dwadzieścia pięć setnych zł",result);
+ }
+
+ @Test
+ void testTransform_replaceNumbers_ZeroEnd_ExpectingSuccess() {
+ String test = "Po -005,250 zł";
+ TextTransformer transformer = new TextTransformer(new String[]{"ReplaceNumbers"});
+ String result = transformer.transform(test);
+ assertEquals("Po minus pięć i dwieście pięćdziesiąt tysięcznych zł",result);
+ }
}
\ No newline at end of file
diff --git a/target/classes/application.properties b/target/classes/application.properties
deleted file mode 100644
index d9099cb..0000000
--- a/target/classes/application.properties
+++ /dev/null
@@ -1,2 +0,0 @@
-logging.level.root= WARN
-logging.level.pl.put.poznan.transformer= DEBUG
diff --git a/target/classes/pl/put/poznan/transformer/app/TextTransformerApplication.class b/target/classes/pl/put/poznan/transformer/app/TextTransformerApplication.class
deleted file mode 100644
index 1fe2c3b..0000000
Binary files a/target/classes/pl/put/poznan/transformer/app/TextTransformerApplication.class and /dev/null differ
diff --git a/target/classes/pl/put/poznan/transformer/logic/TextTransformer.class b/target/classes/pl/put/poznan/transformer/logic/TextTransformer.class
deleted file mode 100644
index 7a8dd56..0000000
Binary files a/target/classes/pl/put/poznan/transformer/logic/TextTransformer.class and /dev/null differ
diff --git a/target/classes/pl/put/poznan/transformer/rest/TextTransformerController.class b/target/classes/pl/put/poznan/transformer/rest/TextTransformerController.class
deleted file mode 100644
index 22d69e0..0000000
Binary files a/target/classes/pl/put/poznan/transformer/rest/TextTransformerController.class and /dev/null differ