From: Alexander Goussas Date: Sat, 23 May 2026 00:03:58 +0000 (-0500) Subject: tests: add unit tests for translation service X-Git-Url: http://git.frustrated-labs.net/?a=commitdiff_plain;h=9f44dd4923468834cb0c22da9bc4884c59fcf794;p=larousseapi tests: add unit tests for translation service --- diff --git a/build.gradle b/build.gradle index 99f40f3..bcc95cb 100644 --- a/build.gradle +++ b/build.gradle @@ -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 index 6eff3ed..0000000 --- a/src/test/java/net/frustratedfunctor/GreetingResourceTest.java +++ /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 index 0000000..9648a32 --- /dev/null +++ b/src/test/java/net/frustratedfunctor/translations/WordTranslationServiceTest.java @@ -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 strings() { + return Stream.of( + Arguments.of(""), + Arguments.of((String) null) + ); + } +} \ No newline at end of file