2525 */
2626public class WsImportTaskTest extends WsAntTaskTestBase {
2727
28- private File wsdl ;
2928 private File pkg ;
3029 private File metainf ;
3130
@@ -39,7 +38,7 @@ protected void setUp() throws Exception {
3938 super .setUp ();
4039 pkg = new File (srcDir , "test" );
4140 metainf = new File (buildDir , "META-INF" );
42- wsdl = copy (projectDir , "hello.wsdl" , WsImportTaskTest .class .getResourceAsStream ("resources/hello.wsdl" ));
41+ copy (projectDir , "hello.wsdl" , WsImportTaskTest .class .getResourceAsStream ("resources/hello.wsdl" ));
4342 assertTrue (pkg .mkdirs ());
4443 assertTrue (metainf .mkdirs ());
4544 }
@@ -49,21 +48,22 @@ public void testEncoding() throws IOException {
4948 assertEquals (1 , AntExecutor .exec (script , "wsimport-client-encoding" ));
5049 //UTF-8
5150 File f = new File (buildDir , "client/utf8/Hello.java" );
52- FileInputStream fis = new FileInputStream (f );
53- byte [] in = new byte [11 ];
54- fis .read (in );
55- fis . close ( );
56- String inStr = new String ( in , "UTF-8" );
57- assertTrue ( "Got: '" + inStr + "'" , inStr . contains ( "package c" ));
51+ try ( FileInputStream fis = new FileInputStream (f )) {
52+ byte [] in = new byte [11 ];
53+ fis .read (in );
54+ String inStr = new String ( in , "UTF-8" );
55+ assertTrue ( "Got: '" + inStr + "'" , inStr . contains ( "package c" ) );
56+ }
5857
5958 //UTF-16LE
6059 f = new File (buildDir , "client/utf16LE/Hello.java" );
61- fis = new FileInputStream (f );
62- in = new byte [22 ];
63- fis .read (in );
64- fis .close ();
65- inStr = new String (in , "UTF-16LE" );
66- assertTrue ("Got: '" + inStr + "'" , inStr .contains ("package c" ));
60+ byte [] in ;
61+ try (FileInputStream fis = new FileInputStream (f )) {
62+ in = new byte [22 ];
63+ fis .read (in );
64+ String inStr = new String (in , "UTF-16LE" );
65+ assertTrue ("Got: '" + inStr + "'" , inStr .contains ("package c" ));
66+ }
6767
6868 //UTF-74
6969 assertFalse (new File (buildDir , "client/invalid" ).exists ());
@@ -72,27 +72,29 @@ public void testEncoding() throws IOException {
7272 public void testPlugin () throws IOException {
7373 assertEquals (0 , AntExecutor .exec (script , "wsimport-plugin" ));
7474 File f = new File (buildDir , "test/Hello_Service.java" );
75- BufferedReader br = new BufferedReader (new FileReader (f ));
76- String line ;
77- boolean found = false ;
78- while ((line = br .readLine ()) != null ) {
79- if (line .contains ("@Generated(value = \" com.sun.tools.ws.wscompile.WsimportTool\" , " )) {
80- found = true ;
81- break ;
75+ try (BufferedReader br = new BufferedReader (new FileReader (f ))) {
76+ String line ;
77+ boolean found = false ;
78+ while ((line = br .readLine ()) != null ) {
79+ if (line .contains ("@Generated(value = \" com.sun.tools.ws.wscompile.WsimportTool\" , " )) {
80+ found = true ;
81+ break ;
82+ }
8283 }
84+ assertFalse ("Plugin invoked" , found );
8385 }
84- br .close ();
85- assertFalse ("Plugin invoked" , found );
8686 f = new File (srcDir , "test/Hello_Service.java" );
87- br = new BufferedReader (new FileReader (f ));
88- while ((line = br .readLine ()) != null ) {
89- if (line .contains ("@Generated(value = \" com.sun.tools.ws.wscompile.WsimportTool\" , " )) {
90- found = true ;
91- break ;
87+ try (BufferedReader br = new BufferedReader (new FileReader (f ))) {
88+ String line ;
89+ boolean found = false ;
90+ while ((line = br .readLine ()) != null ) {
91+ if (line .contains ("@Generated(value = \" com.sun.tools.ws.wscompile.WsimportTool\" , " )) {
92+ found = true ;
93+ break ;
94+ }
9295 }
96+ assertTrue ("Plugin not invoked" , found );
9397 }
94- br .close ();
95- assertTrue ("Plugin not invoked" , found );
9698 }
9799
98100 public void testFork () throws FileNotFoundException , IOException {
@@ -105,16 +107,18 @@ public void testJavac() throws IOException {
105107 assertEquals (0 , AntExecutor .exec (script , "wsimport-javac" ));
106108 //wsimport compiled classes should be valid for java 5
107109 File f = new File (buildDir , "test/types/HelloType.class" );
108- DataInputStream in = new DataInputStream (new FileInputStream (f ));
109- assertEquals (0xcafebabe , in .readInt ());
110- assertEquals (0 , in .readUnsignedShort ());
111- assertEquals (55 , in .readUnsignedShort ());
110+ try (DataInputStream in = new DataInputStream (new FileInputStream (f ))) {
111+ assertEquals (0xcafebabe , in .readInt ());
112+ assertEquals (0 , in .readUnsignedShort ());
113+ assertEquals (55 , in .readUnsignedShort ());
114+ }
112115
113116 f = new File (buildDir , "test/Hello.class" );
114- in = new DataInputStream (new FileInputStream (f ));
115- assertEquals (0xcafebabe , in .readInt ());
116- assertEquals (0 , in .readUnsignedShort ());
117- assertEquals (55 , in .readUnsignedShort ());
117+ try (DataInputStream in = new DataInputStream (new FileInputStream (f ))) {
118+ assertEquals (0xcafebabe , in .readInt ());
119+ assertEquals (0 , in .readUnsignedShort ());
120+ assertEquals (55 , in .readUnsignedShort ());
121+ }
118122 }
119123
120124}
0 commit comments