You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2018/10/09 00:13:11 UTC

[text] Better test coverage for the resource bundle string lookup.

Repository: commons-text
Updated Branches:
  refs/heads/master 0226c1319 -> 5fbca7ea4


Better test coverage for the resource bundle string lookup.

Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/5fbca7ea
Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/5fbca7ea
Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/5fbca7ea

Branch: refs/heads/master
Commit: 5fbca7ea4add561a567fb3e2a55bf1e437504844
Parents: 0226c13
Author: Gary Gregory <gg...@rocketsoftware.com>
Authored: Mon Oct 8 18:13:07 2018 -0600
Committer: Gary Gregory <gg...@rocketsoftware.com>
Committed: Mon Oct 8 18:13:07 2018 -0600

----------------------------------------------------------------------
 .../text/lookup/ResourceBundleStringLookup.java |  3 +-
 .../lookup/ResourceBundleStringLookupTest.java  | 32 ++++++++++++++++++--
 2 files changed, 32 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-text/blob/5fbca7ea/src/main/java/org/apache/commons/text/lookup/ResourceBundleStringLookup.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/text/lookup/ResourceBundleStringLookup.java b/src/main/java/org/apache/commons/text/lookup/ResourceBundleStringLookup.java
index 876de18..a5380bf 100644
--- a/src/main/java/org/apache/commons/text/lookup/ResourceBundleStringLookup.java
+++ b/src/main/java/org/apache/commons/text/lookup/ResourceBundleStringLookup.java
@@ -53,7 +53,8 @@ final class ResourceBundleStringLookup extends AbstractStringLookup {
     /**
      * Constructs an instance that only works for the given bundle.
      *
-     * @param bundleName the name of the resource bundle from which we will look keys up.
+     * @param bundleName
+     *            the name of the resource bundle from which we will look keys up.
      * @since 1.5
      */
     ResourceBundleStringLookup(final String bundleName) {

http://git-wip-us.apache.org/repos/asf/commons-text/blob/5fbca7ea/src/test/java/org/apache/commons/text/lookup/ResourceBundleStringLookupTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/text/lookup/ResourceBundleStringLookupTest.java b/src/test/java/org/apache/commons/text/lookup/ResourceBundleStringLookupTest.java
index 0b5c4d9..00370b9 100644
--- a/src/test/java/org/apache/commons/text/lookup/ResourceBundleStringLookupTest.java
+++ b/src/test/java/org/apache/commons/text/lookup/ResourceBundleStringLookupTest.java
@@ -17,6 +17,8 @@
 
 package org.apache.commons.text.lookup;
 
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
 import java.util.ResourceBundle;
 
 import org.junit.jupiter.api.Assertions;
@@ -24,17 +26,43 @@ import org.junit.jupiter.api.Test;
 
 public class ResourceBundleStringLookupTest {
 
+    private static final String TEST_RESOURCE_BUNDLE = "testResourceBundleLookup";
+
     @Test
     public void testAny() {
-        final String bundleName = "testResourceBundleLookup";
+        final String bundleName = TEST_RESOURCE_BUNDLE;
         final String bundleKey = "key";
         Assertions.assertEquals(ResourceBundle.getBundle(bundleName).getString(bundleKey),
                 ResourceBundleStringLookup.INSTANCE.lookup(bundleName + ":" + bundleKey));
     }
 
     @Test
+    public void testBadKey() {
+        final String bundleName = TEST_RESOURCE_BUNDLE;
+        final String bundleKey = "bad_key";
+        assertThrows(IllegalArgumentException.class, () -> {
+            new ResourceBundleStringLookup(bundleName).lookup(bundleKey);
+        });
+        assertThrows(IllegalArgumentException.class, () -> {
+            ResourceBundleStringLookup.INSTANCE.lookup(bundleName + ":" + bundleKey);
+        });
+    }
+
+    @Test
+    public void testName() {
+        assertThrows(IllegalArgumentException.class, () -> {
+            ResourceBundleStringLookup.INSTANCE.lookup("BAD_RESOURCE_BUNDLE_NAME:KEY");
+        });
+    }
+
+    @Test
+    public void testNull() {
+        Assertions.assertNull(ResourceBundleStringLookup.INSTANCE.lookup(null));
+    }
+
+    @Test
     public void testOne() {
-        final String bundleName = "testResourceBundleLookup";
+        final String bundleName = TEST_RESOURCE_BUNDLE;
         final String bundleKey = "key";
         Assertions.assertEquals(ResourceBundle.getBundle(bundleName).getString(bundleKey),
                 new ResourceBundleStringLookup(bundleName).lookup(bundleKey));