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'
}
+++ /dev/null
-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
--- /dev/null
+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