diff --git a/src/main/java/io/github/brenoepics/at4j/util/logging/FallbackLoggerConfiguration.java b/src/main/java/io/github/brenoepics/at4j/util/logging/FallbackLoggerConfiguration.java index 5697708b..903301f5 100644 --- a/src/main/java/io/github/brenoepics/at4j/util/logging/FallbackLoggerConfiguration.java +++ b/src/main/java/io/github/brenoepics/at4j/util/logging/FallbackLoggerConfiguration.java @@ -9,7 +9,8 @@ public class FallbackLoggerConfiguration { private static final AtomicBoolean trace = new AtomicBoolean(); - private FallbackLoggerConfiguration() { + /** This class should not be instantiated. */ + FallbackLoggerConfiguration() { throw new UnsupportedOperationException(); } diff --git a/src/test/java/io/github/brenoepics/at4j/core/exceptions/AzureExceptionTest.java b/src/test/java/io/github/brenoepics/at4j/core/exceptions/AzureExceptionTest.java index 403c3b6b..b4bf0a7c 100644 --- a/src/test/java/io/github/brenoepics/at4j/core/exceptions/AzureExceptionTest.java +++ b/src/test/java/io/github/brenoepics/at4j/core/exceptions/AzureExceptionTest.java @@ -14,8 +14,8 @@ import java.util.HashMap; import java.util.Optional; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertTrue; class AzureExceptionTest { diff --git a/src/test/java/io/github/brenoepics/at4j/data/DetectedLanguageTest.java b/src/test/java/io/github/brenoepics/at4j/data/DetectedLanguageTest.java index 949c95f9..bf4b933a 100644 --- a/src/test/java/io/github/brenoepics/at4j/data/DetectedLanguageTest.java +++ b/src/test/java/io/github/brenoepics/at4j/data/DetectedLanguageTest.java @@ -24,6 +24,18 @@ void ofJSON_withValidJson_returnsDetectedLanguage() throws JsonProcessingExcepti assertFalse(detectedLanguage.isTransliterationSupported()); } + @Test + void ofJSON_withInvalidLangJson_returnsNull() throws JsonProcessingException { + String json = + "{\"score\":0.9,\"isTranslationSupported\":true,\"isTransliterationSupported\":false}"; + ObjectMapper mapper = new ObjectMapper(); + ObjectNode jsonNode = mapper.convertValue(mapper.readTree(json), ObjectNode.class); + + DetectedLanguage detectedLanguage = DetectedLanguage.ofJSON(jsonNode); + + assertNull(detectedLanguage); + } + @Test void ofJSON_withMissingFields_returnsDetectedLanguageWithDefaults() throws JsonProcessingException { diff --git a/src/test/java/io/github/brenoepics/at4j/data/TranslationTest.java b/src/test/java/io/github/brenoepics/at4j/data/TranslationTest.java new file mode 100644 index 00000000..89047e04 --- /dev/null +++ b/src/test/java/io/github/brenoepics/at4j/data/TranslationTest.java @@ -0,0 +1,49 @@ +package io.github.brenoepics.at4j.data; + +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class TranslationTest { + + @Test + void from_createsTranslationWithGivenParameters() { + Translation translation = Translation.from("en", "Hello"); + + assertEquals("en", translation.getLanguageCode()); + assertEquals("Hello", translation.getText()); + } + + @Test + void ofJSON_createsTranslationFromValidNode() { + ObjectNode node = JsonNodeFactory.instance.objectNode(); + node.put("to", "en"); + node.put("text", "Hello"); + + Translation translation = Translation.ofJSON(node); + + assertNotNull(translation); + assertEquals("en", translation.getLanguageCode()); + assertEquals("Hello", translation.getText()); + } + + @Test + void ofJSON_returnsNullForInvalidNode() { + ObjectNode node = JsonNodeFactory.instance.objectNode(); + node.put("invalid", "data"); + + Translation translation = Translation.ofJSON(node); + + assertNull(translation); + } + + @Test + void toString_returnsCorrectFormat() { + Translation translation = Translation.from("en", "Hello"); + + String expected = "Translation{key='en', value='Hello'}"; + assertEquals(expected, translation.toString()); + } +} \ No newline at end of file diff --git a/src/test/java/io/github/brenoepics/at4j/util/logging/FallbackLoggerConfigurationTest.java b/src/test/java/io/github/brenoepics/at4j/util/logging/FallbackLoggerConfigurationTest.java index a7f93d8a..db4745df 100644 --- a/src/test/java/io/github/brenoepics/at4j/util/logging/FallbackLoggerConfigurationTest.java +++ b/src/test/java/io/github/brenoepics/at4j/util/logging/FallbackLoggerConfigurationTest.java @@ -6,6 +6,10 @@ class FallbackLoggerConfigurationTest { + @Test + void invokingConstructorThrowsException() { + assertThrows(UnsupportedOperationException.class, FallbackLoggerConfiguration::new); + } @Test void debugInitiallyEnabled() { assertTrue(FallbackLoggerConfiguration.isDebugEnabled()); diff --git a/src/test/java/io/github/brenoepics/at4j/util/rest/RestRequestResultErrorCodeTest.java b/src/test/java/io/github/brenoepics/at4j/util/rest/RestRequestResultErrorCodeTest.java index 1e4de7b9..1f86ba72 100644 --- a/src/test/java/io/github/brenoepics/at4j/util/rest/RestRequestResultErrorCodeTest.java +++ b/src/test/java/io/github/brenoepics/at4j/util/rest/RestRequestResultErrorCodeTest.java @@ -1,7 +1,14 @@ package io.github.brenoepics.at4j.util.rest; +import com.google.common.collect.Multimaps; +import io.github.brenoepics.at4j.AzureApi; +import io.github.brenoepics.at4j.AzureApiBuilder; +import io.github.brenoepics.at4j.core.exceptions.AzureException; +import okhttp3.Protocol; +import okhttp3.Response; import org.junit.jupiter.api.Test; +import java.io.IOException; import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -9,7 +16,7 @@ import static org.junit.jupiter.api.Assertions.*; -class RestRequestResultErrorCodeTest { +class RestRequestResultErrorCodeTest { @Test void test_all_enum_values() {