File tree Expand file tree Collapse file tree 3 files changed +29
-2
lines changed
Expand file tree Collapse file tree 3 files changed +29
-2
lines changed Original file line number Diff line number Diff line change 11package next .optional ;
22
3+ import java .util .Optional ;
4+
35public class Computer {
46 private Soundcard soundcard ;
57
68 public Computer (Soundcard soundcard ) {
7- super ();
89 this .soundcard = soundcard ;
910 }
1011
Original file line number Diff line number Diff line change 33import next .optional .Computer .Soundcard ;
44import next .optional .Computer .USB ;
55
6+ import java .util .Optional ;
7+
68public class ComputerStore {
79 public static final String UNKNOWN_VERSION = "UNKNOWN" ;
810
Original file line number Diff line number Diff line change 88import next .optional .Computer .USB ;
99
1010public 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}
You can’t perform that action at this time.
0 commit comments