refactoring : speculative generality - remove dead code
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package com.example.refactoring._15_speculative_generality._35_remove_dead_code;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class Reservation {
|
||||
|
||||
private String title;
|
||||
|
||||
private LocalDateTime from;
|
||||
|
||||
private LocalDateTime to;
|
||||
|
||||
private LocalDateTime alarm;
|
||||
|
||||
public Reservation(String title, LocalDateTime from, LocalDateTime to) {
|
||||
this.title = title;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
public void setAlarmBefore(int minutes) {
|
||||
this.alarm = this.from.minusMinutes(minutes);
|
||||
}
|
||||
|
||||
public LocalDateTime getAlarm() {
|
||||
return alarm;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.example.refactoring._15_speculative_generality._35_remove_dead_code._before;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class Reservation {
|
||||
|
||||
private String title;
|
||||
|
||||
private LocalDateTime from;
|
||||
|
||||
private LocalDateTime to;
|
||||
|
||||
private LocalDateTime alarm;
|
||||
|
||||
public Reservation(String title, LocalDateTime from, LocalDateTime to) {
|
||||
this.title = title;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
public void setAlarmBefore(int minutes) {
|
||||
this.alarm = this.from.minusMinutes(minutes);
|
||||
}
|
||||
|
||||
public LocalDateTime getAlarm() {
|
||||
return alarm;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.example.refactoring._15_speculative_generality._35_remove_dead_code;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class ReservationTest {
|
||||
|
||||
@Test
|
||||
void reservation() {
|
||||
Reservation reservation = new Reservation(
|
||||
"tennis",
|
||||
LocalDateTime.of(2022, 1, 20, 19, 30),
|
||||
LocalDateTime.of(2022, 1, 20, 9, 0));
|
||||
reservation.setAlarmBefore(30);
|
||||
assertEquals(LocalDateTime.of(2022, 1, 20, 19, 0), reservation.getAlarm());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user