Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: format code with Google Java Format #47

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,58 +1,62 @@
package com.github.brenoepics.at4j.data;

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

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.junit.jupiter.api.Test;

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

class DetectedLanguageTest {

@Test
void ofJSON_withValidJson_returnsDetectedLanguage() throws JsonProcessingException {
String json = "{\"language\":\"en\",\"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);

assertEquals("en", detectedLanguage.getLanguageCode());
assertEquals(0.9, detectedLanguage.getScore(), 0.0001);
assertTrue(detectedLanguage.isTranslationSupported());
assertFalse(detectedLanguage.isTransliterationSupported());
}

@Test
void ofJSON_withMissingFields_returnsDetectedLanguageWithDefaults() throws JsonProcessingException {
String json = "{\"language\":\"en\",\"score\":0.9}";
ObjectMapper mapper = new ObjectMapper();
ObjectNode jsonNode = mapper.convertValue(mapper.readTree(json), ObjectNode.class);

DetectedLanguage detectedLanguage = DetectedLanguage.ofJSON(jsonNode);

assertEquals("en", detectedLanguage.getLanguageCode());
assertEquals(0.9, detectedLanguage.getScore(), 0.0001);
assertFalse(detectedLanguage.isTranslationSupported());
assertFalse(detectedLanguage.isTransliterationSupported());
}

@Test
void ofJSON_withInvalidJson_returnsNull() throws JsonProcessingException {
String json = "{\"invalid\":\"json\"}";
ObjectMapper mapper = new ObjectMapper();
ObjectNode jsonNode = mapper.convertValue(mapper.readTree(json), ObjectNode.class);

DetectedLanguage detectedLanguage = DetectedLanguage.ofJSON(jsonNode);

assertNull(detectedLanguage);
}

@Test
void toString_returnsCorrectFormat() {
DetectedLanguage detectedLanguage = new DetectedLanguage("en", 0.9f, true, false);

String expected = "DetectedLanguage{language='en', score=0.9, isTranslationSupported=true, isTransliterationSupported=false}";
assertEquals(expected, detectedLanguage.toString());
}
}
@Test
void ofJSON_withValidJson_returnsDetectedLanguage() throws JsonProcessingException {
String json =
"{\"language\":\"en\",\"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);

assertEquals("en", detectedLanguage.getLanguageCode());
assertEquals(0.9, detectedLanguage.getScore(), 0.0001);
assertTrue(detectedLanguage.isTranslationSupported());
assertFalse(detectedLanguage.isTransliterationSupported());
}

@Test
void ofJSON_withMissingFields_returnsDetectedLanguageWithDefaults()
throws JsonProcessingException {
String json = "{\"language\":\"en\",\"score\":0.9}";
ObjectMapper mapper = new ObjectMapper();
ObjectNode jsonNode = mapper.convertValue(mapper.readTree(json), ObjectNode.class);

DetectedLanguage detectedLanguage = DetectedLanguage.ofJSON(jsonNode);

assertEquals("en", detectedLanguage.getLanguageCode());
assertEquals(0.9, detectedLanguage.getScore(), 0.0001);
assertFalse(detectedLanguage.isTranslationSupported());
assertFalse(detectedLanguage.isTransliterationSupported());
}

@Test
void ofJSON_withInvalidJson_returnsNull() throws JsonProcessingException {
String json = "{\"invalid\":\"json\"}";
ObjectMapper mapper = new ObjectMapper();
ObjectNode jsonNode = mapper.convertValue(mapper.readTree(json), ObjectNode.class);

DetectedLanguage detectedLanguage = DetectedLanguage.ofJSON(jsonNode);

assertNull(detectedLanguage);
}

@Test
void toString_returnsCorrectFormat() {
DetectedLanguage detectedLanguage = new DetectedLanguage("en", 0.9f, true, false);

String expected =
"DetectedLanguage{language='en', score=0.9, isTranslationSupported=true,"
+ " isTransliterationSupported=false}";
assertEquals(expected, detectedLanguage.toString());
}
}