Code review for Curtains
This commit is contained in:
parent
e5011110e7
commit
d964f8846f
4 changed files with 17 additions and 14 deletions
|
@ -75,6 +75,7 @@ public class SpringFoxConfig {
|
|||
.or(PathSelectors.regex("/smartPlug.*")::apply)
|
||||
.or(PathSelectors.regex("/switch.*")::apply)
|
||||
.or(PathSelectors.regex("/motionSensor.*")::apply)
|
||||
.or(PathSelectors.regex("/curtains.*")::apply)
|
||||
.or(PathSelectors.regex("/auth/profile.*")::apply);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ public class CurtainsController {
|
|||
@Autowired private CurtainsRepository curtainsService;
|
||||
|
||||
@GetMapping
|
||||
List<Curtains> findAll() {
|
||||
public List<Curtains> findAll() {
|
||||
return toList(curtainsService.findAll());
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ public class CurtainsController {
|
|||
private Curtains save(Curtains newRL, CurtainsSaveRequest s) {
|
||||
newRL.setName(s.getName());
|
||||
newRL.setRoomId(s.getRoomId());
|
||||
newRL.setOpening(s.getOpening());
|
||||
newRL.setOpenedAmount(s.getOpening());
|
||||
|
||||
return curtainsService.save(newRL);
|
||||
}
|
||||
|
|
|
@ -9,11 +9,13 @@ import javax.validation.constraints.NotNull;
|
|||
@Entity
|
||||
public class Curtains extends OutputDevice {
|
||||
|
||||
/**
|
||||
* it represents how much the curtains are opened, 0 is completely closed 100 is completely open
|
||||
*/
|
||||
@NotNull
|
||||
@Column(nullable = false)
|
||||
@Min(0)
|
||||
@Max(100)
|
||||
/*it represents how much the curtains are opened, 0 is completely closed 100 is completely open*/
|
||||
private int openedAmount;
|
||||
|
||||
public Curtains() {
|
||||
|
@ -21,13 +23,13 @@ public class Curtains extends OutputDevice {
|
|||
this.openedAmount = 0;
|
||||
}
|
||||
|
||||
/*return the current state of the curtain*/
|
||||
public int getOpening() {
|
||||
/** return the current state of the curtain */
|
||||
public int getOpenedAmount() {
|
||||
return this.openedAmount;
|
||||
}
|
||||
|
||||
/*sets the state to a desired one*/
|
||||
public void setOpening(int newOpening) {
|
||||
/** sets the state to a desired one */
|
||||
public void setOpenedAmount(int newOpening) {
|
||||
if (newOpening < 0) {
|
||||
this.openedAmount = 0;
|
||||
} else if (newOpening > 100) {
|
||||
|
|
|
@ -19,27 +19,27 @@ public class CurtainsTests {
|
|||
@Test
|
||||
@DisplayName("State when just created")
|
||||
public void initialState() {
|
||||
assertEquals(0, this.curtains.getOpening());
|
||||
assertEquals(0, this.curtains.getOpenedAmount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Check wether setting the opening works")
|
||||
public void normalSet() {
|
||||
this.curtains.setOpening(42);
|
||||
assertEquals(42, this.curtains.getOpening());
|
||||
this.curtains.setOpenedAmount(42);
|
||||
assertEquals(42, this.curtains.getOpenedAmount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Set setting a negative number")
|
||||
public void setNeg() {
|
||||
this.curtains.setOpening(-1);
|
||||
assertEquals(0, this.curtains.getOpening());
|
||||
this.curtains.setOpenedAmount(-1);
|
||||
assertEquals(0, this.curtains.getOpenedAmount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Setting state to a number greater than 100")
|
||||
public void setLarge() {
|
||||
this.curtains.setOpening(32768);
|
||||
assertEquals(100, this.curtains.getOpening());
|
||||
this.curtains.setOpenedAmount(32768);
|
||||
assertEquals(100, this.curtains.getOpenedAmount());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue