harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jessewil...@apache.org
Subject svn commit: r1004471 - in /harmony/enhanced/java/trunk/classlib/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging: HandlerTest.java LoggerTest.java
Date Mon, 04 Oct 2010 22:59:24 GMT
Author: jessewilson
Date: Mon Oct  4 22:59:23 2010
New Revision: 1004471

URL: http://svn.apache.org/viewvc?rev=1004471&view=rev
Log:
Isolate logging behavior tests from logging+security tests. Necessary to run the tests in
a VM where installing an alternate security manager is not allowed.

Modified:
    harmony/enhanced/java/trunk/classlib/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/HandlerTest.java
    harmony/enhanced/java/trunk/classlib/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggerTest.java

Modified: harmony/enhanced/java/trunk/classlib/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/HandlerTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/HandlerTest.java?rev=1004471&r1=1004470&r2=1004471&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/HandlerTest.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/HandlerTest.java
Mon Oct  4 22:59:23 2010
@@ -497,23 +497,25 @@ public class HandlerTest extends TestCas
 	public void testReportError() {
 		MockHandler h = new MockHandler();
 		h.setErrorManager(new MockErrorManager());
-		SecurityManager oldMan = System.getSecurityManager();
-		System.setSecurityManager(new MockSecurityManager());
 
+        Exception ex = new Exception("test exception");
+        // with non-null parameters
+        h.reportError("test msg", ex, -1);
+        assertEquals(-1, CallVerificationStack.getInstance().popInt());
+        assertSame(ex, CallVerificationStack.getInstance().pop());
+        assertEquals("test msg", CallVerificationStack.getInstance().pop());
+        // with null parameters
+        h.reportError(null, null, 0);
+        assertEquals(0, CallVerificationStack.getInstance().popInt());
+        assertSame(null, CallVerificationStack.getInstance().pop());
+        assertNull(CallVerificationStack.getInstance().pop());
+	}
+
+	public void testReportErrorWithSecurityManager() {
+        SecurityManager oldMan = System.getSecurityManager();
+		System.setSecurityManager(new MockSecurityManager());
 		try {
-			Exception ex = new Exception("test exception");
-			// with non-null parameters
-			h.reportError("test msg", ex, -1);
-			assertEquals(-1, CallVerificationStack.getInstance().popInt());
-			assertSame(ex, CallVerificationStack.getInstance().pop());
-			assertEquals("test msg", CallVerificationStack.getInstance().pop());
-			// with null parameters
-			h.reportError(null, null, 0);
-			assertEquals(0, CallVerificationStack.getInstance().popInt());
-			assertSame(null, CallVerificationStack.getInstance().pop());
-			assertNull(CallVerificationStack.getInstance().pop());
-		} catch (SecurityException e) {
-			fail("Should not throw SecurityException!");
+            testReportError();
 		} finally {
 			System.setSecurityManager(oldMan);
 		}

Modified: harmony/enhanced/java/trunk/classlib/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggerTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggerTest.java?rev=1004471&r1=1004470&r2=1004471&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggerTest.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggerTest.java
Mon Oct  4 22:59:23 2010
@@ -182,22 +182,23 @@ public class LoggerTest extends TestCase
 	 * Test getAnonymousLogger()
 	 */
 	public void testGetAnonymousLogger() {
+        Logger alog = Logger.getAnonymousLogger();
+        assertNotSame(alog, Logger.getAnonymousLogger());
+        assertNull(alog.getFilter());
+        assertEquals(0, alog.getHandlers().length);
+        assertNull(alog.getLevel());
+        assertNull(alog.getName());
+        assertNull(alog.getParent().getParent());
+        assertNull(alog.getResourceBundle());
+        assertNull(alog.getResourceBundleName());
+        assertTrue(alog.getUseParentHandlers());
+	}
+
+	public void testGetAnonymousLoggerWithSecurityManager() {
 		SecurityManager oldMan = System.getSecurityManager();
 		System.setSecurityManager(new MockSecurityManager());
-
 		try {
-			Logger alog = Logger.getAnonymousLogger();
-			assertNotSame(alog, Logger.getAnonymousLogger());
-			assertNull(alog.getFilter());
-			assertEquals(0, alog.getHandlers().length);
-			assertNull(alog.getLevel());
-			assertNull(alog.getName());
-			assertNull(alog.getParent().getParent());
-			assertNull(alog.getResourceBundle());
-			assertNull(alog.getResourceBundleName());
-			assertTrue(alog.getUseParentHandlers());
-			// fail("Should throw SecurityException!");
-			// } catch (SecurityException e) {
+            testGetAnonymousLogger();
 		} finally {
 			System.setSecurityManager(oldMan);
 		}
@@ -3399,17 +3400,16 @@ public class LoggerTest extends TestCase
 	/*
 	 * Test whether privileged code is used to load resource bundles.
 	 */
-	public void testLoadResourceBundle() {
-        // 
+	public void testLoadResourceBundleWithSecurityManager() {
 		SecurityManager oldMan = System.getSecurityManager();
 		System.setSecurityManager(new MockNoLoadingClassSecurityManager());
 		try {
-			Logger.getAnonymousLogger(VALID_RESOURCE_BUNDLE);
+            Logger.getAnonymousLogger(VALID_RESOURCE_BUNDLE);
 		} finally {
 			System.setSecurityManager(oldMan);
 		}
 	}
-    
+
     public void testLoadResourceBundleNonExistent() {
         try {
             // Try a load a non-existent resource bundle.
@@ -3425,38 +3425,35 @@ public class LoggerTest extends TestCase
      * @tests java.util.logging.Logger#logrb(Level, String, String, String,
      *        String, Object)
      */
-    public void test_init_logger()
-            throws Exception {
+    public void test_init_logger() throws Exception {
         Properties p = new Properties();
         p.put("testGetLogger_Normal_ANewLogger2.level", "ALL");
         LogManager.getLogManager().readConfiguration(
                 EnvironmentHelper.PropertiesToInputStream(p));
-
         assertNull(LogManager.getLogManager().getLogger(
                 "testGetLogger_Normal_ANewLogger2"));
+    }
+    
+    public void test_init_loggerWithSecurityManager() throws Exception {
         SecurityManager originalSecurityManager = System.getSecurityManager();
+        System.setSecurityManager(new SecurityManager());
         try {
-            System.setSecurityManager(new SecurityManager());
-            // should not throw expection
             Logger logger = Logger.getLogger("testGetLogger_Normal_ANewLogger2");
-            // should thrpw exception
             try{
                 logger.setLevel(Level.ALL);
                 fail("should throw SecurityException");
-            } catch (SecurityException e){
-                // expected
+            } catch (SecurityException expected) {
             }
             try{
                 logger.setParent(Logger.getLogger("root"));
                 fail("should throw SecurityException");
-            } catch (SecurityException e){
-                // expected
+            } catch (SecurityException expected) {
             }
         } finally {
             System.setSecurityManager(originalSecurityManager);
         }
     }
-    
+
     /*
      * test initHandler
      */



Mime
View raw message