IG: add test for negated conditional

This commit is contained in:
Bas Leijdekkers
2015-10-25 19:53:12 +01:00
parent cada6c39e9
commit 3445d6ad80
3 changed files with 47 additions and 19 deletions
@@ -0,0 +1,20 @@
class NegatedConditional {
String text;
public boolean equals(Object object) {
if (this == object) return true;
if (!(object instanceof NegatedConditional)) return false;
if (!super.equals(object)) return false;
final NegatedConditional that = (NegatedConditional)object;
return text != null ? text.equals(that.text) : that.text == null;
}
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (text != null ? text.hashCode() : 0);
return result;
}
}
@@ -0,0 +1,21 @@
class NegatedConditional {
String text;
public boolean equals(Object object) {
if (this == object) return true;
if (!(object instanceof NegatedConditional)) return false;
if (!super.equals(object)) return false;
final NegatedConditional that = (NegatedConditional)object;
<caret>if (text != null ? !text.equals(that.text) : that.text != null) return false;
return true;
}
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (text != null ? text.hashCode() : 0);
return result;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,13 +15,10 @@
*/
package com.siyeh.ig.fixes.controlflow;
import com.intellij.codeInsight.intention.IntentionAction;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.IGQuickFixesTestCase;
import com.siyeh.ig.controlflow.TrivialIfInspection;
import java.util.List;
public class TrivialIfFixTest extends IGQuickFixesTestCase {
@Override
@@ -29,28 +26,18 @@ public class TrivialIfFixTest extends IGQuickFixesTestCase {
super.setUp();
myFixture.enableInspections(new TrivialIfInspection());
myRelativePath = "controlflow/trivialIf";
myDefaultHint = InspectionGadgetsBundle.message("constant.conditional.expression.simplify.quickfix");
}
public void testComments() {
doTestByName(getTestName(false));
doTest();
}
public void testCommentsInAssignment() {
doTestByName(getTestName(false));
doTest();
}
public void doTestByName(String testName) {
myFixture.configureByFile(getRelativePath() + "/" + testName + ".java");
final String message = InspectionGadgetsBundle.message("constant.conditional.expression.simplify.quickfix");
final List<IntentionAction> actions =
myFixture.filterAvailableIntentions(message);
assertFalse("No actions available", actions.isEmpty());
for (IntentionAction action : actions) {
if (action.getText().equals(message)) {
myFixture.launchAction(action);
myFixture.checkResultByFile(getRelativePath() + "/" + testName + ".after.java");
break;
}
}
public void testNegatedConditional() {
doTest();
}
}