refactoring : speculative generality - remove dead code

This commit is contained in:
haerong22
2022-04-05 01:52:40 +09:00
parent b844d40585
commit 4321bf7ffe
3 changed files with 76 additions and 0 deletions

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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());
}
}