Skip to content

Commit 23371c7

Browse files
committed
fix: Remove Error Prone compilation errors
1 parent 30b4843 commit 23371c7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+212
-149
lines changed

testng-asserts/src/test/java/org/testng/AssertTest.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -305,22 +305,10 @@ public void compareUnEqualDoubleArraysWithDelta() {
305305
Assert.assertEquals(actual, expected, 0.1d);
306306
}
307307

308-
@SuppressWarnings("serial")
309308
@Test(expectedExceptions = AssertionError.class)
310309
public void assertEqualsMapShouldFail() {
311-
Map<String, String> mapActual =
312-
new HashMap<String, String>() {
313-
{
314-
put("a", "1");
315-
}
316-
};
317-
Map<String, String> mapExpected =
318-
new HashMap<String, String>() {
319-
{
320-
put("a", "1");
321-
put("b", "2");
322-
}
323-
};
310+
Map<String, String> mapActual = Map.of("a", "1");
311+
Map<String, String> mapExpected = Map.of("a", "1", "b", "2");
324312

325313
Assert.assertEquals(mapActual, mapExpected);
326314
}
@@ -654,12 +642,22 @@ static class BrokenEqualsTrue {
654642
public boolean equals(Object o) {
655643
return true; // broken implementation
656644
}
645+
646+
@Override
647+
public int hashCode() {
648+
return 0;
649+
}
657650
}
658651

659652
static class BrokenEqualsFalse {
660653
@Override
661654
public boolean equals(Object o) {
662655
return false; // broken implementation
663656
}
657+
658+
@Override
659+
public int hashCode() {
660+
return 0;
661+
}
664662
}
665663
}

testng-core/src/main/java/org/testng/SuiteResult.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.testng.xml.XmlSuite;
77

88
/** This class logs the result of an entire Test Suite (defined by a property file). */
9-
class SuiteResult implements ISuiteResult, Comparable<ISuiteResult> {
9+
class SuiteResult implements ISuiteResult, Comparable<SuiteResult> {
1010
private final XmlSuite m_suite;
1111
private final ITestContext m_testContext;
1212

@@ -26,7 +26,7 @@ public XmlSuite getSuite() {
2626
}
2727

2828
@Override
29-
public int compareTo(@Nonnull ISuiteResult other) {
29+
public int compareTo(@Nonnull SuiteResult other) {
3030
int result = 0;
3131
try {
3232
String n1 = getTestContext().getName();

testng-core/src/main/java/org/testng/internal/ClonedMethod.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public boolean hasMoreInvocation() {
138138

139139
@Override
140140
public Class<?> getRealClass() {
141-
return m_javaMethod.getClass();
141+
return m_javaMethod.getDeclaringClass();
142142
}
143143

144144
@Override

testng-core/src/main/java/org/testng/internal/annotations/JDK15TagFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ private Object invokeMethod(Annotation test, String methodName) {
644644
Object result = null;
645645
try {
646646
// Note: we should cache methods already looked up
647-
Method m = test.getClass().getMethod(methodName);
647+
Method m = test.annotationType().getMethod(methodName);
648648
result = m.invoke(test);
649649
} catch (Exception e) {
650650
Logger.getLogger(JDK15TagFactory.class).error(e.getMessage(), e);

testng-core/src/test/java/NoPackageTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import static org.testng.Assert.assertTrue;
2+
13
import org.testng.annotations.AfterMethod;
24
import org.testng.annotations.Test;
35

@@ -12,6 +14,6 @@ public void test() {
1214

1315
@AfterMethod(groups = {"nopackage"})
1416
public void after() {
15-
assert m_run : "test method was not run";
17+
assertTrue(m_run, "test method was not run");
1618
}
1719
}

testng-core/src/test/java/test/ClassConfigurations.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package test;
22

3+
import static org.testng.Assert.assertEquals;
4+
35
import org.testng.annotations.AfterTest;
46
import org.testng.annotations.BeforeClass;
57
import org.testng.annotations.Test;
@@ -29,22 +31,19 @@ public void afterTestClass() {
2931

3032
@Test
3133
public void testOne() {
32-
// System.out.println("testOne");
33-
assert beforeCount == 1;
34-
assert afterCount == 0;
34+
assertEquals(beforeCount, 1);
35+
assertEquals(afterCount, 0);
3536
}
3637

3738
@Test
3839
public void testTwo() {
39-
// System.out.println("testTwo");
40-
assert beforeCount == 1;
41-
assert afterCount == 0;
40+
assertEquals(beforeCount, 1);
41+
assertEquals(afterCount, 0);
4242
}
4343

4444
@Test
4545
public void testThree() {
46-
// System.out.println("testThree");
47-
assert beforeCount == 1;
48-
assert afterCount == 0;
46+
assertEquals(beforeCount, 1);
47+
assertEquals(afterCount, 0);
4948
}
5049
}

testng-core/src/test/java/test/CtorCalledOnce.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package test;
22

3+
import static org.testng.Assert.assertEquals;
4+
35
import org.testng.annotations.AfterTest;
46
import org.testng.annotations.Test;
57

@@ -16,17 +18,17 @@ public CtorCalledOnce() {
1618

1719
@Test
1820
public void testMethod1() {
19-
assert instantiated == 1 : "Expected 1, was invoked " + instantiated + " times";
21+
assertEquals(instantiated, 1, "Expected 1, was invoked " + instantiated + " times");
2022
}
2123

2224
@Test
2325
public void testMethod2() {
24-
assert instantiated == 1 : "Expected 1, was invoked " + instantiated + " times";
26+
assertEquals(instantiated, 1, "Expected 1, was invoked " + instantiated + " times");
2527
}
2628

2729
@Test
2830
public void testMethod3() {
29-
assert instantiated == 1 : "Expected 1, was invoked " + instantiated + " times";
31+
assertEquals(instantiated, 1, "Expected 1, was invoked " + instantiated + " times");
3032
}
3133

3234
@AfterTest

testng-core/src/test/java/test/Exclude.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package test;
22

3+
import static org.testng.Assert.assertTrue;
4+
35
import org.testng.annotations.Test;
46

57
public class Exclude {
@@ -32,14 +34,15 @@ public void excluded2() {
3234
dependsOnGroups = {"group1"},
3335
groups = {"group2"})
3436
public void verify() {
35-
assert m_included1 && m_included2 && m_excluded1 && m_excluded2
36-
: "Should all be true: "
37+
assertTrue(
38+
m_included1 && m_included2 && m_excluded1 && m_excluded2,
39+
"Should all be true: "
3740
+ m_included1
3841
+ " "
3942
+ m_included2
4043
+ " "
4144
+ m_excluded1
4245
+ " "
43-
+ m_excluded2;
46+
+ m_excluded2);
4447
}
4548
}

testng-core/src/test/java/test/MethodTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package test;
22

3+
import static org.testng.AssertJUnit.assertEquals;
4+
35
import org.testng.Assert;
46
import org.testng.annotations.Test;
57
import test.sample.Sample2;
@@ -36,7 +38,7 @@ public void excludeMethodsOnly() {
3638
@Test
3739
public void excludePackage() {
3840
addClass(CLASS_NAME);
39-
assert 1 == getTest().getXmlClasses().size();
41+
assertEquals(getTest().getXmlClasses().size(), 1);
4042
addExcludedMethod(CLASS_NAME, ".*");
4143
run();
4244
String[] passed = {};

testng-core/src/test/java/test/NestedStaticTest.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package test;
22

3-
import java.util.HashSet;
43
import java.util.List;
54
import java.util.Set;
65
import org.testng.Assert;
@@ -19,13 +18,7 @@ public void nestedClassShouldBeIncluded() {
1918
tng.addListener(tla);
2019
tng.run();
2120

22-
Set<String> expected =
23-
new HashSet<String>() {
24-
{
25-
add("nested");
26-
add("f");
27-
}
28-
};
21+
Set<String> expected = Set.of("nested", "f");
2922
Set<String> actual = Sets.newHashSet();
3023
List<ITestResult> passedTests = tla.getPassedTests();
3124
for (ITestResult t : passedTests) {

0 commit comments

Comments
 (0)