Skip to content

Commit 350a7d1

Browse files
committed
add testcase to Optional
1 parent 7ca3fc3 commit 350a7d1

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

src/main/java/next/optional/Computer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package next.optional;
22

3+
import java.util.Optional;
4+
35
public class Computer {
46
private Soundcard soundcard;
57

68
public Computer(Soundcard soundcard) {
7-
super();
89
this.soundcard = soundcard;
910
}
1011

src/main/java/next/optional/ComputerStore.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import next.optional.Computer.Soundcard;
44
import next.optional.Computer.USB;
55

6+
import java.util.Optional;
7+
68
public class ComputerStore {
79
public static final String UNKNOWN_VERSION = "UNKNOWN";
810

src/test/java/next/optional/ComputerStoreTest.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import next.optional.Computer.USB;
99

1010
public class ComputerStoreTest {
11-
1211
@Test
1312
public void getVersion() {
1413
String version = "pobi's usb";
@@ -33,4 +32,29 @@ public void getVersionWhenUSBIsNull() throws Exception {
3332
Computer computer = new Computer(new Soundcard(null));
3433
assertThat(ComputerStore.getVersion(computer)).isEqualTo(ComputerStore.UNKNOWN_VERSION);
3534
}
35+
36+
@Test
37+
public void getVersionOptional() {
38+
String version = "pobi's usb";
39+
Soundcard soundcard = new Soundcard(new USB(version));
40+
Computer computer = new Computer(soundcard);
41+
assertThat(ComputerStore.getVersionOptional(computer)).isEqualTo(version);
42+
}
43+
44+
@Test
45+
public void getVersionOptionalWhenComputerIsNull() throws Exception {
46+
assertThat(ComputerStore.getVersionOptional(null)).isEqualTo(ComputerStore.UNKNOWN_VERSION);
47+
}
48+
49+
@Test
50+
public void getVersionOptionalWhenSoundcardIsNull() throws Exception {
51+
Computer computer = new Computer(null);
52+
assertThat(ComputerStore.getVersionOptional(computer)).isEqualTo(ComputerStore.UNKNOWN_VERSION);
53+
}
54+
55+
@Test
56+
public void getVersionOptionalWhenUSBIsNull() throws Exception {
57+
Computer computer = new Computer(new Soundcard(null));
58+
assertThat(ComputerStore.getVersionOptional(computer)).isEqualTo(ComputerStore.UNKNOWN_VERSION);
59+
}
3660
}

0 commit comments

Comments
 (0)