Skip to content

Commit b9ccaf9

Browse files
committed
fixed Problem with current working bar not Updating correctly
1 parent d54cdb5 commit b9ccaf9

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/main/java/de/doubleslash/keeptime/controller/Controller.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,21 @@ public void editProject(final Project projectToBeUpdated, final Project newValue
186186

187187
public void editWork(final Work workToBeEdited, final Work newValuedWork) {
188188
LOG.info("Changing work '{}' to '{}'.", workToBeEdited, newValuedWork);
189-
int index = model.getPastWorkItems().size() - 1;
190-
if (model.getPastWorkItems().contains(workToBeEdited)) {
191-
index = model.getPastWorkItems().indexOf(workToBeEdited);
189+
Work toRemove = null;
190+
for (final Work w : model.getPastWorkItems()) {
191+
if (w.getId() == workToBeEdited.getId()) {
192+
toRemove = w;
193+
LOG.debug("changing past Work");
194+
}
195+
}
196+
197+
int index;
198+
if (toRemove != null) {
199+
index = model.getPastWorkItems().indexOf(toRemove);
192200
model.getPastWorkItems().remove(index);
201+
} else {
202+
// TODO sort in right Place
203+
index = model.getPastWorkItems().size() - 1;
193204
}
194205

195206
workToBeEdited.setCreationDate(newValuedWork.getCreationDate());

src/test/java/de/doubleslash/keeptime/controller/ControllerTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616

1717
package de.doubleslash.keeptime.controller;
1818

19+
import static org.hamcrest.Matchers.contains;
1920
import static org.hamcrest.Matchers.equalTo;
2021
import static org.hamcrest.Matchers.is;
22+
import static org.hamcrest.Matchers.not;
2123
import static org.junit.Assert.assertEquals;
2224
import static org.junit.Assert.assertThat;
2325

@@ -382,10 +384,12 @@ public void shouldNotUpdateOthersWhenWorkItemIsEdited() {
382384
testee.editWork(originalWork, newWork);
383385

384386
assertThat("changed amout of WorkItems", model.getPastWorkItems().size(), equalTo(2));
387+
assertThat("pastWorkItems contains work wich shouldnt be added", model.getPastWorkItems(),
388+
not(contains(newWork)));
385389

386390
final ArgumentCaptor<Work> argument = ArgumentCaptor.forClass(Work.class);
387391
Mockito.verify(model.getWorkRepository(), Mockito.times(1)).save(argument.capture());
388-
assertThat("not saved Persistent", argument.getValue(), is(originalWork));
392+
assertThat("saved other Work persistently than what should be updated", argument.getValue(), is(originalWork));
389393

390394
}
391395

0 commit comments

Comments
 (0)