Skip to content

Commit

Permalink
Issue checkstyle#11446: Update checker test method testUnmappableChar…
Browse files Browse the repository at this point in the history
…acters
  • Loading branch information
chrccl committed Feb 16, 2024
1 parent c1ca1b9 commit 8d481b1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/test/java/com/puppycrawl/tools/checkstyle/CheckerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
import com.puppycrawl.tools.checkstyle.internal.utils.CloseAndFlushTestByteArrayOutputStream;
import com.puppycrawl.tools.checkstyle.internal.utils.TestUtil;
import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
import de.thetaphi.forbiddenapis.SuppressForbidden;

/**
* CheckerTest.
Expand Down Expand Up @@ -429,13 +428,21 @@ public void testSetters() {
checker.setFileExtensions(".java", "xml");

try {
checker.setCharset("UNKNOWN-CHARSET");
checker.setCharset("invalid_charset_name");
assertWithMessage("Exception is expected").fail();
}
catch (UnsupportedEncodingException ex) {
assertWithMessage("Error message is not expected")
.that(ex.getMessage())
.isEqualTo("unsupported charset: 'UNKNOWN-CHARSET'");
.isEqualTo("unsupported charset: 'invalid_charset_name'");
}

try {
final String validCharset = "UTF-8";
checker.setCharset(validCharset);
}
catch (UnsupportedEncodingException ex) {
assertWithMessage("Unexpected exception: " + ex.getClass().getName()).fail();
}
}

Expand Down Expand Up @@ -1659,20 +1666,13 @@ public void testCachedFile() throws Exception {
checker.destroy();
}

@SuppressForbidden
@Test
public void testUnmappableCharacters() throws Exception {
final String[] expected = {
"4: " + getCheckMessage(LineLengthCheck.class, MSG_KEY, 75, 238),
"9: " + getCheckMessage(LineLengthCheck.class, MSG_KEY, 80, 100),
};

final DefaultConfiguration checkConfig = createModuleConfig(LineLengthCheck.class);
checkConfig.addProperty("max", "75");

final DefaultConfiguration checkerConfig = createRootConfig(checkConfig);
checkerConfig.addProperty("charset", "IBM1098");

verify(checkerConfig, getPath("InputCheckerTestCharset.java"), expected);
verifyWithInlineConfigParser(getPath("InputCheckerTestCharset.java"), expected);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck
*/

package com.puppycrawl.tools.checkstyle.checker;

public class InputCheckerTestCharset {
Expand Down

0 comments on commit 8d481b1

Please sign in to comment.