From c6c9ad9d33dbb2a1d060f29ade459642ef236a46 Mon Sep 17 00:00:00 2001 From: Ilja Dubinin Date: Sun, 26 Jul 2015 18:00:37 +0100 Subject: [PATCH] Issue #1290: coverage has been increased to 100% in TranslationCheck --- pom.xml | 5 --- .../checks/TranslationCheckTest.java | 38 +++++++++++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 7aad9239a..1fa2b3d42 100644 --- a/pom.xml +++ b/pom.xml @@ -1629,11 +1629,6 @@ 75 93 - - .*.checks.TranslationCheck - 81 - 83 - .*.checks.header.AbstractHeaderCheck diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/TranslationCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/TranslationCheckTest.java index a44e1df98..0493e7b71 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/TranslationCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/TranslationCheckTest.java @@ -22,11 +22,14 @@ package com.puppycrawl.tools.checkstyle.checks; import static com.puppycrawl.tools.checkstyle.checks.TranslationCheck.MSG_KEY; import java.io.File; +import java.io.IOException; +import java.lang.reflect.Method; import org.apache.commons.lang3.ArrayUtils; import org.junit.Test; import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport; +import com.puppycrawl.tools.checkstyle.Checker; import com.puppycrawl.tools.checkstyle.DefaultConfiguration; import com.puppycrawl.tools.checkstyle.api.Configuration; @@ -88,4 +91,39 @@ public class TranslationCheckTest getPath("app-dev.properties"), expected); } + + @Test + public void testLogIOExceptionFileNotFound() throws Exception { + //I can't put wrong file here. Checkstyle fails before check started. + //I saw some usage of file or handling of wrong file in Checker, or somewhere + //in checks running part. So I had to do it with reflection to improve coverage. + TranslationCheck check = new TranslationCheck(); + DefaultConfiguration checkConfig = createCheckConfig(TranslationCheck.class); + check.configure(checkConfig); + Checker checker = createChecker(checkConfig); + check.setMessageDispatcher(checker); + + Method loadKeys = check.getClass().getDeclaredMethod("loadKeys", File.class); + loadKeys.setAccessible(true); + loadKeys.invoke(check, new File("")); + + } + + @Test + public void testLogIOException() throws Exception { + //I can't put wrong file here. Checkstyle fails before check started. + //I saw some usage of file or handling of wrong file in Checker, or somewhere + //in checks running part. So I had to do it with reflection to improve coverage. + TranslationCheck check = new TranslationCheck(); + DefaultConfiguration checkConfig = createCheckConfig(TranslationCheck.class); + check.configure(checkConfig); + check.setMessageDispatcher(createChecker(checkConfig)); + + Method logIOException = check.getClass().getDeclaredMethod("logIOException", + IOException.class, + File.class); + logIOException.setAccessible(true); + logIOException.invoke(check, new IOException(), new File("")); + } + }