Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8dd1add
Increase code coverage on dynamodb-enhanced module
andreas-grafenberger Feb 13, 2026
b278881
Merge branch 'master' into 437-increase_test_coverage
andreas-grafenberger Feb 20, 2026
e33be5f
Addressing comments (refactoring, removing duplicated tests).
andreas-grafenberger Feb 20, 2026
1ef7ea3
Addressing comments (adding more tests for chain extension).
andreas-grafenberger Feb 25, 2026
523fb64
Adding release change note.
andreas-grafenberger Feb 25, 2026
adadbe9
Merge branch 'master' into 437-increase_test_coverage
andreas-grafenberger Feb 26, 2026
377bde1
Parametrization of annotated bean and immutable table schema tests. A…
andreas-grafenberger Feb 26, 2026
d0d61ed
Refactoring test class: AutoGeneratedUuidExtensionTest
andreas-grafenberger Mar 2, 2026
0d124ef
Removing test class: AutoGeneratedUuidExtensionTest... will be added …
andreas-grafenberger Mar 2, 2026
01a65e1
Merge remote-tracking branch 'origin/437-increase_test_coverage' into…
andreas-grafenberger Mar 2, 2026
ef3dc6b
Merge branch 'master' into 437-increase_test_coverage
andreas-grafenberger Mar 2, 2026
11d648d
Removing unused utils class for tests.
andreas-grafenberger Mar 2, 2026
55633a3
Merge branch 'master' into 437-increase_test_coverage
andreas-grafenberger Apr 3, 2026
d2322c6
Fixing conflict and updated tests.
andreas-grafenberger Apr 5, 2026
53b6218
Merge branch 'master' into 437-increase_test_coverage
andreas-grafenberger Apr 17, 2026
1f8a330
Fixing conflicts on EnhancedClientUtilsTest
andreas-grafenberger Apr 17, 2026
e547100
Removing duplicate test pairs.
andreas-grafenberger Apr 28, 2026
87a6083
Replacing hamcrest imports with assertj.
andreas-grafenberger Apr 29, 2026
84bdb63
Merge branch 'master' into 437-increase_test_coverage
andreas-grafenberger Apr 29, 2026
386e270
Tests refactorization (parameterization).
andreas-grafenberger Apr 29, 2026
7815adf
Merge branch 'master' into 437-increase_test_coverage
zoewangg May 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "feature",
"category": "Amazon DynamoDB Enhanced Client",
"contributor": "",
"description": "Increase code coverage on dynamodb-enhanced module"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.awssdk.enhanced.dynamodb;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.util.List;
import org.apache.logging.log4j.core.LogEvent;
import org.junit.jupiter.api.Test;
import org.slf4j.event.Level;

public class DefaultAttributeConverterProviderTest {

@Test
void findConverter_whenConverterFound_logsConverterFound() {
try (LogCaptor logCaptor = new LogCaptor(DefaultAttributeConverterProvider.class, Level.DEBUG)) {
DefaultAttributeConverterProvider provider = DefaultAttributeConverterProvider.create();
provider.converterFor(EnhancedType.of(String.class));

List<LogEvent> logEvents = logCaptor.loggedEvents();
assertThat(logEvents).hasSize(1);
assertThat(logEvents.get(0).getLevel().name()).isEqualTo(Level.DEBUG.name());
assertThat(logEvents.get(0).getMessage().getFormattedMessage())
.contains("Converter for EnhancedType(java.lang.String): software.amazon.awssdk.enhanced.dynamodb.internal"
+ ".converter.attribute.StringAttributeConverter");
}
}

@Test
void findConverter_whenConverterNotFound_logsNoConverter() {
try (LogCaptor logCaptor = new LogCaptor(DefaultAttributeConverterProvider.class, Level.DEBUG)) {
DefaultAttributeConverterProvider provider = DefaultAttributeConverterProvider.create();

assertThatThrownBy(() -> provider.converterFor(EnhancedType.of(CustomUnsupportedType.class)))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("Converter not found for EnhancedType(software.amazon.awssdk.enhanced.dynamodb"
+ ".DefaultAttributeConverterProviderTest$CustomUnsupportedType)");
List<LogEvent> logEvents = logCaptor.loggedEvents();
assertThat(logEvents).hasSize(1);
assertThat(logEvents.get(0).getLevel().name()).isEqualTo(Level.DEBUG.name());
assertThat(logEvents.get(0).getMessage().getFormattedMessage())
.contains("No converter available for EnhancedType(software.amazon.awssdk.enhanced.dynamodb"
+ ".DefaultAttributeConverterProviderTest$CustomUnsupportedType)");
}
}

/**
* A custom type with no converter registered for it.
*/
private static class CustomUnsupportedType {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.awssdk.enhanced.dynamodb;

import static java.util.stream.Collectors.toList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.CALLS_REAL_METHODS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.io.File;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.TestFactory;

/**
* Test class that discovers all interfaces with default methods that throw UnsupportedOperationException. Shows individual test
* scenarios and results using DynamicTest.
*/
public class DefaultMethodsUnsupportedOperationTest {

private static final String BASE_PACKAGE = "software.amazon.awssdk.enhanced.dynamodb";
private static final Pattern CLASS_PATTERN = Pattern.compile(".class", Pattern.LITERAL);

private static final List<String> testScenarios = Collections.synchronizedList(new java.util.ArrayList<>());

@TestFactory
Stream<DynamicTest> testDefaultMethodsThrowUnsupportedOperation() {
List<DynamicTest> dynamicTestList = scanPackageForClasses(BASE_PACKAGE)
.filter(Class::isInterface)
.filter(this::hasDefaultMethods)
.collect(toList())
.stream()
.flatMap(this::createTestsForInterface)
.collect(toList());
assertEquals(102, dynamicTestList.size());
return dynamicTestList.stream();
}

private Stream<Class<?>> scanPackageForClasses(String packageName) {
try {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
return Collections.list(loader.getResources(packageName.replace('.', '/')))
.stream()
.map(URL::getFile)
.map(File::new)
.filter(File::exists)
.flatMap(dir -> findClassesInDirectory(dir, packageName));
} catch (Exception e) {
return Stream.empty();
}
}

private Stream<Class<?>> findClassesInDirectory(File dir, String packageName) {
return Optional.ofNullable(dir.listFiles())
.map(Arrays::stream)
.orElseGet(Stream::empty)
.flatMap(file ->
file.isDirectory()
? findClassesInDirectory(file, packageName + "." + file.getName())
: loadClassFromFile(file, packageName));
}

private Stream<Class<?>> loadClassFromFile(File file, String packageName) {
if (!file.getName().endsWith(".class")) {
return Stream.empty();
}

String className = packageName + '.' + CLASS_PATTERN.matcher(file.getName()).replaceAll("");
try {
return Stream.of(Class.forName(className));
} catch (ClassNotFoundException | NoClassDefFoundError e) {
return Stream.empty();
}
}

private boolean hasDefaultMethods(Class<?> interfaceClass) {
return Arrays.stream(interfaceClass.getDeclaredMethods())
.anyMatch(Method::isDefault);
}

private Stream<DynamicTest> createTestsForInterface(Class<?> interfaceClass) {
return Arrays.stream(interfaceClass.getDeclaredMethods())
.filter(Method::isDefault)
.filter(method -> throwsUnsupportedOperation(interfaceClass, method))
.map(method -> {
String testName = String.format("%s.%s() → throws UnsupportedOperationException",
interfaceClass.getSimpleName(),
method.getName());
testScenarios.add(testName);

return DynamicTest.dynamicTest(testName, () ->
testMethodThrowsUnsupportedOperation(interfaceClass, method));
});
}

private boolean throwsUnsupportedOperation(Class<?> interfaceClass, Method method) {
try {
Object mockInstance = createMockInstance(interfaceClass);
Object[] args = createArguments(method);
method.invoke(mockInstance, args);
return false;
} catch (Exception e) {
Throwable cause = e.getCause() != null ? e.getCause() : e;
return cause instanceof UnsupportedOperationException;
}
}

private void testMethodThrowsUnsupportedOperation(Class<?> interfaceClass, Method method) {
Object mockInstance = createMockInstance(interfaceClass);
Object[] args = createArguments(method);

assertThrows(UnsupportedOperationException.class, () -> {
try {
method.invoke(mockInstance, args);
} catch (Exception e) {
Throwable cause = e.getCause() != null ? e.getCause() : e;
if (cause instanceof UnsupportedOperationException) {
throw cause;
}
throw new RuntimeException(cause);
}
}, () -> String.format("Expected %s.%s() to throw UnsupportedOperationException",
interfaceClass.getSimpleName(), method.getName()));
}

private <T> T createMockInstance(Class<T> interfaceClass) {
T mock = mock(interfaceClass, CALLS_REAL_METHODS);
if (mock instanceof MappedTableResource) {
when(((MappedTableResource<?>) mock).tableName()).thenReturn("test-table");
}
return mock;
}

private Object[] createArguments(Method method) {
return Arrays.stream(method.getParameterTypes()).map(this::createArgument).toArray();
}

private Object createArgument(Class<?> paramType) {
if (paramType == String.class) {
return "test";
}
if (paramType == Key.class) {
return Key.builder().partitionValue("test").build();
}
if (Consumer.class.isAssignableFrom(paramType)) {
return (Consumer<?>) obj -> {
};
}
if (paramType.isInterface()) {
return mock(paramType);
}
try {
return mock(paramType);
} catch (Exception e) {
return null;
}
}
}
Loading
Loading