From 5749a90177a6719d3326a145aa5bf9c74f16b458 Mon Sep 17 00:00:00 2001 From: "T.Aathman" Date: Fri, 26 Apr 2019 20:25:38 +0530 Subject: [PATCH] feat : Null pointer exception and program crash when configuration values are not given in the yml file --- sources/payment-hub/pom.xml | 19 ++++++++ .../src/main/java/hu/HubSettingsTest.java | 44 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 sources/payment-hub/src/main/java/hu/HubSettingsTest.java diff --git a/sources/payment-hub/pom.xml b/sources/payment-hub/pom.xml index 81439a6..cda7d92 100644 --- a/sources/payment-hub/pom.xml +++ b/sources/payment-hub/pom.xml @@ -149,6 +149,25 @@ interop-ilp-conditions 1.3 + + junit + junit + test + + + junit + junit + + + org.springframework + spring-test + 5.1.2.RELEASE + compile + + + org.springframework.boot + spring-boot-test + diff --git a/sources/payment-hub/src/main/java/hu/HubSettingsTest.java b/sources/payment-hub/src/main/java/hu/HubSettingsTest.java new file mode 100644 index 0000000..14abf74 --- /dev/null +++ b/sources/payment-hub/src/main/java/hu/HubSettingsTest.java @@ -0,0 +1,44 @@ +package hu; + +import hu.dpc.rt.psp.config.HubSettings; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.junit.Assert.*; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = { HubSettingsTest.TestConfiguration.class }) +public class HubSettingsTest { + + @Autowired + private HubSettings hubSettings; + + @Test + public void getInstance() { + assertEquals("in01",hubSettings.getInstance()); + } + + @Test + public void getExpiration() { + assertEquals("30000",hubSettings.getExpiration().toString()); + } + + @Test + public void getTenants_0() { + assertEquals("tn03",hubSettings.getTenants().get(0)); + } + + @Test + public void getTenants_1() { + assertEquals("tn04",hubSettings.getTenants().get(1)); + } + + @EnableConfigurationProperties(HubSettings.class) + public static class TestConfiguration { + // nothing + } +} \ No newline at end of file