]> git.frustrated-labs.net Git - larousseapi/commitdiff
tests: add unit tests for translation service
authorAlexander Goussas <[email protected]>
Sat, 23 May 2026 00:03:58 +0000 (19:03 -0500)
committerAlexander Goussas <[email protected]>
Sat, 23 May 2026 00:03:58 +0000 (19:03 -0500)
build.gradle
src/test/java/net/frustratedfunctor/GreetingResourceTest.java [deleted file]
src/test/java/net/frustratedfunctor/translations/WordTranslationServiceTest.java [new file with mode: 0644]

index 99f40f34886302bd1f91095c55d8db6908b7cbfc..bcc95cb30c7bc5dba741c91be5c2be598e6f9335 100644 (file)
@@ -14,6 +14,7 @@ dependencies {
     implementation 'io.quarkus:quarkus-rest-jackson'
     implementation 'io.quarkus:quarkus-arc'
     implementation 'org.jsoup:jsoup:1.22.2'
+    testImplementation 'io.quarkus:quarkus-junit5-mockito'
     testImplementation 'io.quarkus:quarkus-junit'
     testImplementation 'io.rest-assured:rest-assured'
 }
diff --git a/src/test/java/net/frustratedfunctor/GreetingResourceTest.java b/src/test/java/net/frustratedfunctor/GreetingResourceTest.java
deleted file mode 100644 (file)
index 6eff3ed..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-package net.frustratedfunctor;
-
-import io.quarkus.test.junit.QuarkusTest;
-import org.junit.jupiter.api.Test;
-
-import static io.restassured.RestAssured.given;
-import static org.hamcrest.CoreMatchers.is;
-
-@QuarkusTest
-class GreetingResourceTest {
-    @Test
-    void testHelloEndpoint() {
-        given()
-          .when().get("/hello")
-          .then()
-             .statusCode(200)
-             .body(is("Hello from Quarkus REST"));
-    }
-
-}
\ No newline at end of file
diff --git a/src/test/java/net/frustratedfunctor/translations/WordTranslationServiceTest.java b/src/test/java/net/frustratedfunctor/translations/WordTranslationServiceTest.java
new file mode 100644 (file)
index 0000000..9648a32
--- /dev/null
@@ -0,0 +1,41 @@
+package net.frustratedfunctor.translations;
+
+import io.quarkus.test.InjectMock;
+import io.quarkus.test.junit.QuarkusTest;
+import net.frustratedfunctor.InvalidWordException;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.mockito.Mockito;
+
+import java.util.Collections;
+import java.util.stream.Stream;
+
+@QuarkusTest
+class WordTranslationServiceTest {
+
+    @InjectMock
+    WordTranslationRepository repository;
+
+    @MethodSource("strings")
+    @ParameterizedTest
+    void givenInvalidWordWhenTranslateThenExceptionIsThrown(String s) {
+        Mockito.when(repository.translationsForWord(s))
+                .thenReturn(Collections.emptyList());
+
+        final var sut = new WordTranslationService(repository);
+
+        Assertions.assertThrows(
+                InvalidWordException.class,
+                () -> sut.translate(s)
+        );
+    }
+
+    static Stream<Arguments> strings() {
+        return Stream.of(
+                Arguments.of(""),
+                Arguments.of((String) null)
+        );
+    }
+}
\ No newline at end of file