mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Apply hard-coded contract to Assume.assumeThat
Change-Id: I35f88942f58c295b9a7343fc28496f54fc8f4b80
This commit is contained in:
+2
-1
@@ -76,6 +76,7 @@ public class HardcodedContracts {
|
||||
}
|
||||
else if ("junit.framework.Assert".equals(className) ||
|
||||
"org.junit.Assert".equals(className) ||
|
||||
"org.junit.Assume".equals(className) ||
|
||||
"junit.framework.TestCase".equals(className) ||
|
||||
"com.google.common.truth.Truth".equals(className) ||
|
||||
"com.google.common.truth.TestVerb".equals(className) ||
|
||||
@@ -111,7 +112,7 @@ public class HardcodedContracts {
|
||||
|
||||
private static List<MethodContract> handleTestFrameworks(int paramCount, String className, String methodName,
|
||||
@Nullable PsiMethodCallExpression call) {
|
||||
if (("assertThat".equals(methodName) || "that".equals(methodName)) && call != null) {
|
||||
if (("assertThat".equals(methodName) || "assumeThat".equals(methodName) || "that".equals(methodName)) && call != null) {
|
||||
PsiExpression[] args = call.getArgumentList().getExpressions();
|
||||
if (args.length == paramCount) {
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import static org.junit.Assume.assumeThat;
|
||||
|
||||
class Contracts {
|
||||
|
||||
private void checkNotNullValue(@Nullable Object o) {
|
||||
assumeThat(o, CoreMatchers.<Object>notNullValue());
|
||||
System.out.println(o.hashCode());
|
||||
}
|
||||
}
|
||||
@@ -405,6 +405,18 @@ public class DataFlowInspectionTest extends DataFlowInspectionTestCase {
|
||||
myFixture.testHighlighting(true, false, true, getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
public void testAssumeThat() {
|
||||
myFixture.addClass("package org.hamcrest; public class CoreMatchers { " +
|
||||
"public static <T> Matcher<T> notNullValue() {}\n" +
|
||||
"}");
|
||||
myFixture.addClass("package org.hamcrest; public interface Matcher<T> {}");
|
||||
myFixture.addClass("package org.junit; public class Assume { " +
|
||||
"public static <T> void assumeThat(T actual, org.hamcrest.Matcher<? super T> matcher) {}\n" +
|
||||
"}");
|
||||
myFixture.enableInspections(new DataFlowInspection());
|
||||
myFixture.testHighlighting(true, false, true, getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
public void testGoogleTruth() {
|
||||
myFixture.addClass("package com.google.common.truth; public class Truth { " +
|
||||
"public static Subject assertThat(Object o) {}\n" +
|
||||
|
||||
Reference in New Issue
Block a user