Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b974fb2

Browse files
authored
try with resources (#5)
1 parent b42cd5a commit b974fb2

File tree

2 files changed

+4
-23
lines changed

2 files changed

+4
-23
lines changed

src/test/java/org/apache/maven/plugins/resources/ResourcesMojoTest.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.apache.maven.plugins.resources.stub.MavenProjectResourcesStub;
3838
import org.codehaus.plexus.PlexusContainer;
3939
import org.codehaus.plexus.util.FileUtils;
40-
import org.codehaus.plexus.util.IOUtil;
4140
import org.eclipse.aether.RepositorySystemSession;
4241

4342
public class ResourcesMojoTest
@@ -691,18 +690,9 @@ private void assertContent( String fileName, String data )
691690
throws IOException
692691
{
693692
assertTrue( FileUtils.fileExists( fileName ) );
694-
695-
BufferedReader reader = null;
696-
try
693+
try( BufferedReader reader = new BufferedReader( new FileReader( fileName ) ) )
697694
{
698-
reader = new BufferedReader( new FileReader( fileName ) );
699695
assertEquals( data, reader.readLine() );
700-
reader.close();
701-
reader = null;
702-
}
703-
finally
704-
{
705-
IOUtil.close( reader );
706696
}
707697
}
708698

src/test/java/org/apache/maven/plugins/resources/stub/MavenProjectBuildStub.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ private void createDirectories( String parent, String testparent )
240240
}
241241
}
242242

243-
private void createFiles( String parent, String testparent )
243+
private void createFiles( String parent, String testparent ) throws IOException
244244
{
245245
File currentFile;
246246

@@ -278,15 +278,8 @@ private void createFiles( String parent, String testparent )
278278

279279
if ( !currentFile.exists() )
280280
{
281-
try
282-
{
283-
currentFile.createNewFile();
284-
populateFile( currentFile );
285-
}
286-
catch ( IOException io )
287-
{
288-
//TODO: handle exception
289-
}
281+
currentFile.createNewFile();
282+
populateFile( currentFile );
290283
}
291284
}
292285
}
@@ -300,8 +293,6 @@ private void populateFile( File file ) throws IOException
300293
try ( FileOutputStream outputStream = new FileOutputStream( file ) )
301294
{
302295
outputStream.write( data.getBytes() );
303-
outputStream.flush();
304-
outputStream.close();
305296
}
306297
}
307298
}

0 commit comments

Comments
 (0)