Skip to content

Commit

Permalink
Allow any type of data to be passsed.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanenicolas committed Sep 16, 2014
1 parent 8364620 commit 5628687
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions injectextra-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ dependencies {
compile 'com.github.stephanenicolas.afterburner:afterburner-library:1.0.2'

//only needed to create a plugin
compile ("com.github.stephanenicolas.morpheus:morpheus-plugin:1.0.7")
compile ("com.github.stephanenicolas.morpheus:morpheus-commons:1.0.7")
compile ("com.github.stephanenicolas.morpheus:morpheus-plugin:1.0.8-SNAPSHOT")
compile ("com.github.stephanenicolas.morpheus:morpheus-commons:1.0.8-SNAPSHOT")
compile gradleApi()
compile localGroovy()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ private String createInjectExtraStatements(List<CtField> extrasToInject, CtClass
} else if (isSubClass(classPool, field.getType(), CharSequence.class)) {
findExtraString = "getIntent().getCharSequenceExtra(\"" + value + "\")";
} else {
throw new NotFoundException(
format("InjectExtra doesn't know how to inject field %s of type %s in %s",
field.getName(), field.getType().getName(), targetClazz.getName()));
findExtraString = "(" +field.getType().getName()+ ")" + "getIntent().getExtras().get(\"" + value + "\")";
}
buffer.append(checkOptional(assignment, value, optional, findExtraString, fieldName));
buffer.append("\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class InjectExtraProcessorInActivityTest {
public static final String EXTRA_ID_CHAR_SEQUENCE_ARRAY_LIST = "EXTRA_ID_CHAR_SEQUENCE_ARRAY_LIST";
public static final String EXTRA_ID_STRING_ARRAY_LIST = "EXTRA_ID_STRING_ARRAY_LIST";
public static final String EXTRA_ID_PARCELABLE_ARRAY_LIST = "EXTRA_ID_PARCELABLE_ARRAY_LIST";
public static final String EXTRA_ID_OBJECT = "EXTRA_ID_OBJECT";

@Test
public void shouldInjectExtra_simple() {
Expand Down Expand Up @@ -79,6 +80,7 @@ public void shouldInjectExtra_simple() {
ArrayList<Parcelable> pointArrayList = new ArrayList<Parcelable>();
pointArrayList.add(new Point());
intent.putExtra(EXTRA_ID_PARCELABLE_ARRAY_LIST, pointArrayList);
intent.putExtra(EXTRA_ID_OBJECT, new Intent());

System.out.println("Extras used for tests " + intent.getExtras().toString());
TestActivity activity =
Expand Down Expand Up @@ -120,6 +122,9 @@ public void shouldInjectExtra_simple() {
assertThat(activity.listStrings, is(intent.getStringArrayListExtra(EXTRA_ID_STRING_ARRAY_LIST)));
assertThat(activity.listParcelables, is(intent.getParcelableArrayListExtra(
EXTRA_ID_PARCELABLE_ARRAY_LIST)));
assertThat(activity.listParcelables, is(intent.getParcelableArrayListExtra(
EXTRA_ID_PARCELABLE_ARRAY_LIST)));
assertThat(activity.intent, is(intent.getExtras().get(EXTRA_ID_OBJECT)));
}

@Test(expected = RuntimeException.class)
Expand Down Expand Up @@ -220,6 +225,8 @@ public static class TestActivity extends Activity {
protected ArrayList<String> listStrings;
@InjectExtra(EXTRA_ID_PARCELABLE_ARRAY_LIST)
protected ArrayList<Parcelable> listParcelables;
@InjectExtra(EXTRA_ID_OBJECT)
protected Intent intent;
}

public static class TestActivityOptional extends Activity {
Expand Down

0 comments on commit 5628687

Please sign in to comment.