Created
December 12, 2018 15:45
-
-
Save KingsMentor/9a40b2cddefabac641034af46726d010 to your computer and use it in GitHub Desktop.
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
public abstract class AbstractDetectorTest extends LintDetectorTest { | |
protected static final String PATH_TEST_RESOURCES = "/lint/src/test/resources/"; | |
protected static final String NO_WARNINGS = "No warnings."; | |
protected abstract String getTestResourceDirectory(); | |
@Override | |
protected InputStream getTestResource(String relativePath, boolean expectExists) { | |
String path = (PATH_TEST_RESOURCES + getTestResourceDirectory() + File.separatorChar + relativePath).replace('/', File.separatorChar); | |
File file = new File(getTestDataRootDir(), path); | |
if (file.exists()) { | |
try { | |
return new BufferedInputStream(new FileInputStream(file)); | |
} catch (FileNotFoundException e) { | |
if (expectExists) { | |
fail("Could not find file " + relativePath); | |
} | |
} | |
} | |
return null; | |
} | |
private File getTestDataRootDir() { | |
CodeSource source = getClass().getProtectionDomain().getCodeSource(); | |
if (source != null) { | |
URL location = source.getLocation(); | |
try { | |
File classesDir = SdkUtils.urlToFile(location); | |
return classesDir.getParentFile().getAbsoluteFile().getParentFile().getParentFile(); | |
} catch (MalformedURLException e) { | |
fail(e.getLocalizedMessage()); | |
} | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment