Skip to content

Commit 2e88b4a

Browse files
committed
fix issues
1 parent fc52c25 commit 2e88b4a

File tree

5 files changed

+99
-118
lines changed

5 files changed

+99
-118
lines changed

qulice-checkstyle/src/main/resources/com/qulice/checkstyle/checks.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
104104
Checks that the file is not binary
105105
-->
106106
<module name="RegexpMultiline">
107-
<property name="format" value=".*[\x00-\x08\x0E-\x1F].*"/>
107+
<property name="format" value="[^\x00-\x7F]+"/>
108108
<property name="fileExtensions" value="java"/>
109-
<property name="id" value="BinaryFiles"/>
110-
<property name="message" value="Binary files are not allowed"/>
109+
<property name="id" value="BinaryContents"/>
110+
<property name="message" value="Binary contents are not allowed"/>
111111
</module>
112112
<!--
113113
JavaDoc regexp checks

qulice-checkstyle/src/test/java/com/qulice/checkstyle/CheckstyleMetainfoTest.java

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,37 +30,20 @@
3030
*/
3131
package com.qulice.checkstyle;
3232

33-
import org.junit.jupiter.api.BeforeAll;
34-
import org.junit.jupiter.api.BeforeEach;
33+
import com.qulice.spi.Violation;
34+
import java.util.Collection;
35+
import org.hamcrest.MatcherAssert;
36+
import org.hamcrest.Matchers;
3537
import org.junit.jupiter.api.Test;
3638
import org.junit.jupiter.api.TestInstance;
3739

3840
/**
3941
* Test case for file metainfo validation.
4042
* @since 0.3
4143
*/
42-
@SuppressWarnings(
43-
{
44-
"PMD.TooManyMethods", "PMD.AvoidDuplicateLiterals", "PMD.GodClass"
45-
}
46-
)
44+
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
4745
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
48-
final class CheckstyleMetainfoTest {
49-
50-
/**
51-
* Local Common (JavaHelper pattern) with useful utils to test checkstyle.
52-
*/
53-
private Common common;
54-
55-
@BeforeAll
56-
public void setcommon() {
57-
this.common = new Common();
58-
}
59-
60-
@BeforeEach
61-
public void setRule() {
62-
this.common.updateRule();
63-
}
46+
final class CheckstyleMetainfoTest extends CheckstyleTestBase {
6447

6548
/**
6649
* CheckstyleValidator can deny binary contents in java file.
@@ -69,6 +52,19 @@ public void setRule() {
6952
*/
7053
@Test
7154
void rejectsJavaFileWithBinaryContent() throws Exception {
72-
this.common.runValidation("JavaFileWithBinaryContent.java", false);
55+
final String message =
56+
"Binary contents are not allowed";
57+
final String file = "JavaFileWithBinaryContent.java";
58+
final String name = "RegexpMultilineCheck";
59+
final Collection<Violation> results = runValidation(file, false);
60+
MatcherAssert.assertThat(
61+
"Two violations with binary contents shoud be found",
62+
results,
63+
Matchers.hasItems(
64+
new ViolationMatcher(
65+
message, file, "13", name
66+
)
67+
)
68+
);
7369
}
7470
}

qulice-checkstyle/src/test/java/com/qulice/checkstyle/Common.java renamed to qulice-checkstyle/src/test/java/com/qulice/checkstyle/CheckstyleTestBase.java

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@
4141
import org.cactoos.text.TextOf;
4242
import org.hamcrest.MatcherAssert;
4343
import org.hamcrest.Matchers;
44+
import org.junit.jupiter.api.BeforeEach;
4445

4546
/**
46-
* Common utils and constants for checkstyle tests.
47+
* Base class for checkstyle tests.
4748
* @since 0.3
4849
*/
49-
final class Common {
50+
public class CheckstyleTestBase {
5051

5152
/**
5253
* Name of property to set to change location of the license.
@@ -64,18 +65,18 @@ final class Common {
6465
public static final String LICENSE = "Hello.";
6566

6667
/**
67-
* Rule for testing.
68+
* License rule.
6869
*/
6970
private License rule;
7071

71-
public void updateRule() {
72+
/**
73+
* Method to recet license rule before each test in inherited test classes.
74+
*/
75+
@BeforeEach
76+
public void setRule() {
7277
this.rule = new License();
7378
}
7479

75-
public License getRule() {
76-
return this.rule;
77-
}
78-
7980
/**
8081
* Validates that checkstyle reported given violation.
8182
* @param file File to check.
@@ -107,13 +108,13 @@ public void validate(final String file, final boolean result,
107108
public Collection<Violation> runValidation(final String file,
108109
final boolean passes) throws IOException {
109110
final Environment.Mock mock = new Environment.Mock();
110-
final File license = this.getRule().savePackageInfo(
111-
new File(mock.basedir(), Common.DIRECTORY)
112-
).withLines(Common.LICENSE)
111+
final File license = this.rule.savePackageInfo(
112+
new File(mock.basedir(), CheckstyleTestBase.DIRECTORY)
113+
).withLines(CheckstyleTestBase.LICENSE)
113114
.withEol("\n").file();
114115
final Environment env = mock.withParam(
115-
Common.LICENSE_PROP,
116-
Common.toUrl(license)
116+
CheckstyleTestBase.LICENSE_PROP,
117+
CheckstyleTestBase.toUrl(license)
117118
)
118119
.withFile(
119120
String.format("src/main/java/foo/%s", file),
@@ -143,12 +144,20 @@ public Collection<Violation> runValidation(final String file,
143144
return results;
144145
}
145146

147+
/**
148+
* Method to access the rule from inherited classes.
149+
* @return License rule
150+
*/
151+
protected License getRule() {
152+
return this.rule;
153+
}
154+
146155
/**
147156
* Convert file name to URL.
148157
* @param file The file
149158
* @return The URL
150159
*/
151-
private static String toUrl(final File file) {
160+
protected static String toUrl(final File file) {
152161
return String.format("file:%s", file);
153162
}
154163

0 commit comments

Comments
 (0)