Skip to content

Commit

Permalink
added unittests to WorkoutApplicationServiceTest
Browse files Browse the repository at this point in the history
  • Loading branch information
avalax committed Aug 29, 2014
1 parent a3a9650 commit 3601d2a
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public WorkoutApplicationService(WorkoutSession workoutSession) {
this.workoutSession = workoutSession;
}

public int countOfCurrentExercises() throws RessourceNotFoundException {
public int countOfExercises() throws RessourceNotFoundException {
return getWorkout().countOfExercises();
}

Expand Down Expand Up @@ -60,7 +60,7 @@ public double weightOfCurrentSet(int index) throws RessourceNotFoundException{
return exercise.setAtPosition(indexOfCurrentSet).getWeight();
}

public int indexOfCurrentExercise() throws WorkoutNotFoundException {
public int indexOfCurrentExercise() throws RessourceNotFoundException {
return getWorkout().indexOfCurrentExercise();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ public void setCurrentExercise(int index) {
}

@Override
public int indexOfCurrentExercise() {
public int indexOfCurrentExercise() throws ExerciseNotFoundException {
if (exercises.isEmpty()) {
throw new ExerciseNotFoundException();
}
return exerciseIndex;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface Workout extends Serializable {

void setCurrentExercise(int index);

int indexOfCurrentExercise();
int indexOfCurrentExercise() throws ExerciseNotFoundException;

int countOfExercises();
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
inflater.inflate(R.menu.activity_main_actions, menu);
this.menuItem = menu.findItem(R.id.action_change_weight);
try {
viewPager.setAdapter(new ExercisePagerAdapter(getSupportFragmentManager(), workoutApplicationService.countOfCurrentExercises()));
viewPager.setAdapter(new ExercisePagerAdapter(getSupportFragmentManager(), workoutApplicationService.countOfExercises()));
viewPager.setCurrentItem(workoutApplicationService.indexOfCurrentExercise());
updatePage(workoutApplicationService.indexOfCurrentExercise());
} catch (RessourceNotFoundException e) {
Expand Down Expand Up @@ -100,7 +100,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (requestCode == MANAGE_WORKOUT && resultCode == Activity.RESULT_OK) {
try {
viewPager.setAdapter(new ExercisePagerAdapter(getSupportFragmentManager(), workoutApplicationService.countOfCurrentExercises()));
viewPager.setAdapter(new ExercisePagerAdapter(getSupportFragmentManager(), workoutApplicationService.countOfExercises()));
updatePage(0);
} catch (RessourceNotFoundException e) {
Log.d("workout not found", e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ public void setUp() throws Exception {
public void currentWorkoutId_shouldThrowRessourceNotFoundExeption() throws Exception {
workoutApplicationService.currentWorkoutId();
}

@Test(expected = RessourceNotFoundException.class)
public void indexOfCurrentExercise_shouldThrowRessourceNotFoundExeption() throws Exception {
workoutApplicationService.indexOfCurrentExercise();
}

@Test(expected = RessourceNotFoundException.class)
public void countOfExercises_shouldThrowRessourceNotFoundExeption() throws Exception {
workoutApplicationService.countOfExercises();
}
}

public class aWorkoutGiven {
Expand All @@ -58,5 +68,26 @@ public void currentWorkoutId_shouldReturnWorkoutId() throws Exception {

assertThat(currentWorkoutId, equalTo(workoutId));
}

@Test(expected = RessourceNotFoundException.class)
public void indexOfCurrentExerciseWithNoExercises_shouldReturnCurrentIndex() throws Exception {
workoutApplicationService.indexOfCurrentExercise();
}

@Test
public void indexOfCurrentExercise_shouldReturnIndexOf0() throws Exception {
workout.createExercise();
int indexOfCurrentExercise = workoutApplicationService.indexOfCurrentExercise();

assertThat(indexOfCurrentExercise,equalTo(0));
}

public void countOfExercises_shouldReturnCountOfExercies() throws Exception {
workout.createExercise();

int countOfExercises = workoutApplicationService.countOfExercises();

assertThat(countOfExercises,equalTo(1));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import de.avalax.fitbuddy.domain.model.exercise.BasicExercise;
import de.avalax.fitbuddy.domain.model.exercise.Exercise;
import de.avalax.fitbuddy.domain.model.exercise.ExerciseId;
import de.avalax.fitbuddy.domain.model.exercise.ExerciseNotFoundException;
import de.avalax.fitbuddy.domain.model.set.Set;
import de.bechte.junit.runners.context.HierarchicalContextRunner;
import org.junit.Before;
Expand Down Expand Up @@ -94,9 +95,15 @@ public void setNameWithSpace_shouldSetTrimedName() throws Exception {
assertThat(workout.getName(), equalTo("newName"));
}

@Test(expected = ExerciseNotFoundException.class)
public void indexOfCurrentExercise_shouldThrowExerciseNotFoundException() throws Exception {
workout.indexOfCurrentExercise();
}

@Test
public void set_shouldSet() throws Exception {
int index = 42;
public void setCurrentExercise_shouldReturnIndexOfCurrentExercise() throws Exception {
workout.createExercise();
int index = 0;

workout.setCurrentExercise(index);

Expand Down

0 comments on commit 3601d2a

Please sign in to comment.