Skip to content

Commit

Permalink
Issue #15556: updated MethodName module in google_checks.xml to ignor…
Browse files Browse the repository at this point in the history
…e methods with Test annotations
  • Loading branch information
Zopsss authored and romani committed Aug 28, 2024
1 parent 360cab6 commit 9dac1f2
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.google.checkstyle.test.chapter5naming.rule523methodnames;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

/**
* Test input for MethodNameCheck specifically whether the method name equals the class name.
Expand Down Expand Up @@ -56,6 +60,79 @@ void Testing_Foo2() {} // violation 'Method name 'Testing_Foo2' must match patte
@Test
void TestingFooBad() {} // violation 'Method name 'TestingFooBad' must match pattern'

@ParameterizedTest
@ValueSource(strings = {"racecar", "radar", "level", "madam", "noon"})
void testing_foo1(String str) {}

@ParameterizedTest
@ValueSource(strings = {"racecar", "radar", "level", "madam", "noon"})
void testing_Foo1(String str) {}

@ParameterizedTest
@ValueSource(strings = {"racecar", "radar", "level", "madam", "noon"})
void testing_fOo1(String str) {}

@ParameterizedTest
@ValueSource(strings = {"racecar", "radar", "level", "madam", "noon"})
void testingFoo1(String str) {}

@ParameterizedTest
@ValueSource(strings = {"racecar", "radar", "level", "madam", "noon"})
void testingFoo_foo1(String str) {}

@ParameterizedTest
@ValueSource(strings = {"racecar", "radar", "level", "madam", "noon"})
void testing_01231(String str) {}

@ParameterizedTest
@ValueSource(strings = {"racecar", "radar", "level", "madam", "noon"})
void Testing_Foo1(String str) {} // violation 'Method name 'Testing_Foo1' must match pattern'

@ParameterizedTest
@ValueSource(strings = {"racecar", "radar", "level", "madam", "noon"})
void t_esting1(String str) {} // violation 'Method name 't_esting1' must match pattern'

@ParameterizedTest
@ValueSource(strings = {"racecar", "radar", "level", "madam", "noon"})
void _testing1(String str) {} // violation 'Method name '_testing1' must match pattern'

@ParameterizedTest
@ValueSource(strings = {"racecar", "radar", "level", "madam", "noon"})
void TestingFooBad1(String str) {} // violation 'Method name 'TestingFooBad1' must match pattern'

@RepeatedTest(2)
void testing_foo2() {}

@RepeatedTest(2)
void testing_Foo2() {}

@RepeatedTest(2)
void testing_fOo2() {}

@RepeatedTest(2)
void testingFoo2() {}

@RepeatedTest(2)
void testingFoo_foo2() {}

@RepeatedTest(2)
void testing_01232() {}

@RepeatedTest(2)
void Testing_Foo3() {} // violation 'Method name 'Testing_Foo3' must match pattern'

@RepeatedTest(2)
void t_esting2() {} // violation 'Method name 't_esting2' must match pattern'

@RepeatedTest(2)
void _testing2() {} // violation 'Method name '_testing2' must match pattern'

@RepeatedTest(2)
void TestingFooBad2() {} // violation 'Method name 'TestingFooBad2' must match pattern'

@BeforeAll
static void _testingFoooo() {} // violation 'Method name '_testingFoooo' must match pattern'

class InnerFoo {
void foo() {}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/google_checks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@
<module name="SuppressionXpathSingleFilter">
<property name="checks" value="MethodName"/>
<property name="query" value="//METHOD_DEF[
.//ANNOTATION/IDENT[@text='Test']]//*"/>
.//ANNOTATION/IDENT[contains(@text, 'Test')]]//*"/>
<property name="message" value="'[a-z][a-z0-9][_a-zA-Z0-9]*'.*"/>
</module>
<module name="SingleLineJavadoc"/>
Expand Down

0 comments on commit 9dac1f2

Please sign in to comment.