Skip to content

Commit

Permalink
Modify KanaConverterTest in backend to resolve sonar warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
kohei-s committed Nov 7, 2023
1 parent 6092d08 commit 4c011ac
Showing 1 changed file with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
package de.neuefische.koheis.backend.converter;

import com.ibm.icu.text.Transliterator;
import org.junit.Before;
import org.junit.Test;
import org.mockito.MockitoAnnotations;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.junit.jupiter.api.extension.ExtendWith;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.mockito.Mockito;

@ExtendWith(MockitoExtension.class)
class KanaConverterTest {

public class KanaConverterTest {
private KanaConverter kanaConverter;

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
@Mock
private Transliterator transliterator;

@BeforeEach
void setUp() {
kanaConverter = new KanaConverter();
}

@Test
public void testConvertHiraganaToAlphabet() {
void testConvertHiraganaToAlphabet() {
String hiragana = "ひらがな";
Transliterator trans = Transliterator.getInstance("Hiragana-Latin");
String expected = trans.transliterate(hiragana);
Mockito.lenient().when(transliterator.transliterate(hiragana)).thenReturn("hiragana");
String result = kanaConverter.convertHiraganaToAlphabet(hiragana);
assertEquals(expected, result);
assertEquals("hiragana", result);
}

@Test
public void testConvertKatakanaToAlphabet() {
void testConvertKatakanaToAlphabet() {
String katakana = "カタカナ";
Transliterator trans = Transliterator.getInstance("Katakana-Latin");
String expected = trans.transliterate(katakana);
Mockito.lenient().when(transliterator.transliterate(katakana)).thenReturn("katakana");
String result = kanaConverter.convertKatakanaToAlphabet(katakana);
assertEquals(expected, result);
assertEquals("katakana", result);
}
}

0 comments on commit 4c011ac

Please sign in to comment.