Skip to content

Commit

Permalink
FIX: null validation
Browse files Browse the repository at this point in the history
Signed-off-by: George Chen <[email protected]>
  • Loading branch information
chenqi0805 committed Aug 22, 2023
1 parent 79f20cf commit 50f8e0d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import javax.inject.Inject;
import javax.inject.Named;
import java.time.Duration;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -49,7 +50,8 @@ public Object convert(final Class<?> extensionPluginConfigurationType, final Str
final Object configuration = convertSettings(extensionPluginConfigurationType,
extensionProperties.get(rootKey));

final Set<ConstraintViolation<Object>> constraintViolations = validator.validate(configuration);
final Set<ConstraintViolation<Object>> constraintViolations = configuration == null ? Collections.emptySet() :
validator.validate(configuration);

if (!constraintViolations.isEmpty()) {
final String violationsString = constraintViolations.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ void convert_with_test_extension_with_config() {

@Test
void convert_with_null_rootKey_value_should_return_null() {
when(validator.validate(any())).thenReturn(Collections.emptySet());
when(pipelinesDataFlowModel.getPipelineExtensions()).thenReturn(pipelineExtensions);
final String rootKey = "test_extension";
when(pipelineExtensions.getExtensionMap()).thenReturn(Collections.emptyMap());
Expand All @@ -86,7 +85,9 @@ void convert_with_null_rootKey_value_should_return_null() {

@Test
void convert_should_throw_exception_when_there_are_constraint_violations() {
when(pipelinesDataFlowModel.getPipelineExtensions()).thenReturn(pipelineExtensions);
final String rootKey = UUID.randomUUID().toString();
when(pipelineExtensions.getExtensionMap()).thenReturn(Map.of(rootKey, Collections.emptyMap()));
final String errorMessage = UUID.randomUUID().toString();
given(constraintViolation.getMessage()).willReturn(errorMessage);
final String propertyPathString = UUID.randomUUID().toString();
Expand Down

0 comments on commit 50f8e0d

Please sign in to comment.