Browse Source

Tidy up the code (use try with resources)

master
Gintas Grigelionis 7 years ago
parent
commit
44cb398444
5 changed files with 14 additions and 29 deletions
  1. +0
    -1
      src/tests/junit/org/apache/tools/ant/taskdefs/FilterTest.java
  2. +1
    -2
      src/tests/junit/org/apache/tools/ant/taskdefs/ProtectedJarMethodsTest.java
  3. +4
    -14
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java
  4. +8
    -9
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/i18n/TranslateTest.java
  5. +1
    -3
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/ssh/ScpTest.java

+ 0
- 1
src/tests/junit/org/apache/tools/ant/taskdefs/FilterTest.java View File

@@ -20,7 +20,6 @@ package org.apache.tools.ant.taskdefs;


import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;




+ 1
- 2
src/tests/junit/org/apache/tools/ant/taskdefs/ProtectedJarMethodsTest.java View File

@@ -40,8 +40,6 @@ public class ProtectedJarMethodsTest {


@Rule @Rule
public final BuildFileRule buildRule = new BuildFileRule(); public final BuildFileRule buildRule = new BuildFileRule();
private static String tempJar = "tmp.jar";



@Before @Before
public void setUp() { public void setUp() {
@@ -52,6 +50,7 @@ public class ProtectedJarMethodsTest {
@Test @Test
public void testGrabFilesAndDirs() throws IOException { public void testGrabFilesAndDirs() throws IOException {
buildRule.executeTarget("testIndexTests"); buildRule.executeTarget("testIndexTests");
String tempJar = "tmp.jar";
String archive = buildRule.getProject().getProperty(tempJar); String archive = buildRule.getProject().getProperty(tempJar);
List<String> dirs = new ArrayList<>(); List<String> dirs = new ArrayList<>();
List<String> files = new ArrayList<>(); List<String> files = new ArrayList<>();


+ 4
- 14
src/tests/junit/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java View File

@@ -52,15 +52,9 @@ public class ReplaceRegExpTest {
@Test @Test
public void testReplace() throws IOException { public void testReplace() throws IOException {
Properties original = new Properties(); Properties original = new Properties();
FileInputStream propsFile = null;
try {
propsFile = new FileInputStream(new File(buildRule.getProject().getBaseDir() + "/replaceregexp.properties"));
try (FileInputStream propsFile = new FileInputStream(new File(
buildRule.getProject().getBaseDir() + "/replaceregexp.properties"))) {
original.load(propsFile); original.load(propsFile);
} finally {
if (propsFile != null) {
propsFile.close();
propsFile = null;
}
} }


assertEquals("Def", original.get("OldAbc")); assertEquals("Def", original.get("OldAbc"));
@@ -68,13 +62,9 @@ public class ReplaceRegExpTest {
buildRule.executeTarget("testReplace"); buildRule.executeTarget("testReplace");


Properties after = new Properties(); Properties after = new Properties();
try {
propsFile = new FileInputStream(new File(buildRule.getOutputDir(), "test.properties"));
try (FileInputStream propsFile = new FileInputStream(new File(buildRule.getOutputDir(),
"test.properties"))) {
after.load(propsFile); after.load(propsFile);
} finally {
if (propsFile != null) {
propsFile.close();
}
} }


assertNull(after.get("OldAbc")); assertNull(after.get("OldAbc"));


+ 8
- 9
src/tests/junit/org/apache/tools/ant/taskdefs/optional/i18n/TranslateTest.java View File

@@ -69,15 +69,14 @@ public class TranslateTest {
byte[] buffer1 = new byte[BUF_SIZE]; byte[] buffer1 = new byte[BUF_SIZE];
byte[] buffer2 = new byte[BUF_SIZE]; byte[] buffer2 = new byte[BUF_SIZE];


try (FileInputStream fis1 = new FileInputStream(file1)) {
try (FileInputStream fis2 = new FileInputStream(file2)) {
int read = 0;
while ((read = fis1.read(buffer1)) != -1) {
fis2.read(buffer2);
for (int i = 0; i < read; ++i) {
if (buffer1[i] != buffer2[i]) {
return false;
}
try (FileInputStream fis1 = new FileInputStream(file1);
FileInputStream fis2 = new FileInputStream(file2)) {
int read = 0;
while ((read = fis1.read(buffer1)) != -1) {
fis2.read(buffer2);
for (int i = 0; i < read; ++i) {
if (buffer1[i] != buffer2[i]) {
return false;
} }
} }
} }


+ 1
- 3
src/tests/junit/org/apache/tools/ant/taskdefs/optional/ssh/ScpTest.java View File

@@ -171,11 +171,9 @@ public class ScpTest {


/** /**
* Expected failure due to invalid remoteToDir * Expected failure due to invalid remoteToDir
*
* @throws IOException
*/ */
@Test(expected = BuildException.class) @Test(expected = BuildException.class)
public void testInvalidRemoteToDir() throws IOException {
public void testInvalidRemoteToDir() {
scpTask.setRemoteTodir("host:/a/path/without/an/at"); scpTask.setRemoteTodir("host:/a/path/without/an/at");
} }




Loading…
Cancel
Save