From 8b062ec22a26c37c1ab8d20bdb9023bc9a779e0d Mon Sep 17 00:00:00 2001 From: BrenoEpic Date: Tue, 16 Jan 2024 02:28:27 -0300 Subject: [PATCH] Create TranslateParamsTest.java --- .../data/request/TranslateParamsTest.java | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 src/test/java/com/github/brenoepics/at4j/data/request/TranslateParamsTest.java diff --git a/src/test/java/com/github/brenoepics/at4j/data/request/TranslateParamsTest.java b/src/test/java/com/github/brenoepics/at4j/data/request/TranslateParamsTest.java new file mode 100644 index 0000000..e15ea8b --- /dev/null +++ b/src/test/java/com/github/brenoepics/at4j/data/request/TranslateParamsTest.java @@ -0,0 +1,102 @@ +package com.github.brenoepics.at4j.data.request; + +import com.github.brenoepics.at4j.data.request.optional.ProfanityAction; +import com.github.brenoepics.at4j.data.request.optional.ProfanityMarker; +import com.github.brenoepics.at4j.data.request.optional.TextType; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.*; + +class TranslateParamsTest { + + @Test + void shouldSetAndGetText() { + TranslateParams params = new TranslateParams("Hello", List.of("fr")); + params.setText("Bonjour"); + assertEquals("Bonjour", params.getText()); + } + + @Test + void shouldSetAndGetTextType() { + TranslateParams params = new TranslateParams("Hello", List.of("fr")); + params.setTextType(TextType.HTML); + assertEquals(TextType.HTML, params.getTextType()); + } + + @Test + void shouldSetAndGetProfanityAction() { + TranslateParams params = new TranslateParams("Hello", List.of("fr")); + params.setProfanityAction(ProfanityAction.MARKED); + assertEquals(ProfanityAction.MARKED, params.getProfanityAction()); + } + + @Test + void shouldSetAndGetProfanityMarker() { + TranslateParams params = new TranslateParams("Hello", List.of("fr")); + params.setProfanityMarker(ProfanityMarker.TAG); + assertEquals(ProfanityMarker.TAG, params.getProfanityMarker()); + } + + @Test + void shouldSetAndGetIncludeAlignment() { + TranslateParams params = new TranslateParams("Hello", List.of("fr")); + params.setIncludeAlignment(true); + assertTrue(params.getIncludeAlignment()); + } + + @Test + void shouldSetAndGetIncludeSentenceLength() { + TranslateParams params = new TranslateParams("Hello", List.of("fr")); + params.setIncludeSentenceLength(true); + assertTrue(params.getIncludeSentenceLength()); + } + + @Test + void shouldSetAndGetSourceLanguage() { + TranslateParams params = new TranslateParams("Hello", List.of("fr")); + params.setSourceLanguage("en"); + assertEquals("en", params.getSourceLanguage()); + } + + @Test + void shouldSetAndGetTargetLanguages() { + TranslateParams params = new TranslateParams("Hello", List.of("fr")); + params.setTargetLanguages("de", "it"); + assertTrue(params.getTargetLanguages().containsAll(Arrays.asList("de", "it"))); + } + + @Test + void shouldSetAndGetSuggestedFromLanguage() { + TranslateParams params = new TranslateParams("Hello", List.of("fr")); + params.setSuggestedFromLanguage("en"); + assertEquals("en", params.getSuggestedFromLanguage()); + } + + @Test + void shouldGetQueryParameters() { + TranslateParams params = new TranslateParams("Hello", List.of("fr")); + params.setSourceLanguage("en"); + params.setTextType(TextType.HTML); + params.setProfanityAction(ProfanityAction.MARKED); + params.setProfanityMarker(ProfanityMarker.TAG); + params.setIncludeAlignment(true); + params.setIncludeSentenceLength(true); + params.setSuggestedFromLanguage("en"); + + Map expectedParams = new HashMap<>(); + expectedParams.put("from", "en"); + expectedParams.put("textType", "html"); + expectedParams.put("profanityAction", "Marked"); + expectedParams.put("profanityMarker", "Tag"); + expectedParams.put("includeAlignment", "true"); + expectedParams.put("includeSentenceLength", "true"); + expectedParams.put("suggestedFrom", "en"); + + assertEquals(expectedParams, params.getQueryParameters()); + } +} \ No newline at end of file