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 #28

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
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
42 changes: 21 additions & 21 deletions src/main/java/com/github/brenoepics/at4j/data/DetectedLanguage.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import com.fasterxml.jackson.databind.node.ObjectNode;

/**
* Represents a detected language.
*/
/** Represents a detected language. */
public class DetectedLanguage {

// The language code of the detected language
Expand All @@ -24,14 +22,16 @@ public class DetectedLanguage {
*
* @param languageCode The language code of the detected language.
* @param score The confidence score of the detected language.
* @param isTranslationSupported A boolean indicating if the language is supported for translation.
* @param isTransliterationSupported A boolean indicating if the language is supported for transliteration.
* @param isTranslationSupported A boolean indicating if the language is supported for
* translation.
* @param isTransliterationSupported A boolean indicating if the language is supported for
* transliteration.
*/
public DetectedLanguage(
String languageCode,
float score,
boolean isTranslationSupported,
boolean isTransliterationSupported) {
String languageCode,
float score,
boolean isTranslationSupported,
boolean isTransliterationSupported) {
this.languageCode = languageCode;
this.score = score;
this.isTranslationSupported = isTranslationSupported;
Expand Down Expand Up @@ -59,7 +59,7 @@ public static DetectedLanguage ofJSON(ObjectNode jsonNode) {
if (jsonNode == null || !jsonNode.has("language") || !jsonNode.has("score")) return null;

DetectedLanguage detected =
new DetectedLanguage(jsonNode.get("language").asText(), jsonNode.get("score").floatValue());
new DetectedLanguage(jsonNode.get("language").asText(), jsonNode.get("score").floatValue());

if (jsonNode.has("isTranslationSupported"))
detected.isTranslationSupported = jsonNode.get("isTranslationSupported").asBoolean();
Expand Down Expand Up @@ -113,15 +113,15 @@ public boolean isTransliterationSupported() {
@Override
public String toString() {
return "DetectedLanguage{"
+ "language='"
+ languageCode
+ '\''
+ ", score="
+ score
+ ", isTranslationSupported="
+ isTranslationSupported
+ ", isTransliterationSupported="
+ isTransliterationSupported
+ '}';
+ "language='"
+ languageCode
+ '\''
+ ", score="
+ score
+ ", isTranslationSupported="
+ isTranslationSupported
+ ", isTransliterationSupported="
+ isTransliterationSupported
+ '}';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import com.fasterxml.jackson.databind.node.ObjectNode;

/**
* A translation of a text. This class is immutable.
*/
/** A translation of a text. This class is immutable. */
public class Translation {

// The language code for the translation
Expand Down Expand Up @@ -74,4 +72,4 @@ public String getText() {
public String toString() {
return "Translation{" + "key='" + languageCode + '\'' + ", value='" + text + '\'' + '}';
}
}
}
55 changes: 26 additions & 29 deletions src/test/java/com/github/brenoepics/at4j/AT4JTest.java
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
package com.github.brenoepics.at4j;

import org.junit.Test;

import java.lang.reflect.Field;
import java.time.Instant;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class AT4JTest {

@Test
public void testVersionFields() throws NoSuchFieldException, IllegalAccessException {
Field versionField = AT4J.class.getDeclaredField("VERSION");
versionField.setAccessible(true);
String version = (String) versionField.get(null);
assertNotNull(version);

Field commitIdField = AT4J.class.getDeclaredField("COMMIT_ID");
commitIdField.setAccessible(true);
String commitId = (String) commitIdField.get(null);
assertNotNull(commitId);

Field displayVersionField = AT4J.class.getDeclaredField("DISPLAY_VERSION");
displayVersionField.setAccessible(true);
String displayVersion = (String) displayVersionField.get(null);
assertNotNull(displayVersion);
import java.lang.reflect.Field;
import org.junit.Test;

}
public class AT4JTest {

@Test
public void testAzureTranslatorApiVersion() {
assertEquals("3.0", AT4J.AZURE_TRANSLATOR_API_VERSION);
}
}
@Test
public void testVersionFields() throws NoSuchFieldException, IllegalAccessException {
Field versionField = AT4J.class.getDeclaredField("VERSION");
versionField.setAccessible(true);
String version = (String) versionField.get(null);
assertNotNull(version);

Field commitIdField = AT4J.class.getDeclaredField("COMMIT_ID");
commitIdField.setAccessible(true);
String commitId = (String) commitIdField.get(null);
assertNotNull(commitId);

Field displayVersionField = AT4J.class.getDeclaredField("DISPLAY_VERSION");
displayVersionField.setAccessible(true);
String displayVersion = (String) displayVersionField.get(null);
assertNotNull(displayVersion);
}

@Test
public void testAzureTranslatorApiVersion() {
assertEquals("3.0", AT4J.AZURE_TRANSLATOR_API_VERSION);
}
}
70 changes: 33 additions & 37 deletions src/test/java/com/github/brenoepics/at4j/core/AzureApiImplTest.java
Original file line number Diff line number Diff line change
@@ -1,55 +1,51 @@
package com.github.brenoepics.at4j.core;

import com.github.brenoepics.at4j.AzureApiBuilder;
import com.github.brenoepics.at4j.azure.BaseURL;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

import com.github.brenoepics.at4j.data.Translation;
import com.github.brenoepics.at4j.data.request.TranslateParams;
import com.github.brenoepics.at4j.data.response.TranslationResponse;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

class AzureApiImplTest {

private AzureApiImpl azureApi;
private TranslateParams translateParams;
private AzureApiImpl azureApi;
private TranslateParams translateParams;

@BeforeEach
public void setup() {
azureApi = Mockito.mock(AzureApiImpl.class);
translateParams = new TranslateParams("Hello")
.setSourceLanguage("en")
.setTargetLanguages("pt");
}
@BeforeEach
public void setup() {
azureApi = Mockito.mock(AzureApiImpl.class);
translateParams = new TranslateParams("Hello").setSourceLanguage("en").setTargetLanguages("pt");
}

@Test
void returnsTranslationOnValidInput() {
TranslationResponse expectedResponse = new TranslationResponse(Collections.singleton(new Translation("pt", "Olá")));
when(azureApi.translate(any(TranslateParams.class))).thenReturn(CompletableFuture.completedFuture(Optional.of(expectedResponse)));
@Test
void returnsTranslationOnValidInput() {
TranslationResponse expectedResponse =
new TranslationResponse(Collections.singleton(new Translation("pt", "Olá")));
when(azureApi.translate(any(TranslateParams.class)))
.thenReturn(CompletableFuture.completedFuture(Optional.of(expectedResponse)));

CompletableFuture<Optional<TranslationResponse>> response = azureApi.translate(translateParams);
CompletableFuture<Optional<TranslationResponse>> response = azureApi.translate(translateParams);

assertTrue(response.join().isPresent());
assertEquals(expectedResponse, response.join().get());
}
assertTrue(response.join().isPresent());
assertEquals(expectedResponse, response.join().get());
}

@Test
void returnsEmptyOnInvalidInput() {
translateParams.setText(null);
when(azureApi.translate(any(TranslateParams.class))).thenReturn(CompletableFuture.completedFuture(Optional.empty()));
@Test
void returnsEmptyOnInvalidInput() {
translateParams.setText(null);
when(azureApi.translate(any(TranslateParams.class)))
.thenReturn(CompletableFuture.completedFuture(Optional.empty()));

CompletableFuture<Optional<TranslationResponse>> response = azureApi.translate(translateParams);
CompletableFuture<Optional<TranslationResponse>> response = azureApi.translate(translateParams);

assertFalse(response.join().isPresent());
}
}
assertFalse(response.join().isPresent());
}
}