Skip to content

Commit

Permalink
fixed work which resources
Browse files Browse the repository at this point in the history
  • Loading branch information
victorlissoviy committed Jan 3, 2023
1 parent b89df10 commit 4348af0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 31 deletions.

This file was deleted.

34 changes: 18 additions & 16 deletions transliteraion/src/main/java/transliteraion/Transliteration.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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++) {

Expand Down Expand Up @@ -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();

Expand All @@ -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)));
}
Expand All @@ -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<String> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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", "Згорани"));

}
}

0 comments on commit 4348af0

Please sign in to comment.