Skip to content

Commit 5482e29

Browse files
authored
Merge pull request #17 from /issues/15
Fix #15: Dedup `supports` and `client` methods in `AWSClientExtension`
2 parents 194be96 + f417efe commit 5482e29

File tree

72 files changed

+467
-351
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+467
-351
lines changed

.editorconfig

Lines changed: 0 additions & 12 deletions
This file was deleted.

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
.gradle
22
build
33

4-
.idea
4+
.idea/*
5+
!.idea/codeStyles
6+
!.idea/inspectionProfiles
57
out
68

79
public

.idea/codeStyles/Project.xml

Lines changed: 129 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyles/codeStyleConfig.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/aws_junit5.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/profiles_settings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ JUnit 5 extensions for AWS
77
This repo contains few JUnit 5 https://junit.org/junit5/docs/current/user-guide/#extensions[extensions] that you could find useful for testing AWS-related code.
88
These extensions can be used to inject clients for AWS service mocks provided by tools like https://github.com/localstack/localstack[localstack] or https://aws.amazon.com/about-aws/whats-new/2018/08/use-amazon-dynamodb-local-more-easily-with-the-new-docker-image/[DynamoDB Local].
99
Both AWS Java SDK https://docs.aws.amazon.com/sdk-for-java/v2/developer-guide/welcome.html[v 2.x] and https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/welcome.html[v 1.x] are supported.
10-
Currently these services are supported:
10+
Currently, these services are supported:
1111

1212
- https://aws.amazon.com/dynamodb[DynamoDB]
1313
- https://aws.amazon.com/kinesis/data-streams[Kinesis Data Streams]
@@ -16,6 +16,7 @@ Currently these services are supported:
1616
- https://aws.amazon.com/ses[SES]
1717
- https://aws.amazon.com/sns[SNS]
1818
- https://aws.amazon.com/sqs[SQS]
19+
- https://aws.amazon.com/lambda[Lambda]
1920

2021
== How do I use it?
2122

build.gradle.kts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,12 @@ tasks {
140140
"https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/"
141141
)
142142
}
143-
subprojects.forEach {
144-
it.tasks.withType<Javadoc>().forEach {
145-
source += it.source
146-
classpath += it.classpath
147-
includes += it.includes
148-
excludes += it.excludes
143+
subprojects.forEach { subproject ->
144+
subproject.tasks.withType<Javadoc>().forEach { task ->
145+
source += task.source
146+
classpath += task.classpath
147+
includes += task.includes
148+
excludes += task.excludes
149149
}
150150
}
151151
}

common/src/main/java/me/madhead/aws_junit5/common/impl/AWSClientExtension.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public void postProcessTestInstance(final Object testInstance, final ExtensionCo
2020
}
2121

2222
private void inject(final Object testInstance, final Field field) throws Exception {
23-
final boolean accessible = field.isAccessible();
23+
@SuppressWarnings("deprecation") final boolean accessible = field.isAccessible();
2424

2525
try {
2626
field.setAccessible(true);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package me.madhead.aws_junit5.common.impl;
2+
3+
import java.lang.reflect.Field;
4+
import java.util.Map;
5+
6+
/**
7+
* Dictionary-based {@link AWSClientExtension} implementation.
8+
*/
9+
public abstract class AWSClientExtensionBase extends AWSClientExtension {
10+
abstract protected Map<Class<?>, ? extends AWSClientFactory<?>> factories();
11+
12+
@Override
13+
protected boolean supports(final Field field) {
14+
return factories().containsKey(field.getType());
15+
}
16+
17+
@Override
18+
protected Object client(final Field field) throws Exception {
19+
return factories().get(field.getType()).client(field);
20+
}
21+
}

0 commit comments

Comments
 (0)