-
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 internals to replace large arg lists with "options" class (#301
) Note specifically that NO public APIs are affected. * Introduce ErrorContextOptions class * Refactor code to use the options class instead of large argument lists * Add Checker Nullable annotation to methods in ErrorContextUtilities Closes #300
- Loading branch information
1 parent
a55175c
commit 81a5f4b
Showing
10 changed files
with
251 additions
and
142 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
48 changes: 48 additions & 0 deletions
48
src/main/java/org/kiwiproject/dropwizard/error/ErrorContextOptions.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,48 @@ | ||
package org.kiwiproject.dropwizard.error; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NonNull; | ||
|
||
import org.kiwiproject.dropwizard.error.config.CleanupConfig; | ||
import org.kiwiproject.dropwizard.error.health.TimeWindow; | ||
import org.kiwiproject.dropwizard.error.model.DataStoreType; | ||
|
||
import java.time.temporal.ChronoUnit; | ||
import java.time.temporal.TemporalUnit; | ||
|
||
/** | ||
* Contains options common to different types of {@link ErrorContext}. | ||
* | ||
* @implNote This is not public and is subject to change. | ||
*/ | ||
@Builder | ||
@Getter | ||
class ErrorContextOptions { | ||
|
||
@NonNull | ||
@Builder.Default | ||
private DataStoreType dataStoreType = DataStoreType.SHARED; | ||
|
||
@Builder.Default | ||
private boolean addErrorsResource = true; | ||
|
||
@Builder.Default | ||
private boolean addGotErrorsResource = true; | ||
|
||
@Builder.Default | ||
private boolean addHealthCheck = true; | ||
|
||
@Builder.Default | ||
private long timeWindowValue = TimeWindow.DEFAULT_TIME_WINDOW_MINUTES; | ||
|
||
@NonNull | ||
@Builder.Default | ||
private TemporalUnit timeWindowUnit = ChronoUnit.MINUTES; | ||
|
||
@Builder.Default | ||
private boolean addCleanupJob = true; | ||
|
||
@Builder.Default | ||
private CleanupConfig cleanupConfig = new CleanupConfig(); | ||
} |
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
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
45 changes: 45 additions & 0 deletions
45
src/test/java/org/kiwiproject/dropwizard/error/ErrorContextOptionsTest.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,45 @@ | ||
package org.kiwiproject.dropwizard.error; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatNullPointerException; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.kiwiproject.dropwizard.error.config.CleanupConfig; | ||
import org.kiwiproject.dropwizard.error.health.TimeWindow; | ||
import org.kiwiproject.dropwizard.error.model.DataStoreType; | ||
|
||
import java.time.temporal.ChronoUnit; | ||
|
||
@DisplayName("ErrorContextOptions") | ||
class ErrorContextOptionsTest { | ||
|
||
@Test | ||
void shouldBuildWithDefaultValues() { | ||
var options = ErrorContextOptions.builder().build(); | ||
|
||
assertAll( | ||
() -> assertThat(options.getDataStoreType()).isEqualTo(DataStoreType.SHARED), | ||
() -> assertThat(options.isAddErrorsResource()).isTrue(), | ||
() -> assertThat(options.isAddGotErrorsResource()).isTrue(), | ||
() -> assertThat(options.isAddHealthCheck()).isTrue(), | ||
() -> assertThat(options.getTimeWindowValue()).isEqualTo(TimeWindow.DEFAULT_TIME_WINDOW_MINUTES), | ||
() -> assertThat(options.getTimeWindowUnit()).isEqualTo(ChronoUnit.MINUTES), | ||
() -> assertThat(options.isAddCleanupJob()).isTrue(), | ||
() -> assertThat(options.getCleanupConfig()).usingRecursiveComparison().isEqualTo(new CleanupConfig()) | ||
); | ||
} | ||
|
||
@Test | ||
void shouldRequireDataStoreType() { | ||
assertThatNullPointerException() | ||
.isThrownBy(() -> ErrorContextOptions.builder().dataStoreType(null).build()); | ||
} | ||
|
||
@Test | ||
void shouldRequireTimeWindowUnit() { | ||
assertThatNullPointerException() | ||
.isThrownBy(() -> ErrorContextOptions.builder().timeWindowUnit(null).build()); | ||
} | ||
} |
Oops, something went wrong.