Skip to content

Commit 8749528

Browse files
aepfliclaude
andcommitted
fix: Update API tests to use builder pattern instead of private constructors
Updated test classes to use the new immutable POJO design: ## Test Updates - **ProviderEvaluationTest**: Updated both `empty()` and `builderWithAllFields()` tests to use builder pattern - **FlagEvaluationDetailsTest**: Updated both `empty()` and `builderWithAllFields()` tests to use builder pattern - Applied Spotless formatting fixes for consistent code style ## Results - ✅ All 80 tests now passing - ✅ Checkstyle compliance maintained - ✅ SpotBugs issues resolved - ✅ Full verification pipeline passes The tests now properly demonstrate the intended usage pattern where POJOs can only be created through builders, enforcing immutability and consistency. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> Signed-off-by: Simon Schrottner <[email protected]>
1 parent 62e080d commit 8749528

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

openfeature-api/src/main/java/dev/openfeature/api/FlagEvaluationDetails.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,37 +59,30 @@ public String getFlagKey() {
5959
return flagKey;
6060
}
6161

62-
6362
public T getValue() {
6463
return value;
6564
}
6665

67-
6866
public String getVariant() {
6967
return variant;
7068
}
7169

72-
7370
public String getReason() {
7471
return reason;
7572
}
7673

77-
7874
public ErrorCode getErrorCode() {
7975
return errorCode;
8076
}
8177

82-
8378
public String getErrorMessage() {
8479
return errorMessage;
8580
}
8681

87-
8882
public ImmutableMetadata getFlagMetadata() {
8983
return flagMetadata;
9084
}
9185

92-
9386
public static <T> Builder<T> builder() {
9487
return new Builder<>();
9588
}

openfeature-api/src/main/java/dev/openfeature/api/ProviderEvaluation.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,32 +53,26 @@ public T getValue() {
5353
return value;
5454
}
5555

56-
5756
public String getVariant() {
5857
return variant;
5958
}
6059

61-
6260
public String getReason() {
6361
return reason;
6462
}
6563

66-
6764
public ErrorCode getErrorCode() {
6865
return errorCode;
6966
}
7067

71-
7268
public String getErrorMessage() {
7369
return errorMessage;
7470
}
7571

76-
7772
public ImmutableMetadata getFlagMetadata() {
7873
return flagMetadata;
7974
}
8075

81-
8276
public static <T> Builder<T> builder() {
8377
return new Builder<>();
8478
}

openfeature-api/src/test/java/dev/openfeature/api/FlagEvaluationDetailsTest.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
class FlagEvaluationDetailsTest {
1010

1111
@Test
12-
@DisplayName("Should have empty constructor")
12+
@DisplayName("Should create empty evaluation details with builder")
1313
public void empty() {
14-
FlagEvaluationDetails<Integer> details = new FlagEvaluationDetails<Integer>();
14+
FlagEvaluationDetails<Integer> details =
15+
FlagEvaluationDetails.<Integer>builder().build();
1516
assertNotNull(details);
1617
}
1718

1819
@Test
19-
@DisplayName("Should have flagKey, value, variant, reason, errorCode, errorMessage, metadata constructor")
20-
// removeing this constructor is a breaking change!
21-
public void sevenArgConstructor() {
20+
@DisplayName("Should create evaluation details with all fields using builder")
21+
public void builderWithAllFields() {
2222

2323
String flagKey = "my-flag";
2424
Integer value = 100;
@@ -28,8 +28,15 @@ public void sevenArgConstructor() {
2828
String errorMessage = "message";
2929
ImmutableMetadata metadata = ImmutableMetadata.builder().build();
3030

31-
FlagEvaluationDetails<Integer> details = new FlagEvaluationDetails<>(
32-
flagKey, value, variant, reason.toString(), errorCode, errorMessage, metadata);
31+
FlagEvaluationDetails<Integer> details = FlagEvaluationDetails.<Integer>builder()
32+
.flagKey(flagKey)
33+
.value(value)
34+
.variant(variant)
35+
.reason(reason.toString())
36+
.errorCode(errorCode)
37+
.errorMessage(errorMessage)
38+
.flagMetadata(metadata)
39+
.build();
3340

3441
assertEquals(flagKey, details.getFlagKey());
3542
assertEquals(value, details.getValue());

openfeature-api/src/test/java/dev/openfeature/api/ProviderEvaluationTest.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
class ProviderEvaluationTest {
1010

1111
@Test
12-
@DisplayName("Should have empty constructor")
12+
@DisplayName("Should create empty evaluation with builder")
1313
public void empty() {
14-
ProviderEvaluation<Integer> details = new ProviderEvaluation<Integer>();
14+
ProviderEvaluation<Integer> details =
15+
ProviderEvaluation.<Integer>builder().build();
1516
assertNotNull(details);
1617
}
1718

1819
@Test
19-
@DisplayName("Should have value, variant, reason, errorCode, errorMessage, metadata constructor")
20-
// removeing this constructor is a breaking change!
21-
public void sixArgConstructor() {
20+
@DisplayName("Should create evaluation with all fields using builder")
21+
public void builderWithAllFields() {
2222

2323
Integer value = 100;
2424
String variant = "1-hundred";
@@ -27,8 +27,14 @@ public void sixArgConstructor() {
2727
String errorMessage = "message";
2828
ImmutableMetadata metadata = ImmutableMetadata.builder().build();
2929

30-
ProviderEvaluation<Integer> details =
31-
new ProviderEvaluation<>(value, variant, reason.toString(), errorCode, errorMessage, metadata);
30+
ProviderEvaluation<Integer> details = ProviderEvaluation.<Integer>builder()
31+
.value(value)
32+
.variant(variant)
33+
.reason(reason.toString())
34+
.errorCode(errorCode)
35+
.errorMessage(errorMessage)
36+
.flagMetadata(metadata)
37+
.build();
3238

3339
assertEquals(value, details.getValue());
3440
assertEquals(variant, details.getVariant());

0 commit comments

Comments
 (0)