Skip to content

Commit

Permalink
changed constructor von BasicExercise
Browse files Browse the repository at this point in the history
  • Loading branch information
avalax committed Jul 16, 2014
1 parent 785cde8 commit dc6cb13
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public BasicExercise() {
this.sets = new ArrayList<>();
}

public BasicExercise(String name, List<Set> sets) {
public BasicExercise(ExerciseId exerciseId, String name, List<Set> sets) {
this.exerciseId = exerciseId;
this.name = name;
this.sets = sets;
this.exerciseIndex = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public interface Exercise extends Serializable {
@Deprecated
void setCurrentSet(int index);

@Deprecated
Set getCurrentSet();

void setExerciseId(ExerciseId exerciseId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public List<Exercise> allExercisesBelongsTo(WorkoutId workoutId) {
do {
ExerciseId exerciseId = new ExerciseId(cursor.getString(0));
List<Set> sets = setRepository.allSetsBelongsTo(exerciseId);
Exercise exercise = new BasicExercise(cursor.getString(1), sets);
exercise.setExerciseId(exerciseId);
Exercise exercise = new BasicExercise(exerciseId, cursor.getString(1), sets);
exercises.add(exercise);
} while (cursor.moveToNext());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@ public Workout createFromJson(String contents) throws WorkoutParseException {
List<ArrayList> jsonExercises = (List<ArrayList>) jsonWorkout.get(1);
List<Exercise> exerciseList = new ArrayList<>();
for (ArrayList jsonExercise : jsonExercises) {
Exercise exercise = new BasicExercise();
exercise.setName((String) jsonExercise.get(0));

List<ArrayList> jsonSets = (List<ArrayList>) jsonExercise.get(1);
List<Set> sets = new ArrayList<>();
for (ArrayList jsonSet : jsonSets) {
double weight = (double) jsonSet.get(1);
int maxReps = (int) ((double) jsonSet.get(0));
Set set = new BasicSet();
set.setWeight(weight);
set.setMaxReps(maxReps);
sets.add(set);
exercise.addSet(set);
}
exerciseList.add(new BasicExercise((String) jsonExercise.get(0), sets));
exerciseList.add(exercise);
}
return new BasicWorkout((String) jsonWorkout.get(0), exerciseList);
} catch (RuntimeException re) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.ArrayList;
import java.util.List;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.emptyCollectionOf;
import static org.hamcrest.core.IsCollectionContaining.hasItem;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -109,22 +109,19 @@ public void toString_shouldReturnSetInformations() throws Exception {
}

public class givenAnExerciseWithSets {
private List<Set> sets;

@Before
public void setUp() throws Exception {
sets = new ArrayList<>();
exercise = new BasicExercise("Bankdrücken", sets);
exercise = new BasicExercise();
}

@Test
public void getName_shouldReturnNameFromInitialization() throws Exception {
assertThat(exercise.getName(), equalTo("Bankdrücken"));
assertThat(exercise.getName(), equalTo(""));
}

@Test
public void getSets_shouldReturnSets() throws Exception {
assertThat(exercise.getSets(), equalTo(sets));
public void getSets_shouldReturnSetsEmptyListOnConstruction() throws Exception {
assertThat(exercise.getSets(), emptyCollectionOf(Set.class));
}

@Test
Expand All @@ -143,13 +140,13 @@ public void removeSet_shouldRemoveSetFromSets() throws Exception {

exercise.addSet(set);
exercise.removeSet(set);
assertThat(sets, not(hasItem(set)));
assertThat(exercise.getSets(), not(hasItem(set)));
}

@Test
public void getCurrentSet_shouldReturnCurrentSetOnStartup() throws Exception {
public void getCurrentSet_shouldReturnCurrent() throws Exception {
Set set = mock(Set.class);
sets.add(set);
exercise.addSet(set);

assertThat(exercise.getCurrentSet(), equalTo(set));
}
Expand All @@ -158,8 +155,8 @@ public void getCurrentSet_shouldReturnCurrentSetOnStartup() throws Exception {
public void getCurrentSet_shouldReturnSecondSet() throws Exception {
Set set = mock(Set.class);

sets.add(mock(Set.class));
sets.add(set);
exercise.addSet(mock(Set.class));
exercise.addSet(set);

exercise.setCurrentSet(1);

Expand All @@ -173,7 +170,7 @@ public void setCurrentSetWithoutSets_shouldDoNothing() throws Exception {

@Test
public void setSetNumber_shouldSetSetNumberToZero() throws Exception {
sets.add(mock(Set.class));
exercise.addSet(mock(Set.class));

exercise.setCurrentSet(-1);

Expand All @@ -182,9 +179,12 @@ public void setSetNumber_shouldSetSetNumberToZero() throws Exception {

@Test
public void setCurrentSet_ShouldSetToLastSetWhenSizeExceeded() throws Exception {
sets.add(mock(Set.class));
Set set = mock(Set.class);
exercise.addSet(set);

exercise.setCurrentSet(exercise.getSets().size() + 1);

exercise.setCurrentSet(sets.size() + 1);
assertThat(exercise.getCurrentSet(), equalTo(set));
}

@Test(expected = SetNotAvailableException.class)
Expand All @@ -203,7 +203,7 @@ public void oneSetWithoutReps_shouldHaveZeroProgress() throws Exception {
Set set = mock(Set.class);
when(set.getMaxReps()).thenReturn(100);
when(set.getReps()).thenReturn(0);
sets.add(set);
exercise.addSet(set);
assertThat(exercise.getProgress(), equalTo(0.0));
}

Expand All @@ -212,7 +212,7 @@ public void oneSetWithMaxReps_shouldHaveFullProgress() throws Exception {
Set set = mock(Set.class);
when(set.getMaxReps()).thenReturn(100);
when(set.getReps()).thenReturn(100);
sets.add(set);
exercise.addSet(set);
assertThat(exercise.getProgress(), equalTo(1.0));
}

Expand All @@ -221,39 +221,39 @@ public void oneSetWithHalfReps_shouldHaveHalfProgress() throws Exception {
Set set = mock(Set.class);
when(set.getMaxReps()).thenReturn(100);
when(set.getReps()).thenReturn(50);
sets.add(set);
exercise.addSet(set);
assertThat(exercise.getProgress(), equalTo(0.5));
}

@Test
public void twoSetsWithoutReps_shouldHaveHalfProgress() throws Exception {
sets.add(mock(Set.class));
exercise.addSet(mock(Set.class));
Set set = mock(Set.class);
when(set.getMaxReps()).thenReturn(100);
when(set.getReps()).thenReturn(0);
sets.add(set);
exercise.addSet(set);
exercise.setCurrentSet(1);
assertThat(exercise.getProgress(), equalTo(0.5));
}

@Test
public void twoSetsWithMaxReps_shouldHaveFallProgress() throws Exception {
sets.add(mock(Set.class));
exercise.addSet(mock(Set.class));
Set set = mock(Set.class);
when(set.getMaxReps()).thenReturn(100);
when(set.getReps()).thenReturn(100);
sets.add(set);
exercise.addSet(set);
exercise.setCurrentSet(1);
assertThat(exercise.getProgress(), equalTo(1.0));
}

@Test
public void twoSetsWithHalfReps_shouldHave75Progress() throws Exception {
sets.add(mock(Set.class));
exercise.addSet(mock(Set.class));
Set set = mock(Set.class);
when(set.getMaxReps()).thenReturn(100);
when(set.getReps()).thenReturn(50);
sets.add(set);
exercise.addSet(set);
exercise.setCurrentSet(1);
assertThat(exercise.getProgress(), equalTo(0.75));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

import java.util.ArrayList;
import java.util.List;

import static org.hamcrest.CoreMatchers.*;
Expand Down Expand Up @@ -62,7 +61,7 @@ public void setUp() throws Exception {

@Test
public void saveUnpersistedExercise_shouldAssignNewExerciseId() throws Exception {
Exercise exercise = new BasicExercise("nam", new ArrayList<Set>());
Exercise exercise = new BasicExercise();

assertThat(exercise.getExerciseId(), nullValue());
exerciseRepository.save(workoutId, 1, exercise);
Expand All @@ -71,7 +70,7 @@ public void saveUnpersistedExercise_shouldAssignNewExerciseId() throws Exception

@Test
public void savePersistedExercise_shouldKeepExerciseId() {
Exercise exercise = new BasicExercise("name", new ArrayList<Set>());
Exercise exercise = new BasicExercise();
exerciseRepository.save(workoutId, 1, exercise);
ExerciseId exerciseId = exercise.getExerciseId();

Expand All @@ -97,10 +96,9 @@ public void updateExercises_shouldSaveTheCorrectEntity() {

@Test
public void saveExercise_shouldAlsoSaveSets() {
List<Set> sets = new ArrayList<>();
Exercise exercise = new BasicExercise();
Set set = new BasicSet();
sets.add(set);
Exercise exercise = new BasicExercise("name", sets);
exercise.addSet(set);

exerciseRepository.save(workoutId, 1, exercise);

Expand Down Expand Up @@ -129,12 +127,11 @@ public void loadAllExercisesBelongsTo_shouldReturnExercisesOfWorkout() throws Ex

@Test
public void loadAllExercisesBelongsTo_shouldAddSetsToExercise() throws Exception {
ArrayList<Set> sets = new ArrayList<>();
Exercise exercise = new BasicExercise();
Set set1 = new BasicSet();
sets.add(set1);
exercise.addSet(set1);
Set set2 = new BasicSet();
sets.add(set2);
Exercise exercise = new BasicExercise("name", sets);
exercise.addSet(set2);

exerciseRepository.save(workoutId, 1, exercise);

Expand Down

0 comments on commit dc6cb13

Please sign in to comment.