diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/JobParameterDataParser.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/JobParameterDataParser.java index 8aab8271c..a26426242 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/JobParameterDataParser.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/JobParameterDataParser.java @@ -27,6 +27,7 @@ import java.util.HashSet; import java.util.Objects; import java.util.Set; import lombok.RequiredArgsConstructor; +import org.apache.commons.lang3.StringUtils; import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper; import org.apache.fineract.infrastructure.jobs.data.JobParameterDTO; import org.springframework.stereotype.Component; @@ -38,7 +39,7 @@ public class JobParameterDataParser { private final FromJsonHelper jsonHelper; public Set parseExecution(String requestBody) { - if (Objects.isNull(requestBody)) { + if (StringUtils.isBlank(requestBody)) { return Collections.emptySet(); } JsonObject element = JsonParser.parseString(requestBody).getAsJsonObject(); diff --git a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/jobs/service/JobParameterDataParserTest.java b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/jobs/service/JobParameterDataParserTest.java new file mode 100644 index 000000000..6a1676edb --- /dev/null +++ b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/jobs/service/JobParameterDataParserTest.java @@ -0,0 +1,48 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.infrastructure.jobs.service; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Collections; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; + +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.LENIENT) +class JobParameterDataParserTest { + + @InjectMocks + private JobParameterDataParser testObj; + + @Test + public void shouldParserReturnsWithEmptyListWhenRequestBodyIsNull() { + assertEquals(Collections.emptySet(), testObj.parseExecution(null)); + } + + @Test + public void shouldParserReturnsWithEmptyListWhenRequestBodyIsEmptyString() { + assertEquals(Collections.emptySet(), testObj.parseExecution("")); + } + +}