Skip to content

Commit

Permalink
fix(test): update mockito to support final class (#551)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgabelle authored Oct 28, 2024
1 parent 16d0382 commit ef82dcf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ dependencies {
testImplementation "org.junit.jupiter:junit-jupiter-engine"
testImplementation "org.hamcrest:hamcrest"
testImplementation "org.hamcrest:hamcrest-library"
testImplementation 'org.mockito:mockito-junit-jupiter'
testImplementation 'org.mockito:mockito-inline:5.2.0'

testAnnotationProcessor group: "io.kestra", name: "processor"
testImplementation group: "io.kestra", name: "core"
Expand Down
18 changes: 9 additions & 9 deletions src/test/java/io/kestra/plugin/aws/lambda/InvokeUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class InvokeUnitTest {
private File tempFile;

@BeforeEach
public void setUp() throws IOException, IllegalVariableEvaluationException {
void setUp() throws IOException, IllegalVariableEvaluationException {
given(context.storage()).willReturn(storage);
given(context.workingDir()).willReturn(workingDir);
given(context.workingDir().createTempFile()).willReturn(Files.createTempFile("test", "lambdainvoke"));
Expand Down Expand Up @@ -88,40 +88,40 @@ public URI answer(InvocationOnMock invocation) throws Throwable {
}

@AfterEach
public void tearDown() {
void tearDown() {
if (tempFile != null && tempFile.exists()) {
tempFile.delete();
}
this.tempFile = null;
}

@Test
public void testParseContentType_NoContentType_Binary() {
void testParseContentType_NoContentType_Binary() {
assertEquals(ContentType.APPLICATION_OCTET_STREAM, invoke.parseContentType(Optional.empty()), "Should be binary");
}

@Test
public void testParseContentType_BadContent_Binary() {
void testParseContentType_BadContent_Binary() {
assertEquals(ContentType.APPLICATION_OCTET_STREAM, invoke.parseContentType(Optional.of("fake/type")), "Should be binary");
}

@Test
public void testParseContentType_JSON() {
void testParseContentType_JSON() {
assertEquals(ContentType.APPLICATION_JSON.getMimeType().toString(),
invoke.parseContentType(Optional.of("application/json")).getMimeType().toString(),
"Should be JSON");
}

@Test
public void testReadError_NotJsonType(@Mock SdkBytes bytes) {
void testReadError_NotJsonType(@Mock SdkBytes bytes) {
assertThrows(LambdaInvokeException.class, () -> {
invoke.handleError(invoke.getFunctionArn(), ContentType.APPLICATION_OCTET_STREAM, bytes);
}, "Should throw an error"
);
}

@Test
public void testReadError_FromJsonMessage(@Mock SdkBytes bytes) {
void testReadError_FromJsonMessage(@Mock SdkBytes bytes) {
String errorText = "'path'";
given(bytes.asUtf8String()).willReturn(
"{\"errorMessage\": \"" + errorText + "\", \"errorType\": \"KeyError\"}");
Expand All @@ -133,7 +133,7 @@ public void testReadError_FromJsonMessage(@Mock SdkBytes bytes) {
}

@Test
public void testHandleContent_SaveFile_ReturnOutput(@Mock SdkBytes bytes) throws IOException {
void testHandleContent_SaveFile_ReturnOutput(@Mock SdkBytes bytes) throws IOException {
//val json = "{\"data\": \"some value\", \"author\": \"The User\"}";
var data = "some raw data";
given(bytes.asInputStream()).willReturn(new ByteArrayInputStream(data.getBytes()));
Expand All @@ -157,7 +157,7 @@ private void checkOutput(final String originalData, final Output result) throws

// ******** BDD usecases ********
@Test
public void givenFunctionArnNoParams_whenInvokeLambda_thenOutputWithFile(
void givenFunctionArnNoParams_whenInvokeLambda_thenOutputWithFile(
@Mock LambdaClient awsLambda,
@Mock InvokeResponse awsResponse,
@Mock SdkHttpResponse awsHttpResponse,
Expand Down

0 comments on commit ef82dcf

Please sign in to comment.