Browse files

Test is now functioning though what I want to be injected is not. Geo…

…CamMemo is being injected w/ DjangoMemoImplementation and not FakeDjangoMemoImplementation. Unsure as to what's causing this. Need to more closely examine documentation and examples at http://pivotal.github.com/robolectric/roboguice.html.

The issue Anooj and I were having last night seems to be caused by our lack of understanding on how Robolectric is creating "shadow" objects. Shadow objects in Robolectric are standins for typical Android objects. Not sure if this is why we needed to be more explicit in our listView.setAdapter or if what we had would have died on a normal run as well.

I also upgrade to the Robolectric RC1 jar. This could have also fixed the issue as I did the upgrade as I integrated the new code to create items for the ListView.
  • Loading branch information...
1 parent c7b7c4c commit cb1ffb6d04addd1b7b7c2c0f392b6fd546c8e375 @ahsteele ahsteele committed Mar 18, 2011
View
BIN Test/libs/robolectric-1.0-RC1-jar-with-dependencies.jar
Binary file not shown.
View
91 Test/tests/gov/nasa/arc/geocam/memo/test/ActivityTest.java
@@ -1,51 +1,42 @@
-package gov.nasa.arc.geocam.memo.test;
-
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.junit.Assert.assertThat;
-
-import java.util.List;
-
-import gov.nasa.arc.geocam.memo.R;
-import gov.nasa.arc.geocam.memo.activity.GeoCamMemo;
-import gov.nasa.arc.geocam.memo.service.DjangoMemoImplementation;
-import gov.nasa.arc.geocam.memo.service.DjangoMemoInterface;
-import gov.nasa.arc.geocam.memo.test.injected.FakeDjangoMemoImplementation;
-import gov.nasa.arc.geocam.memo.test.injected.InjectedTestRunner;
-import roboguice.activity.RoboActivity;
-import roboguice.config.AbstractAndroidModule;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import android.widget.ListView;
-
-import com.google.inject.Inject;
-import com.xtremelabs.robolectric.RobolectricTestRunner;
-
-@RunWith(InjectedTestRunner.class)
-public class ActivityTest{
- @Inject GeoCamMemo activity;
- @Inject FakeDjangoMemoImplementation fakeDjangoMemo;
-
- @Test
- public void shouldHaveHappySmiles() throws Exception {
- String hello = new GeoCamMemo().getResources().getString(R.string.hello);
- assertThat(hello, equalTo("Hello World, GeoCamMemo!"));
- }
-
- @Test
- public void shouldDisplayMemos() throws Exception {
- //arrange
- activity.onCreate(null);
- //FakeDjangoMemoImplementation fakeDjangoMemo = new FakeDjangoMemoImplementation();
- List<String>fakeMemoList = fakeDjangoMemo.getMemos();
- activity.setContentView(R.layout.main);
-
- //act
- ListView geoCamListView = (ListView)new GeoCamMemo().findViewById(R.id.MemoListView);
-
- //assert
- assertThat(geoCamListView.getChildCount(), equalTo(fakeMemoList.size()));
- }
+package gov.nasa.arc.geocam.memo.test;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+import gov.nasa.arc.geocam.memo.R;
+import gov.nasa.arc.geocam.memo.activity.GeoCamMemo;
+import gov.nasa.arc.geocam.memo.test.injected.FakeDjangoMemoImplementation;
+import gov.nasa.arc.geocam.memo.test.injected.InjectedTestRunner;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import android.widget.ListView;
+
+import com.google.inject.Inject;
+
+@RunWith(InjectedTestRunner.class)
+public class ActivityTest{
+ @Inject GeoCamMemo activity;
+ @Inject FakeDjangoMemoImplementation fakeDjangoMemo;
+
+ @Test
+ public void shouldHaveHappySmiles() throws Exception {
+ String hello = new GeoCamMemo().getResources().getString(R.string.hello);
+ assertThat(hello, equalTo("Hello World, GeoCamMemo!"));
+ }
+
+ @Test
+ public void shouldDisplayMemos() throws Exception {
+ //arrange
+ activity.onCreate(null);
+ List<String>fakeMemoList = fakeDjangoMemo.getMemos();
+
+ //act
+ ListView geoCamListView = (ListView)activity.findViewById(R.id.MemoListView);
+
+ //assert
+ assertThat(geoCamListView.getChildCount(), equalTo(fakeMemoList.size()));
+ }
}
View
2 android/default.properties
@@ -8,4 +8,4 @@
# project structure.
# Project target.
-target=android-8
+target=android-8
View
13 android/res/layout/list_item.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+<TextView
+ android:id="@android:id/text1"
+ android:layout_width="wrap_content"
+ android:gravity="center_vertical"
+ android:layout_height="wrap_content"
+ android:textSize="16dip"
+ />
+</LinearLayout>
View
1 android/res/layout/main.xml
@@ -8,6 +8,7 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
+ android:id="@+id/TestField"
/>
<ListView
android:id="@+id/MemoListView"
View
45 android/src/gov/nasa/arc/geocam/memo/activity/GeoCamMemo.java
@@ -1,31 +1,56 @@
package gov.nasa.arc.geocam.memo.activity;
-import java.util.List;
-
-import com.google.inject.Inject;
-
import gov.nasa.arc.geocam.memo.R;
-import gov.nasa.arc.geocam.memo.R.layout;
import gov.nasa.arc.geocam.memo.service.DjangoMemoInterface;
+
+import java.util.List;
+
import roboguice.activity.RoboActivity;
-import android.app.Activity;
+import android.content.Context;
import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
import android.widget.ArrayAdapter;
-import android.widget.ListAdapter;
import android.widget.ListView;
+import android.widget.TextView;
+
+import com.google.inject.Inject;
public class GeoCamMemo extends RoboActivity {
@Inject DjangoMemoInterface djangoMemo;
+ private LayoutInflater mInflater;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
+ super.onCreate(savedInstanceState);
setContentView(R.layout.main);
List<String>memoList = djangoMemo.getMemos();
- ListView memoListView = (ListView)findViewById(R.id.MemoListView);
- memoListView.setAdapter(new ArrayAdapter(this, R.id.MemoListView, memoList.toArray()));
+ ListView memoListView = (ListView)findViewById(R.id.MemoListView);
+
+ mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+
+ memoListView.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, memoList) {
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ View row;
+
+ if (null == convertView) {
+ row = mInflater.inflate(R.layout.list_item, null);
+ } else {
+ row = convertView;
+ }
+
+ TextView tv = (TextView) row.findViewById(android.R.id.text1);
+ tv.setText(getItem(position));
+
+ return row;
+ }
+ });
+
+ String x = "";
}
}
View
BIN tmp/cached-robolectric-classes.jar
Binary file not shown.

0 comments on commit cb1ffb6

Please sign in to comment.