Skip to content

Commit

Permalink
Issue sevntu-checkstyle#618: fixed all violations from RequireFailFor…
Browse files Browse the repository at this point in the history
…TryCatchInJunitCheck
  • Loading branch information
rnveach committed Oct 29, 2017
1 parent 8a98391 commit b4b1aed
Show file tree
Hide file tree
Showing 17 changed files with 25 additions and 3 deletions.
Expand Up @@ -20,6 +20,7 @@
package com.github.sevntu.checkstyle;

import static java.text.MessageFormat.format;
import static org.junit.Assert.assertEquals;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
Expand All @@ -34,8 +35,6 @@
import java.util.Locale;
import java.util.Properties;

import org.junit.Assert;

import com.google.common.collect.Lists;
import com.puppycrawl.tools.checkstyle.AuditEventUtFormatter;
import com.puppycrawl.tools.checkstyle.Checker;
Expand All @@ -45,7 +44,7 @@
import com.puppycrawl.tools.checkstyle.api.AuditEvent;
import com.puppycrawl.tools.checkstyle.api.Configuration;

public abstract class BaseCheckTestSupport extends Assert {
public abstract class BaseCheckTestSupport {
private final ByteArrayOutputStream baos = new ByteArrayOutputStream();
private final PrintStream printStream = new PrintStream(baos);

Expand Down
Expand Up @@ -20,6 +20,7 @@
package com.github.sevntu.checkstyle;

import static com.puppycrawl.tools.checkstyle.internal.TestUtils.assertUtilsClassHasPrivateConstructor;
import static org.junit.Assert.fail;

import org.junit.Assert;
import org.junit.Test;
Expand All @@ -36,6 +37,7 @@ public void testIsProperUtilsClass() throws ReflectiveOperationException {
public void testReportInvalidToken() {
try {
Utils.reportInvalidToken(TokenTypes.CLASS_DEF);
fail();
}
catch (IllegalArgumentException ex) {
Assert.assertEquals("Found unsupported token: CLASS_DEF", ex.getMessage());
Expand Down
Expand Up @@ -20,6 +20,7 @@
package com.github.sevntu.checkstyle.checks.coding;

import static com.github.sevntu.checkstyle.checks.coding.AvoidModifiersForTypesCheck.MSG_KEY;
import static org.junit.Assert.fail;

import org.junit.Assert;
import org.junit.Test;
Expand Down
Expand Up @@ -20,6 +20,7 @@
package com.github.sevntu.checkstyle.checks.coding;

import static com.github.sevntu.checkstyle.checks.coding.EmptyPublicCtorInClassCheck.MSG_KEY;
import static org.junit.Assert.fail;

import org.junit.Assert;
import org.junit.Test;
Expand Down
Expand Up @@ -20,6 +20,7 @@
package com.github.sevntu.checkstyle.checks.coding;

import static com.github.sevntu.checkstyle.checks.coding.ForbidCertainImportsCheck.MSG_KEY;
import static org.junit.Assert.fail;

import org.junit.Assert;
import org.junit.Test;
Expand Down
Expand Up @@ -20,6 +20,7 @@
package com.github.sevntu.checkstyle.checks.coding;

import static com.github.sevntu.checkstyle.checks.coding.ForbidInstantiationCheck.MSG_KEY;
import static org.junit.Assert.fail;

import org.junit.Assert;
import org.junit.Test;
Expand Down
Expand Up @@ -20,6 +20,7 @@
package com.github.sevntu.checkstyle.checks.coding;

import static com.github.sevntu.checkstyle.checks.coding.NumericLiteralNeedsUnderscoreCheck.MSG_KEY;
import static org.junit.Assert.fail;

import java.io.File;

Expand Down Expand Up @@ -185,6 +186,7 @@ public void testMinSymbolsBeforeCheckingSwitchReflection() throws Exception {
new NumericLiteralNeedsUnderscoreCheck();
final NumericType mockType = PowerMockito.mock(NumericType.class);
WhiteboxImpl.invokeMethod(check, "minSymbolsBeforeChecking", mockType);
fail();
}
catch (IllegalStateException ex) {
Assert.assertTrue(ex.getMessage().startsWith(EXCEPTION_MESSAGE));
Expand All @@ -198,6 +200,7 @@ public void testMaxSymbolsUntilUnderscoreSwitchReflection() throws Exception {
new NumericLiteralNeedsUnderscoreCheck();
final NumericType mockType = PowerMockito.mock(NumericType.class);
WhiteboxImpl.invokeMethod(check, "maxSymbolsUntilUnderscore", mockType);
fail();
}
catch (IllegalStateException ex) {
Assert.assertTrue(ex.getMessage().startsWith(EXCEPTION_MESSAGE));
Expand All @@ -211,6 +214,7 @@ public void testGetNumericSegmentsSwitchReflection() throws Exception {
new NumericLiteralNeedsUnderscoreCheck();
final NumericType mockType = PowerMockito.mock(NumericType.class);
WhiteboxImpl.invokeMethod(check, "getNumericSegments", "", mockType);
fail();
}
catch (IllegalStateException ex) {
Assert.assertTrue(ex.getMessage().startsWith(EXCEPTION_MESSAGE));
Expand All @@ -224,6 +228,7 @@ public void testRemovePrePostfixByTypeSwitchReflection() throws Exception {
new NumericLiteralNeedsUnderscoreCheck();
final NumericType mockType = PowerMockito.mock(NumericType.class);
WhiteboxImpl.invokeMethod(check, "removePrePostfixByType", "", mockType);
fail();
}
catch (IllegalStateException ex) {
Assert.assertTrue(ex.getMessage().startsWith(EXCEPTION_MESSAGE));
Expand Down
Expand Up @@ -20,6 +20,7 @@
package com.github.sevntu.checkstyle.checks.coding;

import static com.github.sevntu.checkstyle.checks.coding.RedundantReturnCheck.MSG_KEY;
import static org.junit.Assert.fail;

import org.junit.Assert;
import org.junit.Test;
Expand Down
Expand Up @@ -20,6 +20,7 @@
package com.github.sevntu.checkstyle.checks.coding;

import static com.github.sevntu.checkstyle.checks.coding.RequireFailForTryCatchInJunitCheck.MSG_KEY;
import static org.junit.Assert.fail;

import org.junit.Assert;
import org.junit.Test;
Expand Down
Expand Up @@ -20,6 +20,7 @@
package com.github.sevntu.checkstyle.checks.coding;

import static com.github.sevntu.checkstyle.checks.coding.ReturnNullInsteadOfBooleanCheck.MSG_KEY;
import static org.junit.Assert.fail;

import org.junit.Assert;
import org.junit.Test;
Expand Down
Expand Up @@ -20,6 +20,7 @@
package com.github.sevntu.checkstyle.checks.design;

import static com.github.sevntu.checkstyle.checks.design.AvoidConditionInversionCheck.MSG_KEY;
import static org.junit.Assert.fail;

import org.junit.Assert;
import org.junit.Test;
Expand Down
Expand Up @@ -20,6 +20,7 @@
package com.github.sevntu.checkstyle.checks.design;

import static com.github.sevntu.checkstyle.checks.design.CauseParameterInExceptionCheck.MSG_KEY;
import static org.junit.Assert.fail;

import org.junit.Assert;
import org.junit.Test;
Expand Down
Expand Up @@ -20,6 +20,7 @@
package com.github.sevntu.checkstyle.checks.design;

import static com.github.sevntu.checkstyle.checks.design.ConstructorWithoutParamsCheck.MSG_KEY;
import static org.junit.Assert.assertArrayEquals;

import org.junit.Before;
import org.junit.Test;
Expand Down
Expand Up @@ -20,6 +20,7 @@
package com.github.sevntu.checkstyle.checks.design;

import static com.github.sevntu.checkstyle.checks.design.PublicReferenceToPrivateTypeCheck.MSG_KEY;
import static org.junit.Assert.fail;

import org.junit.Assert;
import org.junit.Test;
Expand Down
Expand Up @@ -20,6 +20,7 @@
package com.github.sevntu.checkstyle.checks.design;

import static com.github.sevntu.checkstyle.checks.design.StaticMethodCandidateCheck.MSG_KEY;
import static org.junit.Assert.assertArrayEquals;

import java.io.File;

Expand Down
Expand Up @@ -19,6 +19,8 @@

package com.github.sevntu.checkstyle.checks.naming;

import static org.junit.Assert.fail;

import java.util.Arrays;

import org.junit.Assert;
Expand Down
Expand Up @@ -20,6 +20,7 @@
package com.github.sevntu.checkstyle.checks.sizes;

import static com.github.sevntu.checkstyle.checks.sizes.LineLengthExtendedCheck.MSG_KEY;
import static org.junit.Assert.fail;

import org.junit.Assert;
import org.junit.Test;
Expand Down Expand Up @@ -86,6 +87,7 @@ public void testProperty() throws Exception {

try {
verify(checkConfig, getPath("InputLineLengthExtendedCheck.java"), expected);
fail();
}
catch (CheckstyleException ex) {
Assert.assertTrue(ex.getMessage().startsWith("cannot initialize module "
Expand Down

0 comments on commit b4b1aed

Please sign in to comment.