Status Update
Comments
e....@gmail.com <e....@gmail.com> #2
My workaround:
source files and data files:
src/test//java/me/ycdev/android/arch/lint/AbstractCheckTest.java
src/test//java/me/ycdev/android/arch/lint/MyToastHelperDetectorTest.java
src/test//java/me/ycdev/android/arch/lint/testdata/src/test/pkg/MyToastHelperTest.java.txt
public class MyToastHelperDetectorTest extends AbstractCheckTest {
...
}
public abstract class AbstractCheckTest extends LintDetectorTest {
@Override
protected InputStream getTestResource(String relativePath, boolean expectExists) {
String path = "testdata" + File.separator + relativePath; //$NON-NLS-1$
InputStream stream = AbstractCheckTest.class.getResourceAsStream(path);
if (stream == null) {
File root = getTestDataRootDir();
assertNotNull(root);
String pkg = AbstractCheckTest.class.getName();
pkg = pkg.substring(0, pkg.lastIndexOf('.'));
File f = new File(root,
"src/test/java/".replace('/', File.separatorChar)
+ pkg.replace('.', File.separatorChar)
+ File.separatorChar + path);
if (f.exists()) {
try {
return new BufferedInputStream(new FileInputStream(f));
} catch (FileNotFoundException e) {
stream = null;
if (expectExists) {
fail("Could not find file " + relativePath);
}
}
}
}
if (!expectExists && stream == null) {
return null;
}
return stream;
}
private File getTestDataRootDir() {
CodeSource source = getClass().getProtectionDomain().getCodeSource();
if (source != null) {
URL location = source.getLocation();
try {
File classesDir = SdkUtils.urlToFile(location);
// "<module root dir>/build/classes/test" --> "<module root dir>"
return classesDir.getParentFile().getAbsoluteFile().getParentFile().getParentFile();
} catch (MalformedURLException e) {
fail(e.getLocalizedMessage());
}
}
return null;
}
}
source files and data files:
src/test//java/me/ycdev/android/arch/lint/AbstractCheckTest.java
src/test//java/me/ycdev/android/arch/lint/MyToastHelperDetectorTest.java
src/test//java/me/ycdev/android/arch/lint/testdata/src/test/pkg/MyToastHelperTest.java.txt
public class MyToastHelperDetectorTest extends AbstractCheckTest {
...
}
public abstract class AbstractCheckTest extends LintDetectorTest {
@Override
protected InputStream getTestResource(String relativePath, boolean expectExists) {
String path = "testdata" + File.separator + relativePath; //$NON-NLS-1$
InputStream stream = AbstractCheckTest.class.getResourceAsStream(path);
if (stream == null) {
File root = getTestDataRootDir();
assertNotNull(root);
String pkg = AbstractCheckTest.class.getName();
pkg = pkg.substring(0, pkg.lastIndexOf('.'));
File f = new File(root,
"src/test/java/".replace('/', File.separatorChar)
+ pkg.replace('.', File.separatorChar)
+ File.separatorChar + path);
if (f.exists()) {
try {
return new BufferedInputStream(new FileInputStream(f));
} catch (FileNotFoundException e) {
stream = null;
if (expectExists) {
fail("Could not find file " + relativePath);
}
}
}
}
if (!expectExists && stream == null) {
return null;
}
return stream;
}
private File getTestDataRootDir() {
CodeSource source = getClass().getProtectionDomain().getCodeSource();
if (source != null) {
URL location = source.getLocation();
try {
File classesDir = SdkUtils.urlToFile(location);
// "<module root dir>/build/classes/test" --> "<module root dir>"
return classesDir.getParentFile().getAbsoluteFile().getParentFile().getParentFile();
} catch (MalformedURLException e) {
fail(e.getLocalizedMessage());
}
}
return null;
}
}
je...@google.com <je...@google.com> #4
This for reporting this. I hadn't noticed this earlier because in the other uses of this, each subclass (for example, in the base distribution, AbstractCheckTest) overrides getTestResource() to do its own handling.
Fixed for 1.4.
(FYI for most of the lint unit tests I'm gradually switching over to inlining test cases.
XML example:
https://android-review.googlesource.com/#/c/162737/3/lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/ManifestDetectorTest.java
Java example:
https://android-review.googlesource.com/#/c/166225/1/lint/cli/src/test/java/com/android/tools/lint/checks/SupportAnnotationDetectorTest.java
Fixed for 1.4.
(FYI for most of the lint unit tests I'm gradually switching over to inlining test cases.
XML example:
Java example:
be...@google.com <be...@google.com>
be...@google.com <be...@google.com>
[Deleted User] <[Deleted User]> #5
Hi Tor,
cool, thank you very much for pointing out the inline approach, I was not aware of this!
Btw, recently the Android (UI) testing have moved from the JUnit 3 approach of extending a certain TestCase super class to the JUnit 4 approach of rules [1] (e.g. ActivityTestRule, ServiceTestRule, ...).
I like this idea and I'm wondering if you have plans to switch to JUnit 4 too?
However I've implemented such rule already (also to expose Warnings for more powerful assertions). But it's nothing official of course:https://github.com/a11n/lint-junit-rule
Thank you,
André
[1]https://github.com/junit-team/junit/wiki/Rules
cool, thank you very much for pointing out the inline approach, I was not aware of this!
Btw, recently the Android (UI) testing have moved from the JUnit 3 approach of extending a certain TestCase super class to the JUnit 4 approach of rules [1] (e.g. ActivityTestRule, ServiceTestRule, ...).
I like this idea and I'm wondering if you have plans to switch to JUnit 4 too?
However I've implemented such rule already (also to expose Warnings for more powerful assertions). But it's nothing official of course:
Thank you,
André
[1]
be...@google.com <be...@google.com>
vi...@gmail.com <vi...@gmail.com> #8
[Comment deleted]
vi...@gmail.com <vi...@gmail.com> #9
FYI: #212672 and this issue are related: when you fix one, the other one becomes relevant.
Description
Gradle plugin version: 2.0.0
Build number: #AI-143.2739321
Issue:
Application crashes with the following exception
Caused by: java.lang.VerifyError:
Verifier rejected class net.xpece.android.support.preference.XpInsetDrawable due to bad method
java.lang.Object net.xpece.android.support.preference.XpInsetDrawable.access$super(
net.xpece.android.support.preference.XpInsetDrawable,
java.lang.String,
java.lang.Object[])
(declaration of 'net.xpece.android.support.preference.XpInsetDrawable'
appears in /data/data/net.xpece.android.support.preference.sample/files/instant-ru
at runtime upon entering XpInsetDrawable.create(Drawable, int) method.
Class code:
final class XpInsetDrawable extends InsetDrawable {
private static final boolean NEEDS_FIXING = Build.VERSION.SDK_INT < 21;
private final Rect mInset = new Rect();
public static InsetDrawable create(final Drawable drawable, final int insetLeft, final int insetTop, final int insetRight, final int insetBottom) {
if (NEEDS_FIXING) {
return new XpInsetDrawable(drawable, insetLeft, insetTop, insetRight, insetBottom);
} else {
return new InsetDrawable(drawable, insetLeft, insetTop, insetRight, insetBottom);
}
}
public static InsetDrawable create(final Drawable drawable, final int inset) {
if (NEEDS_FIXING) {
return new XpInsetDrawable(drawable, inset);
} else {
return new InsetDrawable(drawable, inset);
}
}
XpInsetDrawable(final Drawable drawable, final int inset) {
super(drawable, inset);
mInset.set(inset, inset, inset, inset);
}
XpInsetDrawable(final Drawable drawable, final int insetLeft, final int insetTop, final int insetRight, final int insetBottom) {
super(drawable, insetLeft, insetTop, insetRight, insetBottom);
mInset.set(insetLeft, insetTop, insetRight, insetBottom);
}
@Override
public int getIntrinsicHeight() {
return super.getIntrinsicHeight() + mInset.top + mInset.bottom;
}
@Override
public int getIntrinsicWidth() {
return super.getIntrinsicWidth() + mInset.left + mInset.right;
}
}
Repro steps:
1) Clone sample project from
2) Instant run sample project.
Android Studio Log: Attached.
ADB bugreport at request.