Closed Bug 938821 Opened 11 years ago Closed 11 years ago

Remove reflection from ContentProviderTest and extending classes

Categories

(Firefox for Android Graveyard :: Testing, defect)

All
Android
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
Firefox 30

People

(Reporter: mcomella, Assigned: nalexander)

References

Details

(Whiteboard: [mentor=mcomella][lang=java])

Attachments

(10 files, 1 obsolete file)

(deleted), patch
mcomella
: review+
Details | Diff | Splinter Review
(deleted), patch
mcomella
: review+
Details | Diff | Splinter Review
(deleted), patch
mcomella
: review+
Details | Diff | Splinter Review
(deleted), patch
mcomella
: review+
Details | Diff | Splinter Review
(deleted), patch
mcomella
: review+
Details | Diff | Splinter Review
(deleted), patch
mcomella
: review+
Details | Diff | Splinter Review
(deleted), patch
mcomella
: review+
Details | Diff | Splinter Review
(deleted), patch
mcomella
: review+
Details | Diff | Splinter Review
(deleted), patch
mcomella
: review+
Details | Diff | Splinter Review
(deleted), patch
mcomella
: review+
Details | Diff | Splinter Review
Reflection is used in setUp in order to get instances of the extending classes - we should just pass those classes in directly.
Whiteboard: [mentor=mcomella][lang=java]
Spoke with Taylor on IRC.
Assignee: nobody → taylor
Spoke with Taylor on IRC.
Assignee: taylor → nobody
FRI, hopefully bug 949208 will address at least part of this.
Can I take this bug?
Flags: needinfo?(michael.l.comella)
Of course! :) Let me know if you need a better description of what to do.
Assignee: nobody → isurae
Status: NEW → ASSIGNED
Flags: needinfo?(michael.l.comella)
Hi Michael, In testHomeListsProvider there is reference to org.mozilla.gecko.db.HomeListsProvider. However I can't HomeLIstsProvider class in the source.
(In reply to Isura Edirisinghe from comment #6) > Hi Michael, > > In testHomeListsProvider there is reference to > org.mozilla.gecko.db.HomeListsProvider. However I can't HomeLIstsProvider > class in the source. It has been renamed to HomeProvider.java now, and it's functionality has changed quite a bit since that test was written, which is why it's disabled until we get the chance to update it. If you want to take on updating that test, you could go for it, but otherwise I would say you don't need to worry about fixing it.
Fixing testHomeListsProvider is bug 964464. Isura, as Margaret mentioned, you don't need to worry about it (unless you want to!).
Attached patch 938821.patch (obsolete) (deleted) — Splinter Review
Attachment #8368310 - Flags: review?(michael.l.comella)
Comment on attachment 8368310 [details] [diff] [review] 938821.patch Review of attachment 8368310 [details] [diff] [review]: ----------------------------------------------------------------- We want to remove all instances of reflection, not just the instantiation. I find reflection is easiest to find by looking for which reflection classes are imported by searching for ".reflect." or similar (e.g. `java.lang.reflect.Method`) and replace their uses with compile-time equivalents. Additionally, search for the `ClassLoader` class, which does not need to be imported. Don't forget to remove the imports! ::: mobile/android/base/tests/ContentProviderTest.java @@ +174,2 @@ > String authorityField) throws Exception { > mProviderContract = mClassLoader.loadClass("org.mozilla.gecko.db.BrowserContract"); We should remove any use of ClassLoaders. @@ +174,4 @@ > String authorityField) throws Exception { > mProviderContract = mClassLoader.loadClass("org.mozilla.gecko.db.BrowserContract"); > mProviderAuthority = (String) mProviderContract.getField(authorityField).get(null); > + mProviderClass = providerClass; We shouldn't need to store this class - we should be able to call it directly. It seems the only use is newInstance(), which means we can just call `new ProviderClass(...);` instead.
Attachment #8368310 - Flags: review?(michael.l.comella) → review-
Okay it's clear now! I thought the bug was only referring to the TODO comment :)
This is rather artificial, since the test is currently disabled it merely needs to compile.
Attachment #8372912 - Flags: review?(michael.l.comella)
Isura: I'd like to apoligise for taking an assigned bug; I was working in the area, moved on this, and didn't realize you were already looking into it. mcomella: these transformations are essentially mechanical. They're broken into pieces for my sanity, if not yours. The proof is in the pudding, a green try build: https://tbpl.mozilla.org/?tree=Try&rev=48c4ace2b5ab
Assignee: isurae → nalexander
Attachment #8372911 - Flags: review?(michael.l.comella) → review+
Comment on attachment 8372912 [details] [diff] [review] Part 2: Remove getContentUri and get*Column from testHomeListsProvider. Review of attachment 8372912 [details] [diff] [review]: ----------------------------------------------------------------- r+ w/ comment. ::: mobile/android/base/tests/testHomeListsProvider.java @@ +7,5 @@ > > public class testHomeListsProvider extends ContentProviderTest { > + private static class Contract { > + public static final Uri CONTENT_URI = null; > + public static final Uri CONTENT_FAKE_URI = null; Add a comment explaining that these are not init because they were added in a refactor where the disabled test only needed to compile.
Attachment #8372912 - Flags: review?(michael.l.comella) → review+
Attachment #8372913 - Flags: review?(michael.l.comella) → review+
Attachment #8372914 - Flags: review?(michael.l.comella) → review+
Attachment #8372915 - Flags: review?(michael.l.comella) → review+
Attachment #8372916 - Flags: review?(michael.l.comella) → review+
Attachment #8372917 - Flags: review?(michael.l.comella) → review+
Attachment #8372918 - Flags: review?(michael.l.comella) → review+
Comment on attachment 8372919 [details] [diff] [review] Part 9: Remove reflection from ContentProviderTest.authority. Review of attachment 8372919 [details] [diff] [review]: ----------------------------------------------------------------- ::: mobile/android/base/tests/testHomeListsProvider.java @@ +32,5 @@ > } > > @Override > public void setUp() throws Exception { > + // This test is disabled, so this just needs to compile. Nice, though I still think we should add the comment in patch #2's review as well.
Attachment #8372919 - Flags: review?(michael.l.comella) → review+
Comment on attachment 8372920 [details] [diff] [review] Part 10: Remove reflection from ContentProviderTest. Review of attachment 8372920 [details] [diff] [review]: ----------------------------------------------------------------- r+ w/ nits. ::: mobile/android/base/tests/ContentProviderTest.java @@ +173,5 @@ > > + /** > + * Factory function that makes new ContentProvider instances. > + * <p> > + * We want a fresh provider each test, so this is invoked in nit: "...so this should be invoked...". This comment's existence does not make it so. ;) @@ +176,5 @@ > + * <p> > + * We want a fresh provider each test, so this is invoked in > + * <code>setUp</code> before each individual test. > + */ > + protected static Callable<ContentProvider> sBrowserProviderCallable = new Callable<ContentProvider>() { nit: Might just be splinter but indentation of javadoc. Tabs? @@ +213,5 @@ > } > > @Override > public void setUp() throws Exception { > + throw new Exception("You should call setUp(authority, databaseName) instead"); nit: UnsupportedOperationException ::: mobile/android/base/tests/testBrowserProviderPerf.java @@ +9,5 @@ > > import org.mozilla.gecko.GeckoProfile; > import org.mozilla.gecko.db.BrowserContract; > import org.mozilla.gecko.db.BrowserDB; > +import org.mozilla.gecko.db.BrowserProvider; nit: I don't think this import is needed. ::: mobile/android/base/tests/testDistribution.java @@ +1,5 @@ > package org.mozilla.gecko.tests; > > import org.mozilla.gecko.*; > import org.mozilla.gecko.db.BrowserContract; > +import org.mozilla.gecko.db.BrowserProvider; nit: I don't think this import is needed.
Attachment #8372920 - Flags: review?(michael.l.comella) → review+
Comment on attachment 8368310 [details] [diff] [review] 938821.patch Isura, I apologize for setting this up as a mentor bug. I didn't realize it was so arduous! :( If you want to continue working on the test framework, bug 943706 is available and, more challengingly, bug 970624.
Attachment #8368310 - Attachment is obsolete: true
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: