From 67fcc6f6abb7904ecd4b4444fa23b355cf9fd4ae Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Mon, 24 Jun 2019 15:46:36 -0400 Subject: Fix some sonar issues in policy-endpoints Refactored various classes to reduce cyclomatic complexity. Introduced some endpoint utility classes to facilitate extraction and conversion of property values, and populating of common "builder" values. Change-Id: Ie1c91cd94cb54700dc9127f72780b4d94b82ec39 Issue-ID: POLICY-1791 Signed-off-by: Jim Hahn --- .../event/comm/bus/DmaapTopicPropertyBuilder.java | 4 +- .../event/comm/bus/NoopTopicEndpointTest.java | 5 +- .../event/comm/bus/NoopTopicFactoryTest.java | 3 + .../endpoints/event/comm/bus/TopicTestBase.java | 4 +- .../event/comm/bus/UebTopicPropertyBuilder.java | 4 +- .../event/comm/bus/UebTopicSinkFactoryTest.java | 10 +- .../event/comm/bus/UebTopicSourceFactoryTest.java | 14 ++- .../event/comm/bus/internal/BusConsumerTest.java | 2 +- .../event/comm/bus/internal/BusPublisherTest.java | 20 ++-- .../comm/bus/internal/BusTopicParamsTest.java | 2 +- .../internal/SingleThreadedBusTopicSourceTest.java | 1 + .../SingleThreadedDmaapTopicSourceTest.java | 8 +- .../internal/SingleThreadedUebTopicSourceTest.java | 1 + .../event/comm/bus/internal/TopicBaseTest.java | 1 + .../endpoints/http/server/test/HttpClientTest.java | 4 +- .../endpoints/http/server/test/HttpServerTest.java | 23 ++--- .../endpoints/http/server/test/MyGsonProvider.java | 10 +- .../http/server/test/MyJacksonProvider.java | 10 +- .../endpoints/listeners/JsonListenerTest.java | 4 +- .../endpoints/listeners/ScoListenerTest.java | 4 +- .../common/endpoints/utils/NetLoggerUtilTest.java | 15 +-- .../common/endpoints/utils/PropertyUtilsTest.java | 108 +++++++++++++++++++++ 22 files changed, 197 insertions(+), 60 deletions(-) create mode 100644 policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/PropertyUtilsTest.java (limited to 'policy-endpoints/src/test/java') diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicPropertyBuilder.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicPropertyBuilder.java index 3b63796c..dff3f788 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicPropertyBuilder.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicPropertyBuilder.java @@ -73,7 +73,7 @@ public class DmaapTopicPropertyBuilder extends TopicPropertyBuilder { public static final String MY_SUBCONTEXT = "my-subcontext"; public static final String MY_DME_VERSION = "my-version"; public static final String MY_AAF_MECHID = "my-aaf-mechid"; - public static final String MY_AAF_PASSWD = "my-aaf-passwd"; + public static final String MY_AAF_PASS = "my-aaf-passwd"; /** * Constructs the object. @@ -99,7 +99,7 @@ public class DmaapTopicPropertyBuilder extends TopicPropertyBuilder { setTopicProperty(PROPERTY_MANAGED_SUFFIX, "true"); setTopicProperty(PROPERTY_HTTP_HTTPS_SUFFIX, "true"); setTopicProperty(PROPERTY_TOPIC_AAF_MECHID_SUFFIX, MY_AAF_MECHID); - setTopicProperty(PROPERTY_TOPIC_AAF_PASSWORD_SUFFIX, MY_AAF_PASSWD); + setTopicProperty(PROPERTY_TOPIC_AAF_PASSWORD_SUFFIX, MY_AAF_PASS); setTopicProperty(PROPERTY_DMAAP_DME2_AFT_ENVIRONMENT_SUFFIX, MY_AFT_ENV); setTopicProperty(PROPERTY_ALLOW_SELF_SIGNED_CERTIFICATES_SUFFIX, "true"); setTopicProperty(PROPERTY_TOPIC_API_KEY_SUFFIX, MY_API_KEY); diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicEndpointTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicEndpointTest.java index 5bbc80cd..8e916ba0 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicEndpointTest.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicEndpointTest.java @@ -40,13 +40,14 @@ public abstract class NoopTopicEndpointTest, T ext protected final F factory; protected T endpoint; - protected abstract boolean io(String message); - public NoopTopicEndpointTest(F factory) { this.factory = factory; } + protected abstract boolean io(String message); + @Before + @Override public void setUp() { super.setUp(); this.endpoint = this.factory.build(servers, MY_TOPIC); diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicFactoryTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicFactoryTest.java index 16d9e539..1f7506f8 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicFactoryTest.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicFactoryTest.java @@ -52,6 +52,7 @@ public abstract class NoopTopicFactoryTest, T exte * Creates the object to be tested. */ @Before + @Override public void setUp() { super.setUp(); initFactory(); @@ -164,12 +165,14 @@ public abstract class NoopTopicFactoryTest, T exte } @Test + @Override public void testDestroyString_testGet_testInventory() { super.testDestroyString_testGet_testInventory(); super.testDestroyString_Ex(); } @Test + @Override public void testDestroy() { super.testDestroy(); } diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/TopicTestBase.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/TopicTestBase.java index 326ec042..8b75fa35 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/TopicTestBase.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/TopicTestBase.java @@ -46,7 +46,7 @@ public class TopicTestBase { public static final String MY_LAT = "my-lat"; public static final String MY_LONG = "my-long"; public static final String MY_PARTNER = "my-partner"; - public static final String MY_PASSWD = "my-pass"; + public static final String MY_PASS = "my-pass"; public static final int MY_PORT = 102; public static final String MY_TOPIC = "my-topic"; public static final String MY_EFFECTIVE_TOPIC = "my-effective-topic"; @@ -116,7 +116,7 @@ public class TopicTestBase { .consumerGroup(MY_CONS_GROUP).consumerInstance(MY_CONS_INST).environment(MY_ENV) .fetchLimit(MY_FETCH_LIMIT).fetchTimeout(MY_FETCH_TIMEOUT).hostname(MY_HOST).latitude(MY_LAT) .longitude(MY_LONG).managed(true).partitionId(MY_PARTITION).partner(MY_PARTNER) - .password(MY_PASSWD).port(MY_PORT).servers(servers).topic(MY_TOPIC) + .password(MY_PASS).port(MY_PORT).servers(servers).topic(MY_TOPIC) .effectiveTopic(MY_EFFECTIVE_TOPIC).useHttps(true).userName(MY_USERNAME); } } diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicPropertyBuilder.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicPropertyBuilder.java index 3ac7d9ae..6119284f 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicPropertyBuilder.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicPropertyBuilder.java @@ -51,7 +51,7 @@ public class UebTopicPropertyBuilder extends TopicPropertyBuilder { public static final String TOPIC2 = "my-topic-2"; public static final String MY_AAF_MECHID = "my-aaf-mechid"; - public static final String MY_AAF_PASSWD = "my-aaf-passwd"; + public static final String MY_AAF_PASS = "my-aaf-passwd"; /** * Constructs the object. @@ -77,7 +77,7 @@ public class UebTopicPropertyBuilder extends TopicPropertyBuilder { setTopicProperty(PROPERTY_MANAGED_SUFFIX, "true"); setTopicProperty(PROPERTY_HTTP_HTTPS_SUFFIX, "true"); setTopicProperty(PROPERTY_TOPIC_AAF_MECHID_SUFFIX, MY_AAF_MECHID); - setTopicProperty(PROPERTY_TOPIC_AAF_PASSWORD_SUFFIX, MY_AAF_PASSWD); + setTopicProperty(PROPERTY_TOPIC_AAF_PASSWORD_SUFFIX, MY_AAF_PASS); setTopicProperty(PROPERTY_DMAAP_DME2_AFT_ENVIRONMENT_SUFFIX, MY_AFT_ENV); setTopicProperty(PROPERTY_ALLOW_SELF_SIGNED_CERTIFICATES_SUFFIX, "true"); setTopicProperty(PROPERTY_TOPIC_API_KEY_SUFFIX, MY_API_KEY); diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicSinkFactoryTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicSinkFactoryTest.java index 10d61f60..4896a9df 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicSinkFactoryTest.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicSinkFactoryTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-endpoints * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,6 +41,7 @@ public class UebTopicSinkFactoryTest extends UebTopicFactoryTestBase params2.getFetchLimit() == UebTopicSource.DEFAULT_LIMIT_FETCH, null, "", "invalid-limit-number"); - + checkDefault(PROPERTY_TOPIC_SOURCE_FETCH_TIMEOUT_SUFFIX, params2 -> params2.getFetchTimeout() == UebTopicSource.DEFAULT_TIMEOUT_MS_FETCH, null, "", "invalid-timeout-number"); @@ -100,6 +103,7 @@ public class UebTopicSourceFactoryTest extends UebTopicFactoryTestBase http(portUrl + SWAGGER_JSON)).isInstanceOf(IOException.class); response = http(portUrl + "/junit/echo/hello?block=true"); assertEquals("FILTERED", response); @@ -311,13 +310,7 @@ public class HttpServerTest { response = http(LOCALHOST_PREFIX + port2 + JUNIT_ECHO_HELLO); assertTrue(HELLO.equals(response)); - response = null; - try { - response = http(LOCALHOST_PREFIX + port2 + SWAGGER_JSON); - } catch (IOException e) { - // Expected - } - assertTrue(response == null); + assertThatThrownBy(() -> http(LOCALHOST_PREFIX + port2 + SWAGGER_JSON)).isInstanceOf(IOException.class); HttpServletServer.factory.destroy(); assertTrue(HttpServletServer.factory.inventory().isEmpty()); diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/MyGsonProvider.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/MyGsonProvider.java index 286d73dc..8343d02d 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/MyGsonProvider.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/MyGsonProvider.java @@ -27,13 +27,19 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Type; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; +import lombok.AccessLevel; +import lombok.Setter; import org.onap.policy.common.gson.GsonMessageBodyHandler; /** * GsonMessageBodyHandler that tracks activities. */ public class MyGsonProvider extends GsonMessageBodyHandler { + + @Setter(AccessLevel.PRIVATE) private static boolean readSome = false; + + @Setter(AccessLevel.PRIVATE) private static boolean wroteSome = false; /** @@ -48,7 +54,7 @@ public class MyGsonProvider extends GsonMessageBodyHandler { public Object readFrom(Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, InputStream entityStream) throws IOException { - readSome = true; + setReadSome(true); return super.readFrom(type, genericType, annotations, mediaType, httpHeaders, entityStream); } @@ -56,7 +62,7 @@ public class MyGsonProvider extends GsonMessageBodyHandler { public void writeTo(Object object, Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, OutputStream entityStream) throws IOException { - wroteSome = true; + setWroteSome(true); super.writeTo(object, type, genericType, annotations, mediaType, httpHeaders, entityStream); } diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/MyJacksonProvider.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/MyJacksonProvider.java index 07062451..55efd8bb 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/MyJacksonProvider.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/MyJacksonProvider.java @@ -28,12 +28,18 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Type; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; +import lombok.AccessLevel; +import lombok.Setter; /** * JacksonJsonProvider that tracks activities. */ public class MyJacksonProvider extends JacksonJsonProvider { + + @Setter(AccessLevel.PRIVATE) private static boolean readSome = false; + + @Setter(AccessLevel.PRIVATE) private static boolean wroteSome = false; /** @@ -48,7 +54,7 @@ public class MyJacksonProvider extends JacksonJsonProvider { public Object readFrom(Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, InputStream entityStream) throws IOException { - readSome = true; + setReadSome(true); return super.readFrom(type, genericType, annotations, mediaType, httpHeaders, entityStream); } @@ -56,7 +62,7 @@ public class MyJacksonProvider extends JacksonJsonProvider { public void writeTo(Object object, Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, OutputStream entityStream) throws IOException { - wroteSome = true; + setWroteSome(true); super.writeTo(object, type, genericType, annotations, mediaType, httpHeaders, entityStream); } diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/JsonListenerTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/JsonListenerTest.java index 39fc9d8f..c2ef4eba 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/JsonListenerTest.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/JsonListenerTest.java @@ -86,7 +86,9 @@ public class JsonListenerTest { primary = new JsonListener() { @Override - public void onTopicEvent(CommInfrastructure infra, String topic, StandardCoderObject sco) {} + public void onTopicEvent(CommInfrastructure infra, String topic, StandardCoderObject sco) { + // do nothing + } }; } diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/ScoListenerTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/ScoListenerTest.java index 0749f891..4d10c65e 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/ScoListenerTest.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/ScoListenerTest.java @@ -93,7 +93,9 @@ public class ScoListenerTest { primary = new ScoListener(MyMessage.class) { @Override public void onTopicEvent(CommInfrastructure infra, String topic, StandardCoderObject sco, - MyMessage message) {} + MyMessage message) { + // do nothing + } }; } diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/NetLoggerUtilTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/NetLoggerUtilTest.java index 6e84c137..2860377e 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/NetLoggerUtilTest.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/NetLoggerUtilTest.java @@ -39,6 +39,7 @@ import org.slf4j.Logger; */ public class NetLoggerUtilTest { + private static final String TEST_TOPIC = "test-topic"; private static final String MESSAGE = "hello world!"; /** * Test feature used for junits. @@ -76,7 +77,7 @@ public class NetLoggerUtilTest { */ @Test public void logTest() { - NetLoggerUtil.log(EventType.IN, CommInfrastructure.NOOP, "test-topic", MESSAGE); + NetLoggerUtil.log(EventType.IN, CommInfrastructure.NOOP, TEST_TOPIC, MESSAGE); assertEquals(3, TestAppender.events.size()); } @@ -85,7 +86,7 @@ public class NetLoggerUtilTest { */ @Test public void logDefaultTest() { - NetLoggerUtil.log(null, EventType.IN, CommInfrastructure.NOOP, "test-topic", MESSAGE); + NetLoggerUtil.log(null, EventType.IN, CommInfrastructure.NOOP, TEST_TOPIC, MESSAGE); assertEquals(3, TestAppender.events.size()); assertEquals("network", TestAppender.events.get(0).getLoggerName()); } @@ -96,7 +97,7 @@ public class NetLoggerUtilTest { @Test public void beforeLogReturnTrueTest() { netLoggerFeature.setReturnValue(true, false); - NetLoggerUtil.log(null, EventType.IN, CommInfrastructure.NOOP, "test-topic", MESSAGE); + NetLoggerUtil.log(null, EventType.IN, CommInfrastructure.NOOP, TEST_TOPIC, MESSAGE); assertEquals(1, TestAppender.events.size()); } @@ -106,7 +107,7 @@ public class NetLoggerUtilTest { @Test public void afterLogReturnTrueTest() { netLoggerFeature.setReturnValue(false, true); - NetLoggerUtil.log(null, EventType.IN, CommInfrastructure.NOOP, "test-topic", MESSAGE); + NetLoggerUtil.log(null, EventType.IN, CommInfrastructure.NOOP, TEST_TOPIC, MESSAGE); assertEquals(3, TestAppender.events.size()); } @@ -116,7 +117,7 @@ public class NetLoggerUtilTest { @Test public void beforeLogExceptionTest() { netLoggerFeature.setExceptions(true, false); - NetLoggerUtil.log(null, EventType.IN, CommInfrastructure.NOOP, "test-topic", MESSAGE); + NetLoggerUtil.log(null, EventType.IN, CommInfrastructure.NOOP, TEST_TOPIC, MESSAGE); assertEquals(2, TestAppender.events.size()); } @@ -126,7 +127,7 @@ public class NetLoggerUtilTest { @Test public void afterLogExceptionTest() { netLoggerFeature.setExceptions(false, true); - NetLoggerUtil.log(null, EventType.IN, CommInfrastructure.NOOP, "test-topic", MESSAGE); + NetLoggerUtil.log(null, EventType.IN, CommInfrastructure.NOOP, TEST_TOPIC, MESSAGE); assertEquals(2, TestAppender.events.size()); } @@ -139,7 +140,7 @@ public class NetLoggerUtilTest { /** * List of logged events. */ - public static List events = new ArrayList<>(); + private static final List events = new ArrayList<>(); /** * Called after every unit test to clear list of events. diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/PropertyUtilsTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/PropertyUtilsTest.java new file mode 100644 index 00000000..048a3902 --- /dev/null +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/PropertyUtilsTest.java @@ -0,0 +1,108 @@ +/* + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.common.endpoints.utils; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.Properties; +import org.junit.Before; +import org.junit.Test; + +public class PropertyUtilsTest { + private static final String DFLT_STRING = "my-default"; + private static final int DLFT_INT = 1000; + + private PropertyUtils utils; + private String invalidName; + private String invalidValue; + private Exception invalidEx; + + /** + * Initializes {@link #utils}. + */ + @Before + public void setUp() { + Properties properties = new Properties(); + properties.put("myPrefix.my-string", "some text"); + properties.put("myPrefix.empty-string", ""); + + properties.put("myPrefix.my-bool", "true"); + properties.put("myPrefix.my-bool2", "false"); + properties.put("myPrefix.empty-bool", ""); + properties.put("myPrefix.invalid-bool", "not a bool"); + + properties.put("myPrefix.my-int", "100"); + properties.put("myPrefix.my-int2", "200"); + properties.put("myPrefix.empty-int", ""); + properties.put("myPrefix.invalid-int", "not an int"); + + utils = new PropertyUtils(properties, "myPrefix", (name, value, ex) -> { + invalidName = name; + invalidValue = value; + invalidEx = ex; + }); + } + + @Test + public void testGetString() { + assertEquals("some text", utils.getString(".my-string", DFLT_STRING)); + assertEquals(DFLT_STRING, utils.getString(".empty-string", DFLT_STRING)); + assertEquals(DFLT_STRING, utils.getString(".missing-string", DFLT_STRING)); + + assertNull(invalidName); + assertNull(invalidValue); + assertNull(invalidEx); + } + + @Test + public void testGetBoolean() { + assertEquals(true, utils.getBoolean(".my-bool", false)); + assertEquals(false, utils.getBoolean(".my-bool2", true)); + assertEquals(true, utils.getBoolean(".empty-bool", true)); + assertEquals(false, utils.getBoolean(".invalid-bool", true)); + assertEquals(true, utils.getBoolean(".missing-bool", true)); + + assertNull(invalidName); + assertNull(invalidValue); + assertNull(invalidEx); + } + + @Test + public void testGetInteger() { + assertEquals(100, utils.getInteger(".my-int", DLFT_INT)); + assertEquals(200, utils.getInteger(".my-int2", DLFT_INT)); + assertEquals(DLFT_INT, utils.getInteger(".empty-int", DLFT_INT)); + assertEquals(DLFT_INT, utils.getInteger(".missing-int", DLFT_INT)); + + assertNull(invalidName); + assertNull(invalidValue); + assertNull(invalidEx); + + assertEquals(DLFT_INT, utils.getInteger(".invalid-int", DLFT_INT)); + + assertEquals("myPrefix.invalid-int", invalidName); + assertEquals("not an int", invalidValue); + assertTrue(invalidEx instanceof NumberFormatException); + } + +} -- cgit 1.2.3-korg