Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3F59190EF for ; Mon, 26 Dec 2011 21:18:43 +0000 (UTC) Received: (qmail 42479 invoked by uid 500); 26 Dec 2011 21:18:43 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 42426 invoked by uid 500); 26 Dec 2011 21:18:43 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 42419 invoked by uid 99); 26 Dec 2011 21:18:42 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Dec 2011 21:18:42 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Dec 2011 21:18:40 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id C26E723888E7 for ; Mon, 26 Dec 2011 21:18:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1224816 - /commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestNullJNDIEnvironmentValues.java Date: Mon, 26 Dec 2011 21:18:18 -0000 To: commits@commons.apache.org From: oheger@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111226211818.C26E723888E7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: oheger Date: Mon Dec 26 21:18:18 2011 New Revision: 1224816 URL: http://svn.apache.org/viewvc?rev=1224816&view=rev Log: Converted tests to JUnit 4, fixed warnings. Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestNullJNDIEnvironmentValues.java Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestNullJNDIEnvironmentValues.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestNullJNDIEnvironmentValues.java?rev=1224816&r1=1224815&r2=1224816&view=diff ============================================================================== --- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestNullJNDIEnvironmentValues.java (original) +++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestNullJNDIEnvironmentValues.java Mon Dec 26 21:18:18 2011 @@ -17,33 +17,44 @@ package org.apache.commons.configuration; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import java.util.Iterator; -import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; -public class TestNullJNDIEnvironmentValues extends TestCase +public class TestNullJNDIEnvironmentValues { private JNDIConfiguration conf = null; + @Before public void setUp() throws Exception { System.setProperty("java.naming.factory.initial", TestJNDIConfiguration.CONTEXT_FACTORY); - + conf = new JNDIConfiguration(); conf.setThrowExceptionOnMissing(false); } + @Test public void testThrowExceptionOnMissing() { assertFalse("Throw Exception Property is set!", conf.isThrowExceptionOnMissing()); } + @Test public void testSimpleGet() throws Exception { String s = conf.getString("test.key"); assertEquals("jndivalue", s); } + @Test public void testMoreGets() throws Exception { String s = conf.getString("test.key"); @@ -52,39 +63,45 @@ public class TestNullJNDIEnvironmentValu assertEquals(1, conf.getShort("test.short")); } + @Test public void testGetMissingKey() throws Exception { assertNull("Missing Key is not null!", conf.getString("test.imaginarykey")); } + @Test public void testGetMissingKeyWithDefault() throws Exception { String result = conf.getString("test.imaginarykey", "bob"); assertEquals("bob", result); } + @Test public void testContainsKey() throws Exception { assertTrue(conf.containsKey("test.key")); assertTrue(!conf.containsKey("test.imaginarykey")); } - + + @Test public void testClearProperty() { assertNotNull("null short for the 'test.short' key", conf.getShort("test.short", null)); conf.clearProperty("test.short"); assertNull("'test.short' property not cleared", conf.getShort("test.short", null)); } - + + @Test public void testIsEmpty() { assertFalse("the configuration shouldn't be empty", conf.isEmpty()); } - + + @Test public void testGetKeys() throws Exception { boolean found = false; - Iterator it = conf.getKeys(); + Iterator it = conf.getKeys(); assertTrue("no key found", it.hasNext()); @@ -96,17 +113,19 @@ public class TestNullJNDIEnvironmentValu assertTrue("'test.boolean' key not found", found); } + @Test public void testGetKeysWithUnknownPrefix() { // test for a unknown prefix - Iterator it = conf.getKeys("foo.bar"); + Iterator it = conf.getKeys("foo.bar"); assertFalse("no key should be found", it.hasNext()); } + @Test public void testGetKeysWithExistingPrefix() { // test for an existing prefix - Iterator it = conf.getKeys("test"); + Iterator it = conf.getKeys("test"); boolean found = false; while (it.hasNext() && !found) { @@ -116,10 +135,11 @@ public class TestNullJNDIEnvironmentValu assertTrue("'test.boolean' key not found", found); } + @Test public void testGetKeysWithKeyAsPrefix() { // test for a prefix matching exactly the key of a property - Iterator it = conf.getKeys("test.boolean"); + Iterator it = conf.getKeys("test.boolean"); boolean found = false; while (it.hasNext() && !found) { @@ -128,5 +148,4 @@ public class TestNullJNDIEnvironmentValu assertTrue("'test.boolean' key not found", found); } - }