Fixed
Status Update
Comments
mi...@gmail.com <mi...@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;
}
}
mi...@gmail.com <mi...@gmail.com> #3
[Comment deleted]
en...@google.com <en...@google.com>
fe...@gmail.com <fe...@gmail.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:
na...@google.com <na...@google.com> #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]
Description
OS: 5.0.2
To reproduce:
{{{
java.text.DateFormat dateFormat = android.text.format.DateFormat.getMediumDateFormat(this);
@Override
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeSerializable(dateFormat);
}
}}}
Stacktrace:
{{{
E/AndroidRuntime( 5652): java.lang.UnsupportedOperationException: Minus sign spans multiple characters: -
E/AndroidRuntime( 5652): at java.text.DecimalFormatSymbols.getMinusSign(DecimalFormatSymbols.java:300)
E/AndroidRuntime( 5652): at java.text.DecimalFormatSymbols.writeObject(DecimalFormatSymbols.java:611)
E/AndroidRuntime( 5652): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 5652): at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime( 5652): at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1033)
E/AndroidRuntime( 5652): at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1384)
E/AndroidRuntime( 5652): at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
E/AndroidRuntime( 5652): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
E/AndroidRuntime( 5652): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
E/AndroidRuntime( 5652): at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:904)
E/AndroidRuntime( 5652): at java.io.ObjectOutputStream.writeFields(ObjectOutputStream.java:863)
E/AndroidRuntime( 5652): at java.text.DecimalFormat.writeObject(DecimalFormat.java:1129)
E/AndroidRuntime( 5652): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 5652): at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime( 5652): at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1033)
E/AndroidRuntime( 5652): at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1384)
E/AndroidRuntime( 5652): at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
E/AndroidRuntime( 5652): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
E/AndroidRuntime( 5652): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
E/AndroidRuntime( 5652): at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:959)
E/AndroidRuntime( 5652): at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:360)
E/AndroidRuntime( 5652): at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1054)
E/AndroidRuntime( 5652): at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1384)
E/AndroidRuntime( 5652): at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
E/AndroidRuntime( 5652): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
E/AndroidRuntime( 5652): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
E/AndroidRuntime( 5652): at android.os.Parcel.writeSerializable(Parcel.java:1383)
}}}