refactoring : repeated switches

This commit is contained in:
haerong22
2022-04-03 16:32:13 +09:00
parent 7f55ac3858
commit a78e242e4b
3 changed files with 43 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
package com.example.refactoring._12_repeated_switches;
public class SwitchImprovements {
public int vacationHours(String type) {
return switch (type) {
case "full-time" -> 120;
case "part-time" -> 80;
case "temporal" -> 32;
default -> 0;
};
}
}

View File

@@ -0,0 +1,15 @@
package com.example.refactoring._12_repeated_switches._before;
public class SwitchImprovements {
public int vacationHours(String type) {
int result;
switch (type) {
case "full-time": result = 120; break;
case "part-time": result = 80; break;
case "temporal": result = 32; break;
default: result = 0;
}
return result;
}
}

View File

@@ -0,0 +1,15 @@
package com.example.refactoring._12_repeated_switches;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class SwitchImprovementsTest {
@Test
void vacationHours() {
SwitchImprovements si = new SwitchImprovements();
assertEquals(120, si.vacationHours("full-time"));
}
}