Skip to content

Commit

Permalink
#107 Covered some branches in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thomcz committed Feb 6, 2017
1 parent ef664ac commit 6966db1
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/hrv/band/app/view/HRVValueActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
4 changes: 3 additions & 1 deletion app/src/test/java/activity/HRVMeasurementActivityTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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());

Expand Down
2 changes: 1 addition & 1 deletion app/src/test/java/activity/HRVValueActivityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
17 changes: 17 additions & 0 deletions app/src/test/java/fragment/MeasuredDetailsEditFragmentTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
}
5 changes: 5 additions & 0 deletions app/src/test/java/fragment/MeasuredDetailsFragmentTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions app/src/test/java/fragment/MeasuredValueFragmentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 6966db1

Please sign in to comment.