Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brenoepics committed Jan 17, 2024
1 parent ec2e9a9 commit 76d0948
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
49 changes: 49 additions & 0 deletions src/test/java/io/github/brenoepics/at4j/data/TranslationTest.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

class FallbackLoggerConfigurationTest {

@Test
void invokingConstructorThrowsException() {
assertThrows(UnsupportedOperationException.class, FallbackLoggerConfiguration::new);
}
@Test
void debugInitiallyEnabled() {
assertTrue(FallbackLoggerConfiguration.isDebugEnabled());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
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;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.*;

class RestRequestResultErrorCodeTest {
class RestRequestResultErrorCodeTest<T> {

@Test
void test_all_enum_values() {
Expand Down

0 comments on commit 76d0948

Please sign in to comment.