Skip to content

Commit

Permalink
refix the bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanSST committed Mar 24, 2024
1 parent 482ce90 commit 541721d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public void tareAllBoxes() {

private void tareIfNeeded(String id) {
Box box = boxService.getBox(id);
if (box.getWeight() < 50) {
if (box.getWeight() <= -5 //
|| (Math.abs(box.getWeight()) >= 5 && Math.abs(box.getWeight()) < 50)) {
scaleService.tare(id);
} else {
log.info("No need to tare Scale {}, weight was {}.", id, box.getWeight());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,18 @@ void setUp() throws Exception {
@Test
void test_WhenWeight0_tareIsCalled() {
setAllWeightsTo(0);
callAndCheckTimesCalled(2);
callAndCheckTimesCalled(0);
}

@Test
void test_WhenWeightMinus165_tareIsCalled() {
setAllWeightsTo(-165);
void test_WhenWeight4_tareIsCalled() {
setAllWeightsTo(4);
callAndCheckTimesCalled(0);
}

@Test
void test_WhenWeight5_tareIsCalled() {
setAllWeightsTo(5);
callAndCheckTimesCalled(2);
}

Expand All @@ -55,6 +61,24 @@ void test_WhenWeight65_tareIsCalled() {
callAndCheckTimesCalled(0);
}

@Test
void test_WhenWeightMinus4_tareIsCalled() {
setAllWeightsTo(-4);
callAndCheckTimesCalled(0);
}

@Test
void test_WhenWeightMinus5_tareIsCalled() {
setAllWeightsTo(-5);
callAndCheckTimesCalled(2);
}

@Test
void test_WhenWeightMinus165_tareIsCalled() {
setAllWeightsTo(-165);
callAndCheckTimesCalled(2);
}

private void setAllWeightsTo(int weight) {
boxService.getBoxes().stream()//
.forEach(b -> b.setWeight(weight));
Expand Down

0 comments on commit 541721d

Please sign in to comment.