Skip to content

Commit c7eaee3

Browse files
committed
feat: basic Constant value provider
1 parent 03ccf3e commit c7eaee3

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

plan.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ in the commit message.
1818

1919
## Fetching data from a constant value provider
2020

21-
- Creating an empty `ConstantValueProvider` should not be possible.
22-
- Test creating a `ConstantValueProvider` with a single String value and getting that value back.
21+
- [x] Creating an empty `ConstantValueProvider` should not be possible.
22+
- [x] Test creating a `ConstantValueProvider` with a single String value and getting that value back.
2323

2424
## Fetching data from a complex object
2525

src/main/java/ru/ewc/decita/core/value/ConstantValueProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
package ru.ewc.decita.core.value;
2626

27+
import java.util.Objects;
2728
import ru.ewc.decisions.api.ComputationContext;
2829

2930
/**
@@ -44,7 +45,7 @@ public final class ConstantValueProvider<T> implements ValueProvider<T> {
4445
* @param value The constant value to be provided.
4546
*/
4647
public ConstantValueProvider(final T value) {
47-
this.value = value;
48+
this.value = Objects.requireNonNull(value, "Constant value cannot be null");
4849
}
4950

5051
@Override

src/test/java/ru/ewc/decita/core/value/ConstantValueProviderTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@
3333
* @since 0.10.0
3434
*/
3535
final class ConstantValueProviderTest {
36-
/**
37-
* A simple test to check that the provider returns the value it was created with.
38-
*/
3936
@Test
4037
void returnsTheValueItWasCreatedWith() {
4138
final var provider = new ConstantValueProvider<>("Hello, World!");
4239
Assertions.assertThat(provider.valueFrom(null)).isEqualTo("Hello, World!");
4340
}
41+
42+
@Test
43+
void doesNotAllowEmptyValue() {
44+
Assertions.assertThatThrownBy(() -> new ConstantValueProvider<>(null))
45+
.isInstanceOf(NullPointerException.class);
46+
}
4447
}

0 commit comments

Comments
 (0)