mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-11-04 23:28:19 -05:00
Add a "testing mode" inject
Doesn't do anything currently, but will allow for Activities/etc. which can't be easily sub-classed, mocked, etc. during runs to modify behavior.
This commit is contained in:
parent
a15e78978b
commit
9548bb50ef
@ -2,8 +2,7 @@ package org.bspeice.minimalbible;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import org.bspeice.minimalbible.activity.downloader.DownloadActivity;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Module;
|
||||
@ -24,4 +23,17 @@ public class MinimalBibleModules {
|
||||
Application provideApplication() {
|
||||
return app;
|
||||
}
|
||||
|
||||
/**
|
||||
* This field allows us to set application-wide whether we are in a test or not
|
||||
* Allows components on down the line to know whether they should set some things up or not.
|
||||
* Additionally, not a Singleton so we can enable/disable testing mode as needed. However,
|
||||
* for production, it's always false.
|
||||
* @return Whether we are in a test - false
|
||||
*/
|
||||
@Provides
|
||||
@Named("Testing")
|
||||
boolean isTest() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -2,14 +2,25 @@ package org.bspeice.minimalbible;
|
||||
|
||||
/**
|
||||
* List modules to be used during testing
|
||||
* Also the entry point for setting whether or not we are using testing mode
|
||||
*/
|
||||
public class Modules {
|
||||
private static TestModules testModules = new TestModules();
|
||||
|
||||
private Modules() {}
|
||||
|
||||
public static void enableTestingMode() {
|
||||
testModules.setTestMode(true);
|
||||
}
|
||||
|
||||
public static void disableTestingMode() {
|
||||
testModules.setTestMode(false);
|
||||
}
|
||||
|
||||
public static Object[] list(MinimalBible app) {
|
||||
return new Object[] {
|
||||
new MinimalBibleModules(app),
|
||||
new TestModules()
|
||||
testModules
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ package org.bspeice.minimalbible;
|
||||
|
||||
import org.bspeice.minimalbible.activity.downloader.DownloadActivity;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
@ -17,4 +19,27 @@ public class TestModules {
|
||||
@Provides CharSequence provideString() {
|
||||
return testActivityTitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide an application-wide hub to enable/disable a "testing" mode
|
||||
* Each application is free to interpret what this means, but allows for programming
|
||||
* different behavior to respond to different testing needs in code that can't be mocked
|
||||
* *cough cough* `Activities`.
|
||||
* @return
|
||||
*/
|
||||
@Provides
|
||||
@Named("Testing")
|
||||
boolean isTest() {
|
||||
return isTest;
|
||||
}
|
||||
|
||||
private boolean isTest;
|
||||
|
||||
public void setTestMode(boolean isTest) {
|
||||
this.isTest = isTest;
|
||||
}
|
||||
|
||||
public boolean getTestMode() {
|
||||
return isTest;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user