View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package javax.faces.component;
21  
22  import java.io.ByteArrayInputStream;
23  import java.io.ByteArrayOutputStream;
24  import java.io.ObjectInputStream;
25  import java.io.ObjectOutputStream;
26  
27  import junit.framework.TestCase;
28  
29  public class _AttachedStateWrapperTest extends TestCase {
30  
31    public static void main(String[] args) {
32      junit.textui.TestRunner.run(_AttachedStateWrapperTest.class);
33    }
34  
35    public _AttachedStateWrapperTest(String name) {
36      super(name);
37    }
38  
39    protected void setUp() throws Exception {
40      super.setUp();
41    }
42  
43    protected void tearDown() throws Exception {
44      super.tearDown();
45    }
46  
47    /*
48     * Test method for 'javax.faces.component._AttachedStateWrapper._AttachedStateWrapper(Class, Object)'
49     */
50    public void test_AttachedStateWrapper() {
51      _AttachedStateWrapper subject = new _AttachedStateWrapper(null, null);
52      assertNull(subject.getWrappedStateObject());
53      assertNull(subject.getClazz());
54    }
55  
56    /*
57     * Test method for 'javax.faces.component._AttachedStateWrapper.getClazz()'
58     */
59    public void testGetClazz() {
60      _AttachedStateWrapper subject = new _AttachedStateWrapper(String.class, "foo");
61      assertEquals(subject.getClazz(), String.class);
62    }
63  
64    /*
65     * Test method for 'javax.faces.component._AttachedStateWrapper.getWrappedStateObject()'
66     */
67    public void testGetWrappedStateObject() {
68      _AttachedStateWrapper subject = new _AttachedStateWrapper(String.class, "foo");
69      assertEquals(subject.getClazz(), String.class);
70    }
71  
72    public void testSerialize() throws Exception {
73      String foo = "foo";
74      _AttachedStateWrapper subject = new _AttachedStateWrapper(String.class, foo);
75      ByteArrayOutputStream baos = new ByteArrayOutputStream(128);
76      ObjectOutputStream oos = new ObjectOutputStream(baos);
77      oos.writeObject(subject);
78      oos.flush();
79      baos.flush();
80      ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
81      ObjectInputStream ois = new ObjectInputStream(bais);
82      _AttachedStateWrapper blorg = (_AttachedStateWrapper) ois
83          .readObject();
84      assertEquals(blorg.getWrappedStateObject(), subject.getWrappedStateObject());
85      oos.close();
86      ois.close();
87    }
88  }