From 6966db13e75c67dd62d0b04161727d6a8032727a Mon Sep 17 00:00:00 2001 From: thomcz Date: Mon, 6 Feb 2017 21:56:25 +0100 Subject: [PATCH] #107 Covered some branches in tests --- .../band/app/view/HRVMeasurementActivity.java | 2 +- .../hrv/band/app/view/HRVValueActivity.java | 2 -- .../activity/HRVMeasurementActivityTest.java | 4 +++- .../java/activity/HRVValueActivityTest.java | 2 +- .../MeasuredDetailsEditFragmentTest.java | 17 +++++++++++++++++ .../fragment/MeasuredDetailsFragmentTest.java | 5 +++++ .../fragment/MeasuredValueFragmentTest.java | 10 ++++++++++ 7 files changed, 37 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/hrv/band/app/view/HRVMeasurementActivity.java b/app/src/main/java/hrv/band/app/view/HRVMeasurementActivity.java index 494645d..a10bab9 100644 --- a/app/src/main/java/hrv/band/app/view/HRVMeasurementActivity.java +++ b/app/src/main/java/hrv/band/app/view/HRVMeasurementActivity.java @@ -68,7 +68,7 @@ public boolean onOptionsItemSelected(MenuItem item) { /** * Saves the actual measured and calculated HRV parameter. */ - public void saveMeasurement() { + private void saveMeasurement() { IStorage storage = new HRVSQLController(); setMeasurementDetails(); storage.saveData(getApplicationContext(), getParameter()); diff --git a/app/src/main/java/hrv/band/app/view/HRVValueActivity.java b/app/src/main/java/hrv/band/app/view/HRVValueActivity.java index 6f1e184..25d3730 100644 --- a/app/src/main/java/hrv/band/app/view/HRVValueActivity.java +++ b/app/src/main/java/hrv/band/app/view/HRVValueActivity.java @@ -79,8 +79,6 @@ private void deleteParameter() { @Override public void onBackPressed() { - //TODO: Implement Cancel Dialog here which asks if the user really don't want to save - // the measurement finish(); } diff --git a/app/src/test/java/activity/HRVMeasurementActivityTest.java b/app/src/test/java/activity/HRVMeasurementActivityTest.java index f2e4fb8..f6b8f70 100644 --- a/app/src/test/java/activity/HRVMeasurementActivityTest.java +++ b/app/src/test/java/activity/HRVMeasurementActivityTest.java @@ -1,5 +1,6 @@ package activity; +import android.app.Dialog; import android.content.Intent; import android.os.Build; import android.support.v7.view.menu.ActionMenuItemView; @@ -14,6 +15,7 @@ import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import org.robolectric.shadows.ShadowApplication; +import org.robolectric.shadows.ShadowDialog; import java.util.Date; @@ -66,7 +68,7 @@ public void testOnBackPressed() throws Exception { } @Test - public void checkSavedParameter() { + public void onOptionsItemSelectedSave() { ActionMenuItemView item = (ActionMenuItemView) activity.findViewById(R.id.menu_ic_save); activity.onOptionsItemSelected(item.getItemData()); diff --git a/app/src/test/java/activity/HRVValueActivityTest.java b/app/src/test/java/activity/HRVValueActivityTest.java index 9fb3b63..1c8e848 100644 --- a/app/src/test/java/activity/HRVValueActivityTest.java +++ b/app/src/test/java/activity/HRVValueActivityTest.java @@ -69,7 +69,7 @@ public void testOnBackPressed() throws Exception { @Ignore @Test - public void checkDeletedParameter() { + public void onOptionsItemSelectedDelete() { ActionMenuItemView item = (ActionMenuItemView) activity.findViewById(R.id.menu_ic_delete); activity.onOptionsItemSelected(item.getItemData()); diff --git a/app/src/test/java/fragment/MeasuredDetailsEditFragmentTest.java b/app/src/test/java/fragment/MeasuredDetailsEditFragmentTest.java index 7332e75..c4a91a2 100644 --- a/app/src/test/java/fragment/MeasuredDetailsEditFragmentTest.java +++ b/app/src/test/java/fragment/MeasuredDetailsEditFragmentTest.java @@ -1,6 +1,7 @@ package fragment; import android.os.Build; +import android.view.View; import android.widget.RatingBar; import android.widget.Spinner; import android.widget.TextView; @@ -19,6 +20,7 @@ import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNotNull; +import static junit.framework.Assert.assertSame; /** * Copyright (c) 2017 @@ -74,4 +76,19 @@ public void checkNote() throws Exception { assertEquals(msg, fragment.getNote()); } + + @Test + public void checkIfViewIsRecycled() throws Exception { + Spinner spinner = (Spinner) fragment.getActivity().findViewById(R.id.measure_categories); + + for (int index = 0; index < spinner.getCount(); index++) { + View view = getViewAtIndex(index, null, spinner); + View viewRecycled = getViewAtIndex(index, view, spinner); + assertSame(view, viewRecycled); + } + } + + private View getViewAtIndex(int index, View parent, Spinner spinner) { + return spinner.getAdapter().getView(index, parent, null); + } } diff --git a/app/src/test/java/fragment/MeasuredDetailsFragmentTest.java b/app/src/test/java/fragment/MeasuredDetailsFragmentTest.java index 01dbf85..c96fb6e 100644 --- a/app/src/test/java/fragment/MeasuredDetailsFragmentTest.java +++ b/app/src/test/java/fragment/MeasuredDetailsFragmentTest.java @@ -1,6 +1,9 @@ package fragment; import android.os.Build; +import android.view.View; +import android.widget.ListView; +import android.widget.Spinner; import org.junit.Before; import org.junit.BeforeClass; @@ -13,10 +16,12 @@ import java.util.Date; import hrv.band.app.BuildConfig; +import hrv.band.app.R; import hrv.band.app.control.HRVParameters; import hrv.band.app.view.fragment.MeasuredDetailsFragment; import static junit.framework.Assert.assertNotNull; +import static junit.framework.Assert.assertSame; /** * Copyright (c) 2017 diff --git a/app/src/test/java/fragment/MeasuredValueFragmentTest.java b/app/src/test/java/fragment/MeasuredValueFragmentTest.java index 4ffd363..a88f9f8 100644 --- a/app/src/test/java/fragment/MeasuredValueFragmentTest.java +++ b/app/src/test/java/fragment/MeasuredValueFragmentTest.java @@ -23,6 +23,7 @@ import hrv.band.app.view.WebActivity; import hrv.band.app.view.fragment.MeasuredValueFragment; +import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNotNull; import static junit.framework.Assert.assertSame; import static junit.framework.Assert.assertTrue; @@ -70,6 +71,15 @@ public void checkItemClicked() throws Exception { checkExpectedIntent(expectedIntent); } } + + @Test + public void checkItems() throws Exception { + ListView listView = (ListView) fragment.getActivity().findViewById(R.id.hrv_value_list); + for (int i = 0; i < listView.getCount(); i ++) { + assertEquals(parameter, listView.getItemAtPosition(i)); + } + } + private void checkExpectedIntent(Intent expectedIntent) { ShadowActivity shadowActivity = Shadows.shadowOf(fragment.getActivity()); Intent actualIntent = shadowActivity.getNextStartedActivity();