-
-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clear Database Test Rule #29
Conversation
🔴 One Issue found: It doesn't work if the database hasn't been created prior to the test (which will be the usual case). We must only try to delete databases if they exist. 🙌
|
150497f
to
dab7a5d
Compare
Great work! Let's see how it progress! By the way @Sloy , what do you think about having one Rule for every kind of thing to be remoded, and another one that just joins all of them? I think that having different rules will make them simpler. So, if we want to ease using all of them at the same tame (that will be the most common way to work with Barista), we can just create a Rule to join them. And... well, we can talk about it later, let's focus on this particular Rule :·D |
That was my original idea. But I wasn't too sure. I thought about having just one for everything for simplicity, but if you think having both can be useful, let's go with it. I don't have a strong opinion on neither. |
@Sloy yes... the Rule that clears the Database needs 80 lines. The SharedPrefs one, 80 lines more I guess. Let's have them smaller as possible, and create a new Rule to join these Rules. By the way, at some point of the future, we will need to remove all .jpg and .png pictures of the filesystem (or whatever other extension) so... let's keep that complex rules isolated. |
One rule to rule them all!! 💍 |
😂 |
🍏 The issue I commented about clearing databases that don't exist is now fixed. |
*/ | ||
public class ClearDatabaseRule implements TestRule { | ||
|
||
private static final String[] UNINTERESTING_FILENAME_SUFFIXES = new String[] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Niiice!
writableDatabase.close(); | ||
} | ||
|
||
private static class OpenHelper extends SQLiteOpenHelper { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could call it OpenDatabaseHelper
. When I seen the dependencies of this Activity, I went crazy: What's this class?
Several horses and monkey died during my madness.
private static class OpenHelper extends SQLiteOpenHelper { | ||
|
||
public OpenHelper(Context context) { | ||
super(context, "mydatabase", null, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What means that 1
?
return tidiedList; | ||
} | ||
|
||
private static String removeSuffix(String str, String[] suffixesToRemove) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about calling this method filterUninterestingSuffixes
? And I suggest to avoid passing the list of suffixest to remove. It seems that they will be always the same: UNINTERESTING_FILENAME_SUFFIXES
.
|
||
private void clearData() { | ||
for (File dbFile : tidyDatabaseList(getDatabaseFiles())) { | ||
SQLiteDatabase database = performOpen(dbFile, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What means this 0
?
* @param databaseFiles Raw list of database files. | ||
* @return Tidied list with shadow databases removed. | ||
*/ | ||
private static List<File> tidyDatabaseList(List<File> databaseFiles) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method name sounds strange... Don't know. I don't have a suggestion, by the way :·)
There are some comments but... great work! |
64bf82f
to
967888a
Compare
Rebased an squashed, much of the code on the rule has been changed @rocboronat. |
Nice, @Sloy ! Check my comments and go on applying the suggestion or merging :·) |
Creates Activity and test to check if database is cleared
967888a
to
c2c2895
Compare
Travis likes it. I tried a local build with InfoJobs project and everything works as expected. |
Ave, @Sloy , morituri te salutant! Great work there :·) It's merge time! Feel free to release a version if you need it! :·) |
This Rule works similarly to #24, but for SQLite databases.
It fetches all databases in the app, obtains all tables from them, and performs a "delete from" without where.
I decided to do this instead of a DROP because I think it might break the app, not sure though.
This should be tested against different scenarios and sdk versions. I've seen in Stetho that they have different ways of opening databases depending on the sdk version. Wonder why.
TODO: