0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-20 03:52:15 +02:00

refactor: Convert InconsistentAnnotationUsageTest to Kotlin

com.ichi2.anki.lint.rules.InconsistentAnnotationUsageTest
This commit is contained in:
David Allison 2022-08-18 18:14:10 +01:00 committed by Mike Hardy
parent 2947fd91a5
commit ab84324548
2 changed files with 59 additions and 59 deletions

View File

@ -42,8 +42,8 @@ permission notice:
// Example of class name: "/com/ichi2/anki/UIUtils.kt"
// Ensure that it starts with '/' (slash)
def source = Source.TEST
def className = "/com/ichi2/anki/lint/rules/InconsistentAnnotationUsageTest.kt"
def source = Source.MAIN
def className = ""
enum Source {
MAIN("/src/main/java"),

View File

@ -13,77 +13,77 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.ichi2.anki.lint.rules
package com.ichi2.anki.lint.rules;
import com.android.tools.lint.checks.infrastructure.TestFile.JavaTestFile
import com.android.tools.lint.checks.infrastructure.TestLintTask
import com.ichi2.anki.lint.utils.KotlinCleanup
import org.intellij.lang.annotations.Language
import org.junit.Assert
import org.junit.Test
import org.intellij.lang.annotations.Language;
import org.junit.Test;
@KotlinCleanup("IDE Lint")
class InconsistentAnnotationUsageTest {
@Language("JAVA")
private val mNotNullUsage = """
package java.util;
import static com.android.tools.lint.checks.infrastructure.TestFile.JavaTestFile.create;
import static com.android.tools.lint.checks.infrastructure.TestLintTask.lint;
import static org.junit.Assert.assertTrue;
public class InconsistentAnnotationUsageTest {
import org.jetbrains.annotations.NotNull;
"""
@Language("JAVA")
private final String mNotNullUsage = " \n" +
"package java.util; \n" +
" \n" +
"import org.jetbrains.annotations.NotNull; \n";
private val mNullable = """
package java.util;
@Language("JAVA")
private final String mNullable = " \n" +
"package java.util; \n" +
" \n" +
"import org.jetbrains.annotations.Nullable; \n";
import org.jetbrains.annotations.Nullable;
"""
// Should be OK
@Language("JAVA")
private final String mContract = " \n" +
"package java.util; \n" +
" \n" +
"import org.jetbrains.annotations.Contract; \n";
private val mContract = """
package java.util;
import org.jetbrains.annotations.Contract;
"""
@Test
public void showsErrorForNotNull() {
lint()
.allowMissingSdk()
.allowCompilationErrors()
.files(create(mNotNullUsage))
.issues(InconsistentAnnotationUsage.ISSUE)
.run()
.expectErrorCount(1)
.check(output -> {
assertTrue(output.contains(InconsistentAnnotationUsage.ID));
assertTrue(output.contains(InconsistentAnnotationUsage.DESCRIPTION));
});
fun showsErrorForNotNull() {
TestLintTask.lint()
.allowMissingSdk()
.allowCompilationErrors()
.files(JavaTestFile.create(mNotNullUsage))
.issues(InconsistentAnnotationUsage.ISSUE)
.run()
.expectErrorCount(1)
.check({ output: String ->
Assert.assertTrue(output.contains(InconsistentAnnotationUsage.ID))
Assert.assertTrue(output.contains(InconsistentAnnotationUsage.DESCRIPTION))
})
}
@Test
public void showsErrorForNullable() {
lint()
.allowMissingSdk()
.allowCompilationErrors()
.files(create(mNullable))
.issues(InconsistentAnnotationUsage.ISSUE)
.run()
.expectErrorCount(1)
.check(output -> {
assertTrue(output.contains(InconsistentAnnotationUsage.ID));
assertTrue(output.contains(InconsistentAnnotationUsage.DESCRIPTION));
});
fun showsErrorForNullable() {
TestLintTask.lint()
.allowMissingSdk()
.allowCompilationErrors()
.files(JavaTestFile.create(mNullable))
.issues(InconsistentAnnotationUsage.ISSUE)
.run()
.expectErrorCount(1)
.check({ output: String ->
Assert.assertTrue(output.contains(InconsistentAnnotationUsage.ID))
Assert.assertTrue(output.contains(InconsistentAnnotationUsage.DESCRIPTION))
})
}
@Test
public void noErrorForContract() {
lint()
.allowMissingSdk()
.allowCompilationErrors()
.files(create(mContract))
.issues(InconsistentAnnotationUsage.ISSUE)
.run()
.expectErrorCount(0);
fun noErrorForContract() {
TestLintTask.lint()
.allowMissingSdk()
.allowCompilationErrors()
.files(JavaTestFile.create(mContract))
.issues(InconsistentAnnotationUsage.ISSUE)
.run()
.expectErrorCount(0)
}
}