KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > cglib > beans > TestImmutableBean


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

16 package net.sf.cglib.beans;
17
18 import java.lang.reflect.Method JavaDoc;
19 import junit.framework.*;
20
21 /**
22  *
23  * @author baliuka
24  */

25 public class TestImmutableBean extends TestCase {
26
27     public void testSimple() {
28         MA bean = new MA();
29         assertTrue(bean.getIntP() == 0);
30         bean.setIntP(42);
31         assertTrue(bean.getIntP() == 42);
32         bean = (MA)ImmutableBean.create(bean);
33         assertTrue(bean.getIntP() == 42);
34         try {
35             bean.setIntP(43);
36             fail("expecting illegal state exception");
37         } catch (IllegalStateException JavaDoc ignore) { }
38     }
39     
40     public TestImmutableBean(java.lang.String JavaDoc testName) {
41         super(testName);
42     }
43     
44     public static void main(java.lang.String JavaDoc[] args) {
45         junit.textui.TestRunner.run(suite());
46     }
47     
48     public static Test suite() {
49         return new TestSuite(TestImmutableBean.class);
50     }
51 }
52
Popular Tags