mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-11-21 15:38:35 -05:00
PoC using reflection
Test will need to be something more meaningful later.
This commit is contained in:
parent
60185c934a
commit
5c71e8f014
@ -1,10 +1,12 @@
|
|||||||
package org.bspeice.minimalbible;
|
package org.bspeice.minimalbible;
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.test.ActivityInstrumentationTestCase2;
|
import android.test.ActivityInstrumentationTestCase2;
|
||||||
import android.test.ActivityUnitTestCase;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import org.bspeice.minimalbible.activity.download.DownloadActivity;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Bradlee Speice on 7/5/2014.
|
* Created by Bradlee Speice on 7/5/2014.
|
||||||
*/
|
*/
|
||||||
@ -12,7 +14,8 @@ import android.util.Log;
|
|||||||
on using an activity that sets up any underlying fragments (includes navigation drawers).
|
on using an activity that sets up any underlying fragments (includes navigation drawers).
|
||||||
The ActivityUnitTestCase doesn't set up enough of the Activity lifecycle.
|
The ActivityUnitTestCase doesn't set up enough of the Activity lifecycle.
|
||||||
*/
|
*/
|
||||||
public class DownloadActivityTest extends ActivityInstrumentationTestCase2<DownloadActivity> {
|
public class DownloadActivityTest extends
|
||||||
|
ActivityInstrumentationTestCase2<DownloadActivity> {
|
||||||
|
|
||||||
public DownloadActivityTest() {
|
public DownloadActivityTest() {
|
||||||
super(DownloadActivity.class);
|
super(DownloadActivity.class);
|
||||||
@ -22,7 +25,17 @@ public class DownloadActivityTest extends ActivityInstrumentationTestCase2<Downl
|
|||||||
DownloadActivity a = getActivity();
|
DownloadActivity a = getActivity();
|
||||||
assertNotNull(a);
|
assertNotNull(a);
|
||||||
|
|
||||||
Log.w("DownloadActivityTest", a.actionTitle);
|
Class c = a.getClass();
|
||||||
assertEquals(a.actionTitle, a.actionTitle, "Test");
|
try {
|
||||||
|
// getField() is public-only
|
||||||
|
Field fTitle = c.getDeclaredField("testInject");
|
||||||
|
fTitle.setAccessible(true);
|
||||||
|
CharSequence title = (CharSequence)fTitle.get(a);
|
||||||
|
assertEquals(TestModules.testActivityTitle, title);
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
fail(e.getMessage());
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
fail(e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
android:theme="@style/AppTheme"
|
android:theme="@style/AppTheme"
|
||||||
android:name=".MinimalBible" >
|
android:name=".MinimalBible" >
|
||||||
<activity
|
<activity
|
||||||
android:name=".DownloadActivity"
|
android:name=".activity.download.DownloadActivity"
|
||||||
android:label="@string/app_name" >
|
android:label="@string/app_name" >
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
@ -2,6 +2,8 @@ package org.bspeice.minimalbible;
|
|||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
|
||||||
|
import org.bspeice.minimalbible.activity.download.DownloadActivity;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
@ -24,7 +26,7 @@ public class MinimalBibleModules {
|
|||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides String provideString() {
|
@Provides CharSequence provideString() {
|
||||||
return "Main";
|
return "Main";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package org.bspeice.minimalbible;
|
package org.bspeice.minimalbible.activity.download;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -14,6 +14,10 @@ import android.view.MenuItem;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import org.bspeice.minimalbible.MinimalBible;
|
||||||
|
import org.bspeice.minimalbible.NavigationDrawerFragment;
|
||||||
|
import org.bspeice.minimalbible.R;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
|
||||||
@ -28,9 +32,10 @@ public class DownloadActivity extends ActionBarActivity
|
|||||||
/**
|
/**
|
||||||
* Used to store the last screen title. For use in {@link #restoreActionBar()}.
|
* Used to store the last screen title. For use in {@link #restoreActionBar()}.
|
||||||
*/
|
*/
|
||||||
private CharSequence mTitle;
|
protected CharSequence mTitle;
|
||||||
|
|
||||||
@Inject String actionTitle;
|
//TODO: This will need to be refactored out later, for now it's a proof of concept.
|
||||||
|
@Inject CharSequence testInject;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -44,7 +49,6 @@ public class DownloadActivity extends ActionBarActivity
|
|||||||
mNavigationDrawerFragment = (NavigationDrawerFragment)
|
mNavigationDrawerFragment = (NavigationDrawerFragment)
|
||||||
getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
|
getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
|
||||||
mTitle = getTitle();
|
mTitle = getTitle();
|
||||||
Log.w("DownloadActivity", "Title: " + mTitle.toString());
|
|
||||||
|
|
||||||
// Set up the drawer.
|
// Set up the drawer.
|
||||||
mNavigationDrawerFragment.setUp(
|
mNavigationDrawerFragment.setUp(
|
@ -1,5 +1,7 @@
|
|||||||
package org.bspeice.minimalbible;
|
package org.bspeice.minimalbible;
|
||||||
|
|
||||||
|
import org.bspeice.minimalbible.activity.download.DownloadActivity;
|
||||||
|
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
import dagger.Provides;
|
import dagger.Provides;
|
||||||
|
|
||||||
@ -10,7 +12,8 @@ import dagger.Provides;
|
|||||||
overrides = true)
|
overrides = true)
|
||||||
public class TestModules {
|
public class TestModules {
|
||||||
|
|
||||||
@Provides String provideString() {
|
public static CharSequence testActivityTitle = "Test";
|
||||||
return "Test";
|
@Provides CharSequence provideString() {
|
||||||
|
return testActivityTitle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,6 +1,6 @@
|
|||||||
#Wed Apr 10 15:27:10 PDT 2013
|
#Sun Jul 06 17:56:45 EDT 2014
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=http\://services.gradle.org/distributions/gradle-1.12-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-1.12-bin.zip
|
||||||
|
Loading…
Reference in New Issue
Block a user