Permalink
Browse files

Added start of mocking for EditActivity. Doesn't work yet.

  • Loading branch information...
1 parent 64a34cd commit 40d0bf1924b485e2f81d780f9c6b042b6091accf @hdweiss hdweiss committed Sep 4, 2012
@@ -0,0 +1,49 @@
+package com.matburt.mobileorg.Gui.Capture;
+
+import android.R;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentActivity;
+import android.support.v4.app.FragmentManager;
+import android.support.v4.app.FragmentTransaction;
+
+import com.actionbarsherlock.app.SherlockFragmentActivity;
+import com.matburt.mobileorg.Gui.Capture.EditDetailsFragment;
+import com.matburt.mobileorg.provider.OrgNode;
+
+public class EditActivityMock extends SherlockFragmentActivity {
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ this.setContentView(com.matburt.mobileorg.R.layout.edit);
+ EditDetailsFragment detailsFragment = new EditDetailsFragment();
+ OrgNode node = new OrgNode();
+ node.name = "initial";
+ detailsFragment.init(node, "", getContentResolver());
+ addFragment(detailsFragment);
+ }
+
+ public void addFragment(EditDetailsFragment detailsFragment) {
+ FragmentManager fragmentManager = getSupportFragmentManager();
+ FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
+ fragmentTransaction.add(com.matburt.mobileorg.R.id.editnode_fragment_container, detailsFragment, "details");
+ fragmentTransaction.commit();
+ }
+
+ public void replaceFragment(OrgNode node) {
+ FragmentManager fragmentManager = getSupportFragmentManager();
+ Fragment fragment = fragmentManager.findFragmentByTag("details");
+ FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
+ fragmentTransaction.remove(fragment).commit();
+
+ fragmentTransaction = fragmentManager.beginTransaction();
+ EditDetailsFragment detailsFragment = new EditDetailsFragment();
+ detailsFragment.init(node, "", getContentResolver());
+ fragmentTransaction.add(com.matburt.mobileorg.R.id.editnode_fragment_container, detailsFragment, "details2");
+ fragmentTransaction.commit();
+
+ fragmentManager.executePendingTransactions();
+ }
+}
@@ -4,7 +4,7 @@
android:versionCode="1"
android:versionName="1.0" >
- <uses-sdk android:minSdkVersion="3" />
+ <uses-sdk android:minSdkVersion="8" />
<instrumentation
android:name="android.test.InstrumentationTestRunner"
@@ -0,0 +1,121 @@
+package com.matburt.mobileorg.test.Gui;
+
+
+import android.R;
+import android.content.ContentResolver;
+import android.content.Intent;
+import android.support.v4.app.Fragment;
+import android.test.ActivityInstrumentationTestCase;
+import android.test.ActivityInstrumentationTestCase2;
+import android.test.ActivityUnitTestCase;
+import android.test.UiThreadTest;
+import android.test.mock.MockContentResolver;
+import android.widget.EditText;
+
+import com.matburt.mobileorg.Gui.Capture.EditActivity;
+import com.matburt.mobileorg.Gui.Capture.EditDetailsFragment;
+import com.matburt.mobileorg.provider.OrgNode;
+import com.matburt.mobileorg.test.util.OrgTestUtils;
+
+public class EditActivityTest extends ActivityInstrumentationTestCase2<EditActivity> {
+
+ private EditActivity activity;
+ private ContentResolver resolver;
+
+ public EditActivityTest() {
+ super(EditActivity.class);
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+
+ //setActivityInitialTouchMode(false);
+ Intent intent = new Intent();
+// intent.putExtra(EditActivity.ACTIONMODE, EditActivity.ACTIONMODE_EDIT);
+// intent.putExtra(EditActivity.NODE_ID, 100);
+ //setActivityIntent(intent);
+ this.activity = getActivity();
+
+ this.resolver = new MockContentResolver();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testMock() {
+ assertNotNull(this.activity);
+
+ final OrgNode node = OrgTestUtils.getDefaultOrgNode();
+ activity.setOrgNode(node, "");
+
+// activity.runOnUiThread(new Runnable (){
+// @Override
+// public void run() {
+// activity.setOrgNode(node, "");
+// }
+// });
+
+ OrgNode editedNode = activity.getOrgNode();
+
+ assertEquals(node.name, editedNode.name);
+ }
+
+
+// public void testFragmentSimple() {
+// OrgNode node = OrgTestUtils.getDefaultOrgNode();
+//
+// EditDetailsFragment details = new EditDetailsFragment();
+// //details.onCreateView(activity.getLayoutInflater(), activity.onCreateView(getName(), context, null), null);
+// details.init(node, "", null);
+// details.updateDisplay();
+//
+// OrgNode editedNode = details.getEditedOrgNode();
+// assertEquals(node.name, editedNode.name);
+// }
+
+// public void testFragment() {
+// Fragment fragment = activity.getSupportFragmentManager().findFragmentByTag(EditActivity.FRAGMENT_DETAILS_TAG);
+// assertNotNull(fragment);
+// final EditDetailsFragment detailsFragment = (EditDetailsFragment) fragment;
+// //detailsFragment.init(node, EditActivity.ACTIONMODE_EDIT, "TODO", activity.getContentResolver());
+//
+// activity.runOnUiThread(new Runnable() {
+// public void run() {
+// detailsFragment.updateDisplay();
+// }
+// });
+//
+// OrgNode node = OrgTestUtils.getDefaultOrgNode();
+// this.activity.setupOrgNode(node, "");
+//
+//
+// OrgNode editedNode = detailsFragment.getEditedOrgNode();
+// assertEquals(node.name, editedNode.name);
+// }
+//
+// public void testTest() {
+// EditText titleView = (EditText) activity.findViewById(com.matburt.mobileorg.R.id.title);
+// assertNotNull(titleView);
+// assertTrue(titleView.getText().equals(""));
+// }
+//
+//
+// @UiThreadTest
+// public void testTest3() {
+// EditText titleView = (EditText) activity.findViewById(R.id.title);
+// assertNotNull(titleView);
+// assertTrue(titleView.getText().equals(""));
+// }
+//
+// public void testTest2() {
+// Fragment detailsFragment = activity.getSupportFragmentManager().findFragmentByTag(EditActivity.FRAGMENT_DETAILS_TAG);
+// assertNotNull(detailsFragment);
+// EditText titleView = (EditText) detailsFragment.getView().findViewById(R.id.title);
+// assertNotNull(titleView);
+// assertTrue(titleView.getText().equals(""));
+// }
+
+}
@@ -0,0 +1,71 @@
+package com.matburt.mobileorg.test.Gui;
+
+import android.content.ContentResolver;
+import android.support.v4.app.FragmentManager;
+import android.support.v4.app.FragmentTransaction;
+import android.test.ActivityInstrumentationTestCase2;
+import android.test.ActivityUnitTestCase;
+import android.test.mock.MockContentResolver;
+
+import com.matburt.mobileorg.Gui.Capture.EditActivity;
+import com.matburt.mobileorg.Gui.Capture.EditActivityMock;
+import com.matburt.mobileorg.Gui.Capture.EditDetailsFragment;
+import com.matburt.mobileorg.provider.OrgNode;
+import com.matburt.mobileorg.test.util.OrgTestUtils;
+
+public class EditActivityTestMock extends ActivityInstrumentationTestCase2<EditActivityMock> {
+
+ private EditActivityMock activity;
+ private ContentResolver resolver;
+
+ public EditActivityTestMock() {
+ super(EditActivityMock.class);
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+
+ this.resolver = new MockContentResolver();
+ this.activity = getActivity();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+// public void testTestMock() {
+// assertNotNull(this.activity);
+//
+// //getInstrumentation().callActivityOnCreate(activity, null);
+//
+// final OrgNode node = OrgTestUtils.getDefaultOrgNode();
+// //replaceFragment(node);
+// //activity.setOrgNode(node);
+// //activity.replaceFragment(node);
+// callReplace(node);
+//
+// EditDetailsFragment detailsFragment = (EditDetailsFragment)activity.getSupportFragmentManager().findFragmentByTag("details2");
+// OrgNode editedNode = detailsFragment.getEditedOrgNode();
+// assertEquals(node.name, editedNode.name);
+// }
+
+ public void callReplace(final OrgNode node) {
+ activity.runOnUiThread(new Runnable (){
+ @Override
+ public void run() {
+ getActivity().replaceFragment(node);
+ }
+ });
+ }
+
+ public void replaceFragment(OrgNode node) {
+ EditDetailsFragment fragment = new EditDetailsFragment();
+ fragment.init(node, "", null);
+ FragmentManager fragmentManager = activity.getSupportFragmentManager();
+ FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
+ fragmentTransaction.replace(com.matburt.mobileorg.R.id.editnode_fragment_container, fragment, "details");
+ fragmentTransaction.commit();
+ }
+}

0 comments on commit 40d0bf1

Please sign in to comment.