Code review for Curtains

This commit is contained in:
Claudio Maggioni 2020-04-15 16:36:51 +02:00
parent e5011110e7
commit d964f8846f
4 changed files with 17 additions and 14 deletions

View File

@ -75,6 +75,7 @@ public class SpringFoxConfig {
.or(PathSelectors.regex("/smartPlug.*")::apply) .or(PathSelectors.regex("/smartPlug.*")::apply)
.or(PathSelectors.regex("/switch.*")::apply) .or(PathSelectors.regex("/switch.*")::apply)
.or(PathSelectors.regex("/motionSensor.*")::apply) .or(PathSelectors.regex("/motionSensor.*")::apply)
.or(PathSelectors.regex("/curtains.*")::apply)
.or(PathSelectors.regex("/auth/profile.*")::apply); .or(PathSelectors.regex("/auth/profile.*")::apply);
} }

View File

@ -19,7 +19,7 @@ public class CurtainsController {
@Autowired private CurtainsRepository curtainsService; @Autowired private CurtainsRepository curtainsService;
@GetMapping @GetMapping
List<Curtains> findAll() { public List<Curtains> findAll() {
return toList(curtainsService.findAll()); return toList(curtainsService.findAll());
} }
@ -31,7 +31,7 @@ public class CurtainsController {
private Curtains save(Curtains newRL, CurtainsSaveRequest s) { private Curtains save(Curtains newRL, CurtainsSaveRequest s) {
newRL.setName(s.getName()); newRL.setName(s.getName());
newRL.setRoomId(s.getRoomId()); newRL.setRoomId(s.getRoomId());
newRL.setOpening(s.getOpening()); newRL.setOpenedAmount(s.getOpening());
return curtainsService.save(newRL); return curtainsService.save(newRL);
} }

View File

@ -9,11 +9,13 @@ import javax.validation.constraints.NotNull;
@Entity @Entity
public class Curtains extends OutputDevice { public class Curtains extends OutputDevice {
/**
* it represents how much the curtains are opened, 0 is completely closed 100 is completely open
*/
@NotNull @NotNull
@Column(nullable = false) @Column(nullable = false)
@Min(0) @Min(0)
@Max(100) @Max(100)
/*it represents how much the curtains are opened, 0 is completely closed 100 is completely open*/
private int openedAmount; private int openedAmount;
public Curtains() { public Curtains() {
@ -21,13 +23,13 @@ public class Curtains extends OutputDevice {
this.openedAmount = 0; this.openedAmount = 0;
} }
/*return the current state of the curtain*/ /** return the current state of the curtain */
public int getOpening() { public int getOpenedAmount() {
return this.openedAmount; return this.openedAmount;
} }
/*sets the state to a desired one*/ /** sets the state to a desired one */
public void setOpening(int newOpening) { public void setOpenedAmount(int newOpening) {
if (newOpening < 0) { if (newOpening < 0) {
this.openedAmount = 0; this.openedAmount = 0;
} else if (newOpening > 100) { } else if (newOpening > 100) {

View File

@ -19,27 +19,27 @@ public class CurtainsTests {
@Test @Test
@DisplayName("State when just created") @DisplayName("State when just created")
public void initialState() { public void initialState() {
assertEquals(0, this.curtains.getOpening()); assertEquals(0, this.curtains.getOpenedAmount());
} }
@Test @Test
@DisplayName("Check wether setting the opening works") @DisplayName("Check wether setting the opening works")
public void normalSet() { public void normalSet() {
this.curtains.setOpening(42); this.curtains.setOpenedAmount(42);
assertEquals(42, this.curtains.getOpening()); assertEquals(42, this.curtains.getOpenedAmount());
} }
@Test @Test
@DisplayName("Set setting a negative number") @DisplayName("Set setting a negative number")
public void setNeg() { public void setNeg() {
this.curtains.setOpening(-1); this.curtains.setOpenedAmount(-1);
assertEquals(0, this.curtains.getOpening()); assertEquals(0, this.curtains.getOpenedAmount());
} }
@Test @Test
@DisplayName("Setting state to a number greater than 100") @DisplayName("Setting state to a number greater than 100")
public void setLarge() { public void setLarge() {
this.curtains.setOpening(32768); this.curtains.setOpenedAmount(32768);
assertEquals(100, this.curtains.getOpening()); assertEquals(100, this.curtains.getOpenedAmount());
} }
} }