KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > j2biz > pencil > test > output > CastingTestCase


1 /*
2  * Copyright 2004 Andreas Siebert (j2biz community)
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
17 package com.j2biz.pencil.test.output;
18
19 import java.io.FileInputStream JavaDoc;
20 import java.io.FileOutputStream JavaDoc;
21 import java.io.PrintStream JavaDoc;
22 import java.util.Properties JavaDoc;
23
24 import junit.framework.TestCase;
25
26 import com.j2biz.pencil.test.stuff.TestCastingCallerClass;
27 import com.j2biz.pencil.test.stuff.TestCastingInstance2;
28 import com.j2biz.pencil.test.stuff.TestCastingInstance3;
29
30
31 /**
32  * @author andrej
33  *
34  * To change the template for this generated type comment go to
35  * Window - Preferences - Java - Code Generation - Code and Comments
36  */

37 public class CastingTestCase extends TestCase {
38
39     public void testCasting() throws Exception JavaDoc {
40         PrintStream JavaDoc oldOut = System.err;
41         FileOutputStream JavaDoc dropedOut = new FileOutputStream JavaDoc( "testCascadingVars.out" );
42         PrintStream JavaDoc newOut = new PrintStream JavaDoc(dropedOut);
43         System.setErr( newOut );
44         
45         TestCastingCallerClass myVar = new TestCastingCallerClass();
46         
47         System.setErr(oldOut);
48         newOut.flush();
49         newOut.close();
50         
51         Properties JavaDoc props = new Properties JavaDoc();
52         props.load(new FileInputStream JavaDoc("testCascadingVars.out"));
53         
54         assertEquals( props.getProperty( "parent.class.public.instance" ), ((TestCastingInstance2) myVar.testVar).field3 );
55         assertEquals(props.getProperty( "parent.interface.public.instance" ), ((TestCastingInstance3) myVar.testVar).field1 );
56     }
57 }
58
Popular Tags