mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-11-04 23:28:19 -05:00
Testing now working
Still requires shenanigans in its own right, but this is a much better platform. Plus, I don't need to mess with the application context, all I do is change the injections.
This commit is contained in:
parent
b34f5e147a
commit
8b5e6ede51
@ -3,13 +3,12 @@ apply plugin: 'com.android.application'
|
||||
android {
|
||||
compileSdkVersion 20
|
||||
buildToolsVersion '20.0.0'
|
||||
|
||||
defaultConfig {
|
||||
applicationId "org.bspeice.minimalbible"
|
||||
applicationId 'org.bspeice.minimalbible'
|
||||
minSdkVersion 8
|
||||
targetSdkVersion 20
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
versionName '1.0'
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
@ -24,10 +23,22 @@ android {
|
||||
exclude 'META-INF/LICENSE'
|
||||
exclude 'META-INF/NOTICE'
|
||||
}
|
||||
productFlavors {
|
||||
testConfig {
|
||||
minSdkVersion 8
|
||||
applicationId 'org.bspeice.minimalbible'
|
||||
targetSdkVersion 20
|
||||
}
|
||||
mainConfig {
|
||||
minSdkVersion 8
|
||||
applicationId 'org.bspeice.minimalbible'
|
||||
targetSdkVersion 20
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile project(path: ':jsword-minimalbible', configuration: 'buildJSword')
|
||||
|
||||
compile 'com.squareup.dagger:dagger:1.2.1'
|
||||
provided 'com.squareup.dagger:dagger-compiler:1.2.1'
|
||||
compile 'com.android.support:appcompat-v7:20.+'
|
||||
}
|
||||
|
@ -1,13 +0,0 @@
|
||||
package org.bspeice.minimalbible;
|
||||
|
||||
import android.app.Application;
|
||||
import android.test.ApplicationTestCase;
|
||||
|
||||
/**
|
||||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
|
||||
*/
|
||||
public class ApplicationTest extends ApplicationTestCase<Application> {
|
||||
public ApplicationTest() {
|
||||
super(Application.class);
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package org.bspeice.minimalbible;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.test.ActivityUnitTestCase;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* Created by Bradlee Speice on 7/5/2014.
|
||||
*/
|
||||
public class DownloadActivityTest extends ActivityUnitTestCase<DownloadActivity> {
|
||||
|
||||
public DownloadActivityTest() {
|
||||
super(DownloadActivity.class);
|
||||
}
|
||||
|
||||
public void testAndroidTestInjection() {
|
||||
MinimalBible m = new MinimalBible();
|
||||
m.buildObjGraph();
|
||||
setApplication(m);
|
||||
|
||||
startActivity(new Intent(getInstrumentation().getTargetContext(),
|
||||
DownloadActivity.class), null, null);
|
||||
|
||||
DownloadActivity a = getActivity();
|
||||
assertNotNull(a);
|
||||
|
||||
Log.w("DownloadActivityTest", a.actionTitle);
|
||||
assertEquals(a.actionTitle, a.actionTitle, "Test");
|
||||
}
|
||||
}
|
@ -6,7 +6,8 @@
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme" >
|
||||
android:theme="@style/AppTheme"
|
||||
android:name=".MinimalBible" >
|
||||
<activity
|
||||
android:name=".DownloadActivity"
|
||||
android:label="@string/app_name" >
|
||||
|
@ -1,22 +1,19 @@
|
||||
package org.bspeice.minimalbible;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.Gravity;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
||||
public class DownloadActivity extends ActionBarActivity
|
||||
@ -32,19 +29,28 @@ public class DownloadActivity extends ActionBarActivity
|
||||
*/
|
||||
private CharSequence mTitle;
|
||||
|
||||
@Inject String actionTitle;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
setTheme(R.style.AppTheme);
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
MinimalBible.get(this).inject(this);
|
||||
|
||||
setContentView(R.layout.activity_download);
|
||||
|
||||
mNavigationDrawerFragment = (NavigationDrawerFragment)
|
||||
getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
|
||||
mTitle = getTitle();
|
||||
Log.w("DownloadActivity", "Title: " + mTitle.toString());
|
||||
|
||||
/*
|
||||
// Set up the drawer.
|
||||
mNavigationDrawerFragment.setUp(
|
||||
R.id.navigation_drawer,
|
||||
(DrawerLayout) findViewById(R.id.drawer_layout));
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
|
31
app/src/main/java/org/bspeice/minimalbible/MinimalBible.java
Normal file
31
app/src/main/java/org/bspeice/minimalbible/MinimalBible.java
Normal file
@ -0,0 +1,31 @@
|
||||
package org.bspeice.minimalbible;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
|
||||
import dagger.ObjectGraph;
|
||||
|
||||
/**
|
||||
* Created by Bradlee Speice on 7/5/2014.
|
||||
*/
|
||||
public class MinimalBible extends Application {
|
||||
private ObjectGraph mObjectGraph;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
buildObjGraph();
|
||||
}
|
||||
|
||||
public void buildObjGraph() {
|
||||
mObjectGraph = ObjectGraph.create(Modules.list(this));
|
||||
}
|
||||
|
||||
public void inject(Object o) {
|
||||
mObjectGraph.inject(o);
|
||||
}
|
||||
|
||||
public static MinimalBible get(Context ctx) {
|
||||
return (MinimalBible)ctx.getApplicationContext();
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package org.bspeice.minimalbible;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
/**
|
||||
* Entry point for the default modules used by MinimalBible
|
||||
*/
|
||||
@Module(injects = DownloadActivity.class,
|
||||
library = true)
|
||||
public class MinimalBibleModules {
|
||||
MinimalBible app;
|
||||
|
||||
public MinimalBibleModules(MinimalBible app) {
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
@Provides @Singleton
|
||||
Application provideApplication() {
|
||||
return app;
|
||||
}
|
||||
|
||||
@Provides String provideString() {
|
||||
return "Main";
|
||||
}
|
||||
}
|
@ -98,7 +98,8 @@ public class NavigationDrawerFragment extends Fragment {
|
||||
}
|
||||
});
|
||||
mDrawerListView.setAdapter(new ArrayAdapter<String>(
|
||||
getActionBar().getThemedContext(),
|
||||
//getActionBar().getThemedContext(),
|
||||
getActivity(),
|
||||
android.R.layout.simple_list_item_1,
|
||||
android.R.id.text1,
|
||||
new String[]{
|
||||
|
@ -0,0 +1,14 @@
|
||||
package org.bspeice.minimalbible;
|
||||
|
||||
/**
|
||||
* List modules used by default MinimalBible configuration
|
||||
*/
|
||||
public class Modules {
|
||||
private Modules() {}
|
||||
|
||||
public static Object[] list(MinimalBible app) {
|
||||
return new Object[] {
|
||||
new MinimalBibleModules(app)
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package org.bspeice.minimalbible;
|
||||
|
||||
/**
|
||||
* List modules to be used during testing
|
||||
*/
|
||||
public class Modules {
|
||||
private Modules() {}
|
||||
|
||||
public static Object[] list(MinimalBible app) {
|
||||
return new Object[] {
|
||||
new MinimalBibleModules(app),
|
||||
new TestModules()
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package org.bspeice.minimalbible;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
/**
|
||||
* Created by Bradlee Speice on 7/5/2014.
|
||||
*/
|
||||
@Module(injects = DownloadActivity.class,
|
||||
overrides = true)
|
||||
public class TestModules {
|
||||
|
||||
@Provides String provideString() {
|
||||
return "Test";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user