diff options
author | vasilyeva <valeria.vasylieva@gmail.com> | 2017-05-07 22:46:37 +0300 |
---|---|---|
committer | Roman Ivanov <romani@users.noreply.github.com> | 2017-05-07 14:49:37 -0700 |
commit | a6d025d0c72777b4dab2a5f8b27638b644a4fa72 (patch) | |
tree | f33db4bee5e2636b9b2e0e1fb43d3a262a758fed /src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming | |
parent | b666a23cc595af7cc1a8bf4d4d49744025adfa11 (diff) | |
download | checkstyle-a6d025d0c72777b4dab2a5f8b27638b644a4fa72.tar.gz |
Issue #3348: add validation of try with resources to the LocalFinalVariableName check
Diffstat (limited to 'src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming')
-rw-r--r-- | src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/localfinalvariablename/InputLocalFinalVariableNameTryResources.java | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/localfinalvariablename/InputLocalFinalVariableNameTryResources.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/localfinalvariablename/InputLocalFinalVariableNameTryResources.java new file mode 100644 index 000000000..f9ab90a51 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/localfinalvariablename/InputLocalFinalVariableNameTryResources.java @@ -0,0 +1,85 @@ +package com.puppycrawl.tools.checkstyle.checks.naming.localfinalvariablename; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.PropertyResourceBundle; +import java.util.zip.ZipFile; + +/** + * Contains test cases regarding checking local + * final variable name in try-with-resources statement: + * + * @author Valeria Vasylieva + **/ +public class InputLocalFinalVariableNameTryResources { + + void method() throws Exception { + final String fileName = "Test"; + final BufferedReader br = new BufferedReader(new InputStreamReader( + new FileInputStream(fileName), StandardCharsets.UTF_8)); + try { + } finally { + br.close(); + } + } + + void method2() throws Exception { + final String fileName = "Test"; + try (BufferedReader br = new BufferedReader(new InputStreamReader( + new FileInputStream(fileName), StandardCharsets.UTF_8))) { + } finally { + + } + } + + void method3() throws Exception { + final String fileName = "Test"; + try (final BufferedReader BR = new BufferedReader(new InputStreamReader( + new FileInputStream(fileName), StandardCharsets.UTF_8))) { + } finally { + + } + } + + void method4() throws Exception { + final String fileName = "Test"; + try (BufferedReader BR = new BufferedReader(new InputStreamReader( + new FileInputStream(fileName), StandardCharsets.UTF_8)); + ZipFile zf = new ZipFile(fileName)) { + } finally { + + } + } + + void method5() throws Exception { + final String fileName = "Test"; + try (BufferedReader BR = new BufferedReader(new InputStreamReader( + new FileInputStream(fileName), StandardCharsets.UTF_8)); + ZipFile ZF = new ZipFile(fileName)) { + } finally { + + } + } + + void method6() throws Exception { + String srcDir = System.getProperty("test.src", "."); + try (FileInputStream fis8859_1 = new FileInputStream(new File(srcDir, "Bug6204853.properties")); + FileInputStream fisUTF8 = new FileInputStream(new File(srcDir, "Bug6204853_Utf8.properties")); + InputStreamReader isrutf8 = new InputStreamReader(fisUTF8, "UTF-8")) { + PropertyResourceBundle bundleUtf8 = new PropertyResourceBundle(isrutf8); + PropertyResourceBundle bundle = new PropertyResourceBundle(fis8859_1); + String[] arrayUtf8 = {"1", "2", "3"}; + String[] array = {"key1", "key2"}; + if (!Arrays.equals(arrayUtf8, array)) { + throw new RuntimeException("Error message"); + } + } catch (IOException ioe) { + throw new RuntimeException(ioe); + } + } +} |