Skip to content

Commit e347bdb

Browse files
committed
add more unit tests
1 parent 5b1ead9 commit e347bdb

4 files changed

Lines changed: 66 additions & 0 deletions

File tree

sdk/src/main/java/com/amazonaws/lambda/durable/exception/StepInterruptedException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ public StepInterruptedException(Operation operation) {
1212
}
1313

1414
public static boolean isStepInterruptedException(ErrorObject errorObject) {
15+
if (errorObject == null) {
16+
return false;
17+
}
1518
return StepInterruptedException.toErrorObject().errorType().equals(errorObject.errorType());
1619
}
1720

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
package com.amazonaws.lambda.durable.exception;
4+
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
6+
7+
import org.junit.jupiter.api.Test;
8+
import software.amazon.awssdk.services.lambda.model.ErrorObject;
9+
import software.amazon.awssdk.services.lambda.model.Operation;
10+
11+
class CallbackExceptionTest {
12+
String CALLBACK_ID = "123";
13+
Operation OPERATION = Operation.builder().build();
14+
ErrorObject ERROR_OBJECT = ErrorObject.builder()
15+
.errorType("MyErrorType")
16+
.errorMessage("MyErrorMessage")
17+
.build();
18+
19+
@Test
20+
void testCallbackTimeoutException() {
21+
var exception = new CallbackTimeoutException(CALLBACK_ID, OPERATION);
22+
assertEquals(CALLBACK_ID, exception.getCallbackId());
23+
assertEquals(OPERATION, exception.getOperation());
24+
assertEquals("Callback timed out: " + CALLBACK_ID, exception.getMessage());
25+
}
26+
27+
@Test
28+
void testCallbackFailedException() {
29+
var exception = new CallbackFailedException(CALLBACK_ID, OPERATION, ERROR_OBJECT);
30+
assertEquals(CALLBACK_ID, exception.getCallbackId());
31+
assertEquals(OPERATION, exception.getOperation());
32+
assertEquals(ERROR_OBJECT, exception.getErrorObject());
33+
assertEquals("MyErrorType: MyErrorMessage", exception.getMessage());
34+
}
35+
36+
@Test
37+
void testCallbackException() {
38+
var exception = new CallbackException(CALLBACK_ID, OPERATION, ERROR_OBJECT, "myErrorMessage");
39+
assertEquals(CALLBACK_ID, exception.getCallbackId());
40+
assertEquals(OPERATION, exception.getOperation());
41+
assertEquals(ERROR_OBJECT, exception.getErrorObject());
42+
assertEquals("myErrorMessage", exception.getMessage());
43+
}
44+
}

sdk/src/test/java/com/amazonaws/lambda/durable/exception/StepFailedExceptionTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@ class StepFailedExceptionTest {
1818
@Test
1919
void testConstructorWithNullErrorObject() {
2020
var exception = new StepFailedException(OPERATION, null);
21+
assertEquals(OPERATION, exception.getOperation());
22+
assertNull(exception.getErrorObject());
2123
assertEquals("Step failed with null error", exception.getMessage());
2224
}
2325

2426
@Test
2527
void testConstructorWithErrorObject() {
2628
var exception = new StepFailedException(OPERATION, ERROR_OBJECT);
2729

30+
assertEquals(OPERATION, exception.getOperation());
31+
assertEquals(ERROR_OBJECT, exception.getErrorObject());
2832
assertEquals("Step failed with error of type MyErrorType. Message: MyErrorMessage", exception.getMessage());
2933
}
3034
}

sdk/src/test/java/com/amazonaws/lambda/durable/exception/StepInterruptedExceptionTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@
55
import static org.junit.jupiter.api.Assertions.*;
66

77
import org.junit.jupiter.api.Test;
8+
import software.amazon.awssdk.services.lambda.model.ErrorObject;
89
import software.amazon.awssdk.services.lambda.model.Operation;
910

1011
class StepInterruptedExceptionTest {
12+
private static final String ERROR_TYPE = "com.amazonaws.lambda.durable.exception.StepInterruptedException";
1113
private static final Operation OPERATION =
1214
Operation.builder().id("op-123").name("my-step").build();
1315

1416
@Test
1517
void testConstructorWithOperationIdAndStepName() {
1618
var exception = new StepInterruptedException(OPERATION);
1719

20+
assertEquals(ERROR_TYPE, exception.getErrorObject().errorType());
1821
assertInstanceOf(RuntimeException.class, exception);
1922
assertInstanceOf(DurableExecutionException.class, exception);
2023
assertEquals("op-123", exception.getOperation().id());
@@ -23,4 +26,16 @@ void testConstructorWithOperationIdAndStepName() {
2326
assertTrue(exception.getMessage().contains("Step Name: my-step"));
2427
assertTrue(exception.getMessage().contains("initiated but failed to reach completion due to an interruption"));
2528
}
29+
30+
@Test
31+
void testIsStepInterruptedException() {
32+
var errorObject = ErrorObject.builder().errorType(ERROR_TYPE).build();
33+
assertTrue(StepInterruptedException.isStepInterruptedException(errorObject));
34+
35+
assertFalse(StepInterruptedException.isStepInterruptedException(null));
36+
assertFalse(StepInterruptedException.isStepInterruptedException(
37+
ErrorObject.builder().build()));
38+
assertFalse(StepInterruptedException.isStepInterruptedException(
39+
ErrorObject.builder().errorType("StepInterruptedException").build()));
40+
}
2641
}

0 commit comments

Comments
 (0)