From 4348af0f1ddbc1e7320c2226221c702a62e195c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D1=96=D1=81=D0=BE=D0=B2=D0=B8=D0=B9=20=D0=92=D1=96?= =?UTF-8?q?=D0=BA=D1=82=D0=BE=D1=80=20=D0=AE=D1=80=D1=96=D0=B9=D0=BE=D0=B2?= =?UTF-8?q?=D0=B8=D1=87?= Date: Tue, 3 Jan 2023 11:16:07 +0200 Subject: [PATCH] fixed work which resources --- .../exceptions/ConfigNotFoundException.java | 7 ---- .../java/transliteraion/Transliteration.java | 34 ++++++++++--------- .../main/resources/{ => links}/charChange.txt | 0 .../transliteraion/TransliterationTest.java | 12 +++---- .../test/resources/{ => links}/charChange.txt | 0 5 files changed, 22 insertions(+), 31 deletions(-) delete mode 100644 transliteraion/src/main/java/exceptions/ConfigNotFoundException.java rename transliteraion/src/main/resources/{ => links}/charChange.txt (100%) rename transliteraion/src/test/resources/{ => links}/charChange.txt (100%) diff --git a/transliteraion/src/main/java/exceptions/ConfigNotFoundException.java b/transliteraion/src/main/java/exceptions/ConfigNotFoundException.java deleted file mode 100644 index 6e5959e..0000000 --- a/transliteraion/src/main/java/exceptions/ConfigNotFoundException.java +++ /dev/null @@ -1,7 +0,0 @@ -package exceptions; - -public class ConfigNotFoundException extends RuntimeException { - public ConfigNotFoundException(String message) { - super(message); - } -} diff --git a/transliteraion/src/main/java/transliteraion/Transliteration.java b/transliteraion/src/main/java/transliteraion/Transliteration.java index 279eda2..7588ddf 100644 --- a/transliteraion/src/main/java/transliteraion/Transliteration.java +++ b/transliteraion/src/main/java/transliteraion/Transliteration.java @@ -1,12 +1,11 @@ package transliteraion; -import exceptions.ConfigNotFoundException; import exceptions.ErrorReadFileException; import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; @@ -30,6 +29,10 @@ private static String convertSymbol(final String symbol) { String result = symbol; + if (firstSymbol) { + result = symbol.substring(0, 1).toUpperCase() + lowSymbol.substring(1); + } + int n = masLinks.length; for (int i = 1; i < n; i++) { @@ -69,7 +72,7 @@ private static String convertSymbol(final Character symbol) { public static String convert(final String name, final String lastname) { readFile(); - String prepareLastName = lastname.replace(masLinks[0][0], masLinks[0][1]); + String prepareLastName = lastname.toLowerCase().replace(masLinks[0][0], masLinks[0][1]); StringBuilder resultLine = new StringBuilder(); @@ -80,7 +83,7 @@ public static String convert(final String name, final String lastname) { firstSymbol = false; - int n = lastname.length(); + int n = prepareLastName.length(); for (int i = 1; i < n; i++) { resultLine.append(convertSymbol(prepareLastName.charAt(i))); } @@ -89,24 +92,23 @@ public static String convert(final String name, final String lastname) { } private static void readFile() { - File file = new File("src/main/resources/charChange.txt"); - if (!file.exists() || !file.isFile()) { - throw new ConfigNotFoundException("File not found"); - } List list = new ArrayList<>(); - try (FileReader fr = new FileReader(file); - BufferedReader br = new BufferedReader(fr)) { + try (InputStream is = Transliteration.class.getResourceAsStream("/links/charChange.txt")) { + assert is != null; + try (InputStreamReader isr = new InputStreamReader(is); + BufferedReader br = new BufferedReader(isr)) { - String line = br.readLine(); + String line = br.readLine(); - while (line != null) { - list.add(line); + while (line != null) { + list.add(line); - line = br.readLine(); - } + line = br.readLine(); + } + } } catch (IOException e) { throw new ErrorReadFileException(e); } diff --git a/transliteraion/src/main/resources/charChange.txt b/transliteraion/src/main/resources/links/charChange.txt similarity index 100% rename from transliteraion/src/main/resources/charChange.txt rename to transliteraion/src/main/resources/links/charChange.txt diff --git a/transliteraion/src/test/java/transliteraion/TransliterationTest.java b/transliteraion/src/test/java/transliteraion/TransliterationTest.java index 96fa534..ee2b7d1 100644 --- a/transliteraion/src/test/java/transliteraion/TransliterationTest.java +++ b/transliteraion/src/test/java/transliteraion/TransliterationTest.java @@ -2,19 +2,12 @@ import org.junit.jupiter.api.Test; -import java.nio.file.Path; -import java.nio.file.Paths; - -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; class TransliterationTest { @Test void readFileTest() { - Path p = Paths.get("src/main/resources/charChange.txt"); - - assertEquals("charChange.txt", p.getFileName().toString()); - Transliteration.convert("Name", "LastName"); String[] actual = Transliteration.getMasLinks()[0]; @@ -87,5 +80,8 @@ void convertTest() { assertEquals("KKostiantyn", Transliteration.convert("K", "Костянтин")); assertEquals("ZZnamianka", Transliteration.convert("Z", "Знам'янка")); assertEquals("FFeodosiia", Transliteration.convert("F", "Феодосія")); + assertEquals("RRozghon", Transliteration.convert("R", "Розгон")); + assertEquals("ZZghorany", Transliteration.convert("Z", "Згорани")); + } } \ No newline at end of file diff --git a/transliteraion/src/test/resources/charChange.txt b/transliteraion/src/test/resources/links/charChange.txt similarity index 100% rename from transliteraion/src/test/resources/charChange.txt rename to transliteraion/src/test/resources/links/charChange.txt