summaryrefslogtreecommitdiff
path: root/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy
diff options
context:
space:
mode:
Diffstat (limited to 'java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy')
-rw-r--r--java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy49
1 files changed, 49 insertions, 0 deletions
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy b/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy
index ab9a5660b8ad..32982f3687df 100644
--- a/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy
@@ -171,6 +171,55 @@ class ContractInferenceFromSourceTest extends LightCodeInsightFixtureTestCase {
assert c == []
}
+ public void "test plain delegation"() {
+ def c = inferContracts("""
+ boolean delegating(Object o) {
+ return smth(o);
+ }
+ boolean smth(Object o) {
+ assert o instanceof String;
+ return true;
+ }
+""")
+ assert c == ['null -> fail']
+ }
+
+ public void "test arg swapping delegation"() {
+ def c = inferContracts("""
+ boolean delegating(Object o, Object o1) {
+ return smth(o1, o);
+ }
+ boolean smth(Object o, Object o1) {
+ return o == null && o1 != null;
+ }
+""")
+ assert c == ['_, !null -> false', 'null, null -> false', '!null, null -> true']
+ }
+
+ public void "test negating delegation"() {
+ def c = inferContracts("""
+ boolean delegating(Object o) {
+ return !smth(o);
+ }
+ boolean smth(Object o) {
+ return o == null;
+ }
+""")
+ assert c == ['null -> false', '!null -> true']
+ }
+
+ public void "test delegation with constant"() {
+ def c = inferContracts("""
+ boolean delegating(Object o) {
+ return smth(null);
+ }
+ boolean smth(Object o) {
+ return o == null;
+ }
+""")
+ assert c == ['_ -> true']
+ }
+
private String inferContract(String method) {
return assertOneElement(inferContracts(method))
}