diff options
Diffstat (limited to 'java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy')
-rw-r--r-- | java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy b/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy index c3bb014d8342..d8b6fb2c53df 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy @@ -161,11 +161,10 @@ class ContractInferenceFromSourceTest extends LightCodeInsightFixtureTestCase { assert c == ['null -> fail'] } - void "_test no NotNull duplication"() { + void "test no return value NotNull duplication"() { def c = inferContracts(""" - boolean smth(@org.jetbrains.annotations.NotNull Object o) { - if (o == null) throw new RuntimeException(); - return o.hashCode() == 1; + @org.jetbrains.annotations.NotNull String smth(Object o) { + return "abc"; } """) assert c == [] @@ -334,29 +333,41 @@ class ContractInferenceFromSourceTest extends LightCodeInsightFixtureTestCase { assert c == ['null -> null'] } - public void "test go inside try"() { + public void "test use invoked method notnull"() { def c = inferContracts(""" final Object foo(Object bar) { - try { - if (bar == null) return null; - bar = smth(bar); - } finally {} - return new String("abc"); + if (bar == null) return null; + return doo(); } + + @org.jetbrains.annotations.NotNull Object doo() {} """) - assert c == ['null -> null'] + assert c == ['null -> null', '!null -> !null'] } - public void "test use invoked method notnull"() { + public void "test use delegated method notnull"() { def c = inferContracts(""" final Object foo(Object bar) { - if (bar == null) return null; return doo(); } @org.jetbrains.annotations.NotNull Object doo() {} """) - assert c == ['null -> null', '!null -> !null'] + assert c == ['_ -> !null'] + } + + public void "test use delegated method notnull with contracts"() { + def c = inferContracts(""" + final Object foo(Object bar, Object o2) { + return doo(o2); + } + + @org.jetbrains.annotations.NotNull Object doo(Object o) { + if (o == null) throw new RuntimeException(); + return smth(); + } + """) + assert c == ['_, null -> fail', '_, _ -> !null'] } private String inferContract(String method) { |