-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue #29: Hints for "Convert to assertTrue/assertFalse" should also …
…support junit.framework.Assert
- Loading branch information
Showing
4 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project-shared-configuration> | ||
<!-- | ||
This file contains additional configuration written by modules in the NetBeans IDE. | ||
The configuration is intended to be shared among all the users of project and | ||
therefore it is assumed to be part of version control checkout. | ||
Without this configuration present, some functionality in the IDE may be limited or fail altogether. | ||
--> | ||
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1"> | ||
<!-- | ||
Properties that influence various parts of the IDE, especially code formatting and the like. | ||
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up. | ||
That way multiple projects can share the same settings (useful for formatting rules for example). | ||
Any value defined here will override the pom.xml file value but is only applicable to the current project. | ||
--> | ||
<netbeans.compile.on.save>all</netbeans.compile.on.save> | ||
<netbeans.hint.jdkPlatform>JDK_1.7</netbeans.hint.jdkPlatform> | ||
</properties> | ||
</project-shared-configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
...test/java/de/markiewb/netbeans/plugins/hints/assertfix/ConvertToAssertTrueFalse2Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package de.markiewb.netbeans.plugins.hints.assertfix; | ||
|
||
import org.junit.Test; | ||
import org.netbeans.modules.java.hints.test.api.HintTest; | ||
import org.openide.filesystems.FileUtil; | ||
|
||
public class ConvertToAssertTrueFalse2Test { | ||
|
||
@Test | ||
public void testERR_computeAssertTrueWithoutMessage2() throws Exception { | ||
HintTest.create() | ||
.input("package test;\n" | ||
+ "public class Test {\n" | ||
+ " public static void main(String[] args) {\n" | ||
+ " junit.framework.Assert.assertEquals(true, false);\n" | ||
+ " }\n" | ||
+ "}\n") | ||
.classpath(FileUtil.getArchiveRoot(junit.framework.Assert.class.getProtectionDomain().getCodeSource().getLocation())) | ||
.run(ConvertToAssertTrueFalse.class) | ||
.findWarning("3:31-3:43:hint:" + Bundle.ERR_computeAssertTrueWithoutMessage2()) | ||
.applyFix() | ||
.assertCompilable() | ||
.assertOutput("package test;\n" | ||
+ "import junit.framework.Assert;\n" | ||
+ "public class Test {\n" | ||
+ " public static void main(String[] args) {\n" | ||
+ " Assert.assertTrue(false);\n" | ||
+ " }\n" | ||
+ "}\n"); | ||
|
||
} | ||
@Test | ||
public void testERR_computeAssertTrueWithMessage2() throws Exception { | ||
HintTest.create() | ||
.input("package test;\n" | ||
+ "public class Test {\n" | ||
+ " public static void main(String[] args) {\n" | ||
+ " junit.framework.Assert.assertEquals(\"expected different result\", true, false);\n" | ||
+ " }\n" | ||
+ "}\n") | ||
.classpath(FileUtil.getArchiveRoot(junit.framework.Assert.class.getProtectionDomain().getCodeSource().getLocation())) | ||
.run(ConvertToAssertTrueFalse.class) | ||
.findWarning("3:31-3:43:hint:" + Bundle.ERR_computeAssertTrueWithMessage2()) | ||
.applyFix() | ||
.assertCompilable() | ||
.assertOutput("package test;\n" | ||
+ "import junit.framework.Assert;\n" | ||
+ "public class Test {\n" | ||
+ " public static void main(String[] args) {\n" | ||
+ " Assert.assertTrue(\"expected different result\", false);\n" | ||
+ " }\n" | ||
+ "}\n"); | ||
|
||
} | ||
@Test | ||
public void testERR_computeAssertFalseWithoutMessage2() throws Exception { | ||
HintTest.create() | ||
.input("package test;\n" | ||
+ "public class Test {\n" | ||
+ " public static void main(String[] args) {\n" | ||
+ " junit.framework.Assert.assertEquals(false, false);\n" | ||
+ " }\n" | ||
+ "}\n") | ||
.classpath(FileUtil.getArchiveRoot(junit.framework.Assert.class.getProtectionDomain().getCodeSource().getLocation())) | ||
.run(ConvertToAssertTrueFalse.class) | ||
.findWarning("3:31-3:43:hint:" + Bundle.ERR_computeAssertFalseWithoutMessage2()) | ||
.applyFix() | ||
.assertCompilable() | ||
.assertOutput("package test;\n" | ||
+ "import junit.framework.Assert;\n" | ||
+ "public class Test {\n" | ||
+ " public static void main(String[] args) {\n" | ||
+ " Assert.assertFalse(false);\n" | ||
+ " }\n" | ||
+ "}\n"); | ||
|
||
} | ||
@Test | ||
public void testERR_computeAssertFalseWithMessage2() throws Exception { | ||
HintTest.create() | ||
.input("package test;\n" | ||
+ "public class Test {\n" | ||
+ " public static void main(String[] args) {\n" | ||
+ " junit.framework.Assert.assertEquals(\"expected different result\", false, true);\n" | ||
+ " }\n" | ||
+ "}\n") | ||
.classpath(FileUtil.getArchiveRoot(junit.framework.Assert.class.getProtectionDomain().getCodeSource().getLocation())) | ||
.run(ConvertToAssertTrueFalse.class) | ||
.findWarning("3:31-3:43:hint:" + Bundle.ERR_computeAssertFalseWithMessage2()) | ||
.applyFix() | ||
.assertCompilable() | ||
.assertOutput("package test;\n" | ||
+ "import junit.framework.Assert;\n" | ||
+ "public class Test {\n" | ||
+ " public static void main(String[] args) {\n" | ||
+ " Assert.assertFalse(\"expected different result\", true);\n" | ||
+ " }\n" | ||
+ "}\n"); | ||
|
||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/test/java/example/ConvertToAssertTrueFalseExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package example; | ||
|
||
public class ConvertToAssertTrueFalseExample { | ||
|
||
public static void main(String[] args) { | ||
boolean actual = false; | ||
org.junit.Assert.assertEquals("Not correct", true, actual); | ||
junit.framework.Assert.assertEquals("Not correct", true, actual); | ||
org.junit.Assert.assertEquals(true, actual); | ||
junit.framework.Assert.assertEquals(true, actual); | ||
org.junit.Assert.assertEquals(false, actual); | ||
junit.framework.Assert.assertEquals(false, actual); | ||
} | ||
|
||
} |