1 19 20 package org.apache.excalibur.instrument.test; 21 22 import junit.framework.TestCase; 23 24 import org.apache.excalibur.instrument.CounterInstrument; 25 26 32 public class CounterInstrumentTestCase 33 extends TestCase 34 { 35 38 public CounterInstrumentTestCase( String name ) 39 { 40 super( name ); 41 } 42 43 46 47 50 public void testSimpleIncrementDisconnected() throws Exception 51 { 52 CounterInstrument ci = new CounterInstrument( "testInstrument" ); 53 assertEquals( "A disconnected instrument should not be active.", ci.isActive(), false ); 54 55 ci.increment( 1 ); 56 } 57 58 public void testCount1IncrementDisconnected() throws Exception 59 { 60 CounterInstrument ci = new CounterInstrument( "testInstrument" ); 61 assertEquals( "A disconnected instrument should not be active.", ci.isActive(), false ); 62 63 ci.increment( 1 ); 64 } 65 66 public void testCount0IncrementDisconnected() throws Exception 67 { 68 CounterInstrument ci = new CounterInstrument( "testInstrument" ); 69 try 70 { 71 ci.increment( 0 ); 72 fail( "calling increment with a count of 0 should fail." ); 73 } 74 catch ( IllegalArgumentException e ) 75 { 76 } 78 } 79 80 public void testCountNegIncrementDisconnected() throws Exception 81 { 82 CounterInstrument ci = new CounterInstrument( "testInstrument" ); 83 try 84 { 85 ci.increment( -1 ); 86 fail( "calling increment with a negative count should fail." ); 87 } 88 catch ( IllegalArgumentException e ) 89 { 90 } 92 } 93 94 public void testSimpleIncrementConnectedInactive() throws Exception 95 { 96 CounterInstrument ci = new CounterInstrument( "testInstrument" ); 97 TestInstrumentProxy proxy = new TestInstrumentProxy(); 98 ci.setInstrumentProxy( proxy ); 99 100 assertEquals( "The instrument should not be active.", ci.isActive(), false ); 101 102 ci.increment(); 103 104 assertEquals( "The expected count was incorrect.", proxy.getValue(), 1 ); 105 106 ci.increment(); 107 assertEquals( "The expected count was incorrect.", proxy.getValue(), 2 ); 108 } 109 110 public void testCount1IncrementConnectedInactive() throws Exception 111 { 112 CounterInstrument ci = new CounterInstrument( "testInstrument" ); 113 TestInstrumentProxy proxy = new TestInstrumentProxy(); 114 ci.setInstrumentProxy( proxy ); 115 116 assertEquals( "The instrument should not be active.", ci.isActive(), false ); 117 118 ci.increment( 1 ); 119 120 assertEquals( "The expected count was incorrect.", proxy.getValue(), 1 ); 121 122 ci.increment( 2 ); 123 assertEquals( "The expected count was incorrect.", proxy.getValue(), 3 ); 124 } 125 126 public void testSimpleIncrementConnectedActive() throws Exception 127 { 128 CounterInstrument ci = new CounterInstrument( "testInstrument" ); 129 TestInstrumentProxy proxy = new TestInstrumentProxy(); 130 ci.setInstrumentProxy( proxy ); 131 proxy.activate(); 132 133 assertEquals( "The instrument should br active.", ci.isActive(), true ); 134 135 ci.increment(); 136 137 assertEquals( "The expected count was incorrect.", proxy.getValue(), 1 ); 138 } 139 140 public void testCount1IncrementConnectedActive() throws Exception 141 { 142 CounterInstrument ci = new CounterInstrument( "testInstrument" ); 143 TestInstrumentProxy proxy = new TestInstrumentProxy(); 144 ci.setInstrumentProxy( proxy ); 145 proxy.activate(); 146 147 assertEquals( "The instrument should br active.", ci.isActive(), true ); 148 149 ci.increment( 1 ); 150 151 assertEquals( "The expected count was incorrect.", proxy.getValue(), 1 ); 152 } 153 } 154 155 | Popular Tags |