KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > excalibur > instrument > test > ValueInstrumentTestCase


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14  * implied.
15  *
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19
20 package org.apache.excalibur.instrument.test;
21
22 import junit.framework.TestCase;
23
24 import org.apache.excalibur.instrument.ValueInstrument;
25
26 /**
27  * Test of the ValueInstrument instrument.
28  *
29  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
30  * @version CVS $Revision: 1.4 $ $Date: 2004/02/28 11:47:34 $
31  */

32 public class ValueInstrumentTestCase
33     extends TestCase
34 {
35     /*---------------------------------------------------------------
36      * Constructors
37      *-------------------------------------------------------------*/

38     public ValueInstrumentTestCase( String JavaDoc name )
39     {
40         super( name );
41     }
42     
43     /*---------------------------------------------------------------
44      * TestCase Methods
45      *-------------------------------------------------------------*/

46     
47     /*---------------------------------------------------------------
48      * Test Cases
49      *-------------------------------------------------------------*/

50     public void testSimpleValueDisconnected() throws Exception JavaDoc
51     {
52         ValueInstrument vi = new ValueInstrument( "testInstrument" );
53         
54         assertEquals( "A disconnected instrument should not be active.", vi.isActive(), false );
55         
56         vi.setValue( 0 );
57         vi.setValue( -1 );
58         vi.setValue( 1 );
59     }
60     
61     public void testSimpleValueConnectedInactive() throws Exception JavaDoc
62     {
63         ValueInstrument vi = new ValueInstrument( "testInstrument" );
64         TestInstrumentProxy proxy = new TestInstrumentProxy();
65         vi.setInstrumentProxy( proxy );
66         
67         assertEquals( "The instrument should not be active.", vi.isActive(), false );
68         
69         vi.setValue( 0 );
70         assertEquals( "The expected value was incorrect.", proxy.getValue(), 0 );
71         
72         vi.setValue( -1 );
73         assertEquals( "The expected value was incorrect.", proxy.getValue(), -1 );
74         
75         vi.setValue( 1 );
76         assertEquals( "The expected value was incorrect.", proxy.getValue(), 1 );
77     }
78     
79     public void testLargeValueConnectedInactive() throws Exception JavaDoc
80     {
81         ValueInstrument vi = new ValueInstrument( "testInstrument" );
82         TestInstrumentProxy proxy = new TestInstrumentProxy();
83         vi.setInstrumentProxy( proxy );
84         
85         assertEquals( "The instrument should not be active.", vi.isActive(), false );
86         
87         vi.setValue( 1313123123 );
88         assertEquals( "The expected value was incorrect.", proxy.getValue(), 1313123123 );
89         
90         vi.setValue( -325353253 );
91         assertEquals( "The expected value was incorrect.", proxy.getValue(), -325353253 );
92     }
93     
94     public void testSimpleValueConnectedActive() throws Exception JavaDoc
95     {
96         ValueInstrument vi = new ValueInstrument( "testInstrument" );
97         TestInstrumentProxy proxy = new TestInstrumentProxy();
98         vi.setInstrumentProxy( proxy );
99         proxy.activate();
100         
101         assertEquals( "The instrument should br active.", vi.isActive(), true );
102         
103         vi.setValue( 0 );
104         assertEquals( "The expected value was incorrect.", proxy.getValue(), 0 );
105         
106         vi.setValue( -1 );
107         assertEquals( "The expected value was incorrect.", proxy.getValue(), -1 );
108         
109         vi.setValue( 1 );
110         assertEquals( "The expected value was incorrect.", proxy.getValue(), 1 );
111     }
112     
113     public void testLargeValueConnectedActive() throws Exception JavaDoc
114     {
115         ValueInstrument vi = new ValueInstrument( "testInstrument" );
116         TestInstrumentProxy proxy = new TestInstrumentProxy();
117         vi.setInstrumentProxy( proxy );
118         proxy.activate();
119         
120         assertEquals( "The instrument should br active.", vi.isActive(), true );
121         
122         vi.setValue( 1313123123 );
123         assertEquals( "The expected value was incorrect.", proxy.getValue(), 1313123123 );
124         
125         vi.setValue( -325353253 );
126         assertEquals( "The expected value was incorrect.", proxy.getValue(), -325353253 );
127     }
128 }
129
130
Popular Tags