fix contracts for junit5 assertions

This commit is contained in:
peter
2017-06-08 16:54:18 +02:00
parent 31ddfe6122
commit 0e938165ea
3 changed files with 34 additions and 2 deletions

View File

@@ -8,4 +8,20 @@ class Contracts {
String s = o.toString();
}
void foo2(@Nullable Object o) {
Assertions.assertNotNull(o, "message");
String s = o.toString();
}
void foo3(java.util.function.BooleanSupplier o) {
Assertions.assertTrue(o, "message");
}
void foo3(boolean b) {
Assertions.assertTrue(b, "message");
if (<warning descr="Condition '!b' is always 'false'">!<warning descr="Value 'b' is always 'true'">b</warning></warning>) {
System.out.println("how?");
}
}
}

View File

@@ -17,11 +17,18 @@ package com.intellij.java.codeInspection;
import com.intellij.JavaTestUtil;
import com.intellij.codeInspection.dataFlow.DataFlowInspection;
import com.intellij.testFramework.LightProjectDescriptor;
import org.jetbrains.annotations.NotNull;
/**
* @author peter
*/
public class HardcodedContractsTest extends DataFlowInspectionTestCase {
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return JAVA_8;
}
@Override
protected String getTestDataPath() {
@@ -110,8 +117,13 @@ public class HardcodedContractsTest extends DataFlowInspectionTestCase {
}
public void testJunit5Assert() {
myFixture.addClass("package org.junit.jupiter.api; public class Assertions {\n" +
myFixture.addClass("package org.junit.jupiter.api;" +
"import java.util.function.BooleanSupplier;" +
"public class Assertions {\n" +
" public static void assertNotNull(Object actual){}" +
" public static void assertNotNull(Object actual, String message){}" +
" public static void assertTrue(boolean b, String message){}" +
" public static void assertTrue(BooleanSupplier b, String message){}" +
"}");
checkHighlighting();
}