-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor dependency injection to support test implementations
- Loading branch information
1 parent
1ce06e6
commit 5c7fc84
Showing
17 changed files
with
254 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 0 additions & 27 deletions
27
...tracker_api/src/main/java/com/jordansimsmith/immersiontracker/ImmersionTrackerModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...er_api/src/test/java/com/jordansimsmith/immersiontracker/ImmersionTrackerTestFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.jordansimsmith.immersiontracker; | ||
|
||
import com.jordansimsmith.dynamodb.DynamoDbTestModule; | ||
import com.jordansimsmith.json.ObjectMapperModule; | ||
import com.jordansimsmith.time.ClockTestModule; | ||
import com.jordansimsmith.time.FakeClock; | ||
import dagger.BindsInstance; | ||
import dagger.Component; | ||
import java.net.URI; | ||
import javax.inject.Named; | ||
import javax.inject.Singleton; | ||
|
||
@Singleton | ||
@Component( | ||
modules = { | ||
ClockTestModule.class, | ||
ObjectMapperModule.class, | ||
DynamoDbTestModule.class, | ||
ImmersionTrackerModule.class | ||
}) | ||
public interface ImmersionTrackerTestFactory extends ImmersionTrackerFactory { | ||
FakeClock fakeClock(); | ||
|
||
@Component.Factory | ||
interface Factory { | ||
ImmersionTrackerTestFactory create( | ||
@BindsInstance @Named("dynamoDbEndpoint") URI dynamoDbEndpoint); | ||
} | ||
|
||
static ImmersionTrackerTestFactory create(URI dynamoDbEndpoint) { | ||
return DaggerImmersionTrackerTestFactory.factory().create(dynamoDbEndpoint); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
load("@dagger//:workspace_defs.bzl", "dagger_rules") | ||
|
||
dagger_rules() | ||
|
||
java_library( | ||
name = "lib", | ||
srcs = glob(["src/main/java/**/*.java"]), | ||
visibility = [ | ||
"//visibility:public", | ||
], | ||
deps = [ | ||
":dagger", | ||
"@maven//:software_amazon_awssdk_dynamodb", | ||
"@maven//:software_amazon_awssdk_dynamodb_enhanced", | ||
], | ||
) |
22 changes: 22 additions & 0 deletions
22
lib/dynamodb/src/main/java/com/jordansimsmith/dynamodb/DynamoDbModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.jordansimsmith.dynamodb; | ||
|
||
import dagger.Module; | ||
import dagger.Provides; | ||
import javax.inject.Singleton; | ||
import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient; | ||
import software.amazon.awssdk.services.dynamodb.DynamoDbClient; | ||
|
||
@Module | ||
public class DynamoDbModule { | ||
@Provides | ||
@Singleton | ||
public DynamoDbClient dynamoDbClient() { | ||
return DynamoDbClient.builder().build(); | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
public DynamoDbEnhancedClient dynamoDbEnhancedClient(DynamoDbClient dynamoDbClient) { | ||
return DynamoDbEnhancedClient.builder().dynamoDbClient(dynamoDbClient).build(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
lib/dynamodb/src/main/java/com/jordansimsmith/dynamodb/DynamoDbTestModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.jordansimsmith.dynamodb; | ||
|
||
import dagger.Module; | ||
import dagger.Provides; | ||
import java.net.URI; | ||
import javax.inject.Named; | ||
import javax.inject.Singleton; | ||
import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient; | ||
import software.amazon.awssdk.services.dynamodb.DynamoDbClient; | ||
|
||
@Module | ||
public class DynamoDbTestModule { | ||
@Provides | ||
@Singleton | ||
public DynamoDbClient dynamoDbClient(@Named("dynamoDbEndpoint") URI dynamoDbEndpoint) { | ||
return DynamoDbClient.builder().endpointOverride(dynamoDbEndpoint).build(); | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
public DynamoDbEnhancedClient dynamoDbEnhancedClient(DynamoDbClient dynamoDbClient) { | ||
return DynamoDbEnhancedClient.builder().dynamoDbClient(dynamoDbClient).build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
load("@dagger//:workspace_defs.bzl", "dagger_rules") | ||
|
||
dagger_rules() | ||
|
||
java_library( | ||
name = "lib", | ||
srcs = glob(["src/main/java/**/*.java"]), | ||
visibility = [ | ||
"//visibility:public", | ||
], | ||
deps = [ | ||
":dagger", | ||
"@maven//:com_fasterxml_jackson_core_jackson_databind", | ||
], | ||
) |
13 changes: 13 additions & 0 deletions
13
lib/json/src/main/java/com/jordansimsmith/json/ObjectMapperModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.jordansimsmith.json; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import dagger.Module; | ||
import dagger.Provides; | ||
|
||
@Module | ||
public class ObjectMapperModule { | ||
@Provides | ||
public ObjectMapper objectMapper() { | ||
return new ObjectMapper(); | ||
} | ||
} |
Oops, something went wrong.