1 17 package org.apache.log.test; 18 19 import junit.framework.TestCase; 20 import org.apache.log.LogEvent; 21 import org.apache.log.LogTarget; 22 import org.apache.log.output.AbstractWrappingTarget; 23 import org.apache.log.util.Closeable; 24 25 30 public final class WrappingTargetTestCase 31 extends TestCase 32 { 33 public WrappingTargetTestCase(String name) 34 { 35 super(name); 36 } 37 38 static private class DummyTarget implements LogTarget 39 { 40 private boolean closed = false; 41 42 public void close() 43 { 44 closed = true; 45 } 46 47 public boolean isClosed() 48 { 49 return closed; 50 } 51 52 public void processEvent( LogEvent event ) 53 { 54 } 56 } 57 58 static private class CloseableDummyTarget extends DummyTarget implements Closeable 59 { 60 } 61 62 static private class DummyTargetWrapper extends AbstractWrappingTarget 63 { 64 public DummyTargetWrapper( final LogTarget logTarget ) 65 { 66 super( logTarget ); 67 } 68 69 public DummyTargetWrapper( final LogTarget logTarget, final boolean closeWrappedTarget ) 70 { 71 super( logTarget, closeWrappedTarget ); 72 } 73 74 public void doProcessEvent( LogEvent event ) 75 { 76 } 78 } 79 80 public void testNonCloseable() 81 { 82 DummyTarget dummyTargetNonClose = new DummyTarget(); 83 DummyTarget dummyTargetNonClose2 = new DummyTarget(); 84 DummyTarget dummyTargetClose = new DummyTarget(); 85 86 DummyTargetWrapper wrapperNonClose = new DummyTargetWrapper(dummyTargetNonClose, false); 87 DummyTargetWrapper wrapperNonClose2 = new DummyTargetWrapper(dummyTargetNonClose2); DummyTargetWrapper wrapperClose = new DummyTargetWrapper(dummyTargetClose, true); 89 90 assertTrue( !dummyTargetNonClose.isClosed() ); 91 assertTrue( !dummyTargetNonClose2.isClosed() ); 92 assertTrue( !dummyTargetClose.isClosed() ); 93 94 wrapperNonClose.close(); 95 wrapperNonClose2.close(); 96 wrapperClose.close(); 97 98 100 assertTrue( !dummyTargetNonClose.isClosed() ); 101 assertTrue( !dummyTargetNonClose2.isClosed() ); 102 assertTrue( !dummyTargetClose.isClosed() ); 103 } 104 105 public void testCloseable() 106 { 107 DummyTarget dummyTargetNonClose = new CloseableDummyTarget(); 108 DummyTarget dummyTargetNonClose2 = new CloseableDummyTarget(); 109 DummyTarget dummyTargetClose = new CloseableDummyTarget(); 110 111 DummyTargetWrapper wrapperNonClose = new DummyTargetWrapper(dummyTargetNonClose, false); 112 DummyTargetWrapper wrapperNonClose2 = new DummyTargetWrapper(dummyTargetNonClose2); DummyTargetWrapper wrapperClose = new DummyTargetWrapper(dummyTargetClose, true); 114 115 assertTrue( !dummyTargetNonClose.isClosed() ); 116 assertTrue( !dummyTargetNonClose2.isClosed() ); 117 assertTrue( !dummyTargetClose.isClosed() ); 118 119 wrapperNonClose.close(); 120 wrapperNonClose2.close(); 121 wrapperClose.close(); 122 123 126 assertTrue( !dummyTargetNonClose.isClosed() ); 127 assertTrue( !dummyTargetNonClose2.isClosed() ); 128 assertTrue( dummyTargetClose.isClosed() ); 129 } 130 } 131 | Popular Tags |