Skip to content

Instantly share code, notes, and snippets.

@KingsMentor
Created December 12, 2018 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KingsMentor/9a40b2cddefabac641034af46726d010 to your computer and use it in GitHub Desktop.
Save KingsMentor/9a40b2cddefabac641034af46726d010 to your computer and use it in GitHub Desktop.
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