com.android.tools.lint.checks.infrastructure
Class LintDetectorTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by com.android.testutils.SdkTestCase
              extended by com.android.tools.lint.checks.infrastructure.LintDetectorTest
All Implemented Interfaces:
junit.framework.Test

@Beta
public abstract class LintDetectorTest
extends com.android.testutils.SdkTestCase

Test case for lint detectors.

NOTE: This is not a public or final API; if you rely on this be prepared to adjust your code for the next tools release.


Nested Class Summary
 class LintDetectorTest.BinaryTestFile
           
static class LintDetectorTest.BytecodeProducer
           
static class LintDetectorTest.ByteProducer
          Produces byte arrays, for use with LintDetectorTest.BinaryTestFile
 class LintDetectorTest.CustomIssueRegistry
           
 class LintDetectorTest.JarTestFile
           
 class LintDetectorTest.ManifestTestFile
           
 class LintDetectorTest.PropertyTestFile
           
 class LintDetectorTest.TestConfiguration
           
 class LintDetectorTest.TestLintClient
           
 
Nested classes/interfaces inherited from class com.android.testutils.SdkTestCase
com.android.testutils.SdkTestCase.TestFile
 
Field Summary
 
Fields inherited from class com.android.testutils.SdkTestCase
sCleanDirs
 
Constructor Summary
LintDetectorTest()
           
 
Method Summary
protected  boolean allowCompilationErrors()
           
 LintDetectorTest.BinaryTestFile base64(java.lang.String to, java.lang.String encoded)
          Creates a test file from the given base64 data.
 LintDetectorTest.BinaryTestFile bytecode(java.lang.String to, LintDetectorTest.BytecodeProducer producer)
           
protected  java.lang.String checkLint(LintDetectorTest.TestLintClient lintClient, java.util.List<java.io.File> files)
           
protected  java.lang.String checkLint(java.util.List<java.io.File> files)
           
protected  void checkReportedError(com.android.tools.lint.detector.api.Context context, com.android.tools.lint.detector.api.Issue issue, com.android.tools.lint.detector.api.Severity severity, com.android.tools.lint.detector.api.Location location, java.lang.String message)
           
protected  void configureDriver(com.android.tools.lint.client.api.LintDriver driver)
           
 com.android.testutils.SdkTestCase.TestFile copy(java.lang.String from)
           
 com.android.testutils.SdkTestCase.TestFile copy(java.lang.String from, java.lang.String to)
           
protected  LintDetectorTest.TestLintClient createClient()
           
 com.android.testutils.SdkTestCase.TestFile file()
           
protected  LintDetectorTest.TestConfiguration getConfiguration(com.android.tools.lint.client.api.LintClient client, com.android.tools.lint.detector.api.Project project)
           
protected abstract  com.android.tools.lint.detector.api.Detector getDetector()
           
protected  com.android.tools.lint.detector.api.Detector getDetectorInstance()
           
protected abstract  java.util.List<com.android.tools.lint.detector.api.Issue> getIssues()
           
protected  java.util.EnumSet<com.android.tools.lint.detector.api.Scope> getLintScope(java.util.List<java.io.File> file)
           
protected  java.io.File getProjectDir(java.lang.String name, com.android.testutils.SdkTestCase.TestFile... testFiles)
          Creates a project directory structure from the given files
protected  java.io.File getProjectDir(java.lang.String name, java.lang.String... relativePaths)
          Creates a project directory structure from the given files
protected  java.io.File getRootDir()
          Returns the Android source tree root dir.
 java.lang.String getSuperClass(com.android.tools.lint.detector.api.Project project, java.lang.String name)
           
protected  java.io.File getTargetDir()
           
protected  java.io.InputStream getTestResource(java.lang.String relativePath, boolean expectExists)
           
protected  boolean ignoreSystemErrors()
           
protected  boolean includeParentPath()
           
protected  boolean isEnabled(com.android.tools.lint.detector.api.Issue issue)
           
 LintDetectorTest.JarTestFile jar(java.lang.String to)
           
 LintDetectorTest.JarTestFile jar(java.lang.String to, com.android.testutils.SdkTestCase.TestFile... files)
           
 com.android.testutils.SdkTestCase.TestFile java(java.lang.String source)
           
 com.android.testutils.SdkTestCase.TestFile java(java.lang.String to, java.lang.String source)
           
protected  java.lang.String lintFiles(java.lang.String... relativePaths)
           
protected  java.lang.String lintProject(com.android.testutils.SdkTestCase.TestFile... files)
          Run lint on the given files when constructed as a separate project
protected  java.lang.String lintProject(java.lang.String... relativePaths)
          Run lint on the given files when constructed as a separate project
protected  java.lang.String lintProjectIncrementally(java.lang.String currentFile, com.android.testutils.SdkTestCase.TestFile... files)
           
protected  java.lang.String lintProjectIncrementally(java.lang.String currentFile, java.lang.String... relativePaths)
           
 LintDetectorTest.ManifestTestFile manifest()
           
 LintDetectorTest.PropertyTestFile projectProperties()
           
protected  void setUp()
           
 com.android.testutils.SdkTestCase.TestFile source(java.lang.String to, java.lang.String source)
           
protected  void tearDown()
           
static java.lang.String toBase64(byte[] bytes)
           
static java.lang.String toBase64(java.io.File file)
           
 com.android.testutils.SdkTestCase.TestFile xml(java.lang.String to, java.lang.String source)
           
 
Methods inherited from class com.android.testutils.SdkTestCase
addCleanupDir, addSelection, assertEqualsGolden, assertEqualsGolden, cleanup, deleteFile, findSrcDir, findSrcRelativeDir, getCaretContext, getCaretOffset, getDiff, getDiff, getTempDir, getTestDataRelPath, getTestfile, makeTestFile, makeTestFile, readTestFile, removeSessionData
 
Methods inherited from class junit.framework.TestCase
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runBare, runTest, setName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LintDetectorTest

public LintDetectorTest()
Method Detail

setUp

protected void setUp()
              throws java.lang.Exception
Overrides:
setUp in class junit.framework.TestCase
Throws:
java.lang.Exception

tearDown

protected void tearDown()
                 throws java.lang.Exception
Overrides:
tearDown in class junit.framework.TestCase
Throws:
java.lang.Exception

getDetector

protected abstract com.android.tools.lint.detector.api.Detector getDetector()

getDetectorInstance

protected final com.android.tools.lint.detector.api.Detector getDetectorInstance()

allowCompilationErrors

protected boolean allowCompilationErrors()

getIssues

protected abstract java.util.List<com.android.tools.lint.detector.api.Issue> getIssues()

lintFiles

protected java.lang.String lintFiles(java.lang.String... relativePaths)
                              throws java.lang.Exception
Throws:
java.lang.Exception

checkLint

protected java.lang.String checkLint(java.util.List<java.io.File> files)
                              throws java.lang.Exception
Throws:
java.lang.Exception

checkLint

protected java.lang.String checkLint(LintDetectorTest.TestLintClient lintClient,
                                     java.util.List<java.io.File> files)
                              throws java.lang.Exception
Throws:
java.lang.Exception

checkReportedError

protected void checkReportedError(@NonNull
                                  com.android.tools.lint.detector.api.Context context,
                                  @NonNull
                                  com.android.tools.lint.detector.api.Issue issue,
                                  @NonNull
                                  com.android.tools.lint.detector.api.Severity severity,
                                  @Nullable
                                  com.android.tools.lint.detector.api.Location location,
                                  @NonNull
                                  java.lang.String message)

createClient

protected LintDetectorTest.TestLintClient createClient()

getConfiguration

protected LintDetectorTest.TestConfiguration getConfiguration(com.android.tools.lint.client.api.LintClient client,
                                                              com.android.tools.lint.detector.api.Project project)

configureDriver

protected void configureDriver(com.android.tools.lint.client.api.LintDriver driver)

lintProject

protected java.lang.String lintProject(java.lang.String... relativePaths)
                                throws java.lang.Exception
Run lint on the given files when constructed as a separate project

Returns:
The output of the lint check. On Windows, this transforms all directory separators to the unix-style forward slash.
Throws:
java.lang.Exception

lintProjectIncrementally

protected java.lang.String lintProjectIncrementally(java.lang.String currentFile,
                                                    java.lang.String... relativePaths)
                                             throws java.lang.Exception
Throws:
java.lang.Exception

lintProjectIncrementally

protected java.lang.String lintProjectIncrementally(java.lang.String currentFile,
                                                    com.android.testutils.SdkTestCase.TestFile... files)
                                             throws java.lang.Exception
Throws:
java.lang.Exception

lintProject

protected java.lang.String lintProject(com.android.testutils.SdkTestCase.TestFile... files)
                                throws java.lang.Exception
Run lint on the given files when constructed as a separate project

Returns:
The output of the lint check. On Windows, this transforms all directory separators to the unix-style forward slash.
Throws:
java.lang.Exception

getTargetDir

protected java.io.File getTargetDir()
Overrides:
getTargetDir in class com.android.testutils.SdkTestCase

file

@NonNull
public com.android.testutils.SdkTestCase.TestFile file()

source

@NonNull
public com.android.testutils.SdkTestCase.TestFile source(@NonNull
                                                                 java.lang.String to,
                                                                 @NonNull
                                                                 java.lang.String source)

java

@NonNull
public com.android.testutils.SdkTestCase.TestFile java(@NonNull
                                                               java.lang.String to,
                                                               @NonNull
                                                               java.lang.String source)

java

@NonNull
public com.android.testutils.SdkTestCase.TestFile java(@NonNull
                                                               java.lang.String source)

xml

@NonNull
public com.android.testutils.SdkTestCase.TestFile xml(@NonNull
                                                              java.lang.String to,
                                                              @NonNull
                                                              java.lang.String source)

copy

@NonNull
public com.android.testutils.SdkTestCase.TestFile copy(@NonNull
                                                               java.lang.String from,
                                                               @NonNull
                                                               java.lang.String to)

manifest

@NonNull
public LintDetectorTest.ManifestTestFile manifest()

projectProperties

@NonNull
public LintDetectorTest.PropertyTestFile projectProperties()

bytecode

@NonNull
public LintDetectorTest.BinaryTestFile bytecode(@NonNull
                                                        java.lang.String to,
                                                        @NonNull
                                                        LintDetectorTest.BytecodeProducer producer)

toBase64

public static java.lang.String toBase64(@NonNull
                                        byte[] bytes)

toBase64

public static java.lang.String toBase64(@NonNull
                                        java.io.File file)
                                 throws java.io.IOException
Throws:
java.io.IOException

base64

public LintDetectorTest.BinaryTestFile base64(@NonNull
                                              java.lang.String to,
                                              @NonNull
                                              java.lang.String encoded)
Creates a test file from the given base64 data. To create this data, use toBase64(File) or toBase64(byte[]), for example via assertEquals("", uuencode(new File("path/to/your.class")));

Parameters:
to - the file to write as
encoded - the encoded data
Returns:
the new test file

jar

@NonNull
public LintDetectorTest.JarTestFile jar(@NonNull
                                                java.lang.String to)

jar

@NonNull
public LintDetectorTest.JarTestFile jar(@NonNull
                                                java.lang.String to,
                                                @NonNull
                                                com.android.testutils.SdkTestCase.TestFile... files)

copy

@NonNull
public com.android.testutils.SdkTestCase.TestFile copy(@NonNull
                                                               java.lang.String from)

getProjectDir

protected java.io.File getProjectDir(java.lang.String name,
                                     java.lang.String... relativePaths)
                              throws java.lang.Exception
Creates a project directory structure from the given files

Throws:
java.lang.Exception

getProjectDir

protected java.io.File getProjectDir(java.lang.String name,
                                     com.android.testutils.SdkTestCase.TestFile... testFiles)
                              throws java.lang.Exception
Creates a project directory structure from the given files

Throws:
java.lang.Exception

getTestResource

protected java.io.InputStream getTestResource(java.lang.String relativePath,
                                              boolean expectExists)
Overrides:
getTestResource in class com.android.testutils.SdkTestCase

isEnabled

protected boolean isEnabled(com.android.tools.lint.detector.api.Issue issue)

includeParentPath

protected boolean includeParentPath()

getLintScope

protected java.util.EnumSet<com.android.tools.lint.detector.api.Scope> getLintScope(java.util.List<java.io.File> file)

getSuperClass

public java.lang.String getSuperClass(com.android.tools.lint.detector.api.Project project,
                                      java.lang.String name)

ignoreSystemErrors

protected boolean ignoreSystemErrors()

getRootDir

protected java.io.File getRootDir()
Returns the Android source tree root dir.

Returns:
the root dir or null if it couldn't be computed.