From f336788e71ec5cb5a3cf1fe51481649042030371 Mon Sep 17 00:00:00 2001 From: Simon Kitching Date: Mon, 27 Feb 2006 03:07:41 +0000 Subject: [PATCH] Add Serializable tests for NoOpLog. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@381239 13f79535-47bb-0310-9956-ffa450edef68 --- .../commons/logging/noop/NoOpLogTestCase.java | 66 ++++++++++++++++++- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/src/test/org/apache/commons/logging/noop/NoOpLogTestCase.java b/src/test/org/apache/commons/logging/noop/NoOpLogTestCase.java index ed1a52b..4a9ef2c 100644 --- a/src/test/org/apache/commons/logging/noop/NoOpLogTestCase.java +++ b/src/test/org/apache/commons/logging/noop/NoOpLogTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2001-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,13 @@ package org.apache.commons.logging.noop; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; + import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.impl.NoOpLog; import org.apache.commons.logging.AbstractLogTest; @@ -27,8 +33,25 @@ import org.apache.commons.logging.AbstractLogTest; */ public class NoOpLogTestCase extends AbstractLogTest { + /** + * Set up instance variables required by this test case. + */ + public void setUp() throws Exception { + LogFactory.releaseAll(); - /** + System.setProperty( + "org.apache.commons.logging.Log", + "org.apache.commons.logging.impl.NoOpLog"); + } + + /** + * Tear down instance variables required by this test case. + */ + public void tearDown() { + LogFactory.releaseAll(); + } + + /** * Override the abstract method from the parent class so that the * inherited tests can access the right Log object type. */ @@ -36,4 +59,43 @@ public class NoOpLogTestCase extends AbstractLogTest { return (Log) new NoOpLog(this.getClass().getName()); } + + // Test Serializability of standard instance + public void testSerializable() throws Exception { + Log log = LogFactory.getLog(this.getClass().getName()); + checkLog(log); + + // Serialize and deserialize the instance + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos); + oos.writeObject(log); + oos.close(); + ByteArrayInputStream bais = + new ByteArrayInputStream(baos.toByteArray()); + ObjectInputStream ois = new ObjectInputStream(bais); + log = (Log) ois.readObject(); + ois.close(); + + checkLog(log); + } + + + // -------------------------------------------------------- Support Methods + + private void checkLog(Log log) { + + assertNotNull("Log exists", log); + assertEquals("Log class", + "org.apache.commons.logging.impl.NoOpLog", + log.getClass().getName()); + + // Can we call level checkers with no exceptions? + // Note that *everything* is permanently disabled for NoOpLog + assertFalse(log.isTraceEnabled()); + assertFalse(log.isDebugEnabled()); + assertFalse(log.isInfoEnabled()); + assertFalse(log.isWarnEnabled()); + assertFalse(log.isErrorEnabled()); + assertFalse(log.isFatalEnabled()); + } }