forked from happi1masia-pixel/Java-Tests
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomeTest.java
More file actions
87 lines (62 loc) · 2.17 KB
/
HomeTest.java
File metadata and controls
87 lines (62 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class SmartHomeTest {
@Test
void testEncapsulation_DeviceState() {
Device device = new Device("Generic Device");
assertFalse(device.isOn());
device.turnOn();
assertTrue(device.isOn());
device.turnOff();
assertFalse(device.isOn());
}
@Test
void testInheritance_Light() {
Light light = new Light("Living Room Light");
light.setBrightness(75);
assertEquals(75, light.getBrightness());
light.turnOn();
assertTrue(light.isOn());
}
@Test
void testInheritance_Thermostat() {
Thermostat thermostat = new Thermostat("Main Thermostat");
thermostat.setTemperature(25.5);
assertEquals(25.5, thermostat.getTemperature());
thermostat.turnOn();
assertTrue(thermostat.isOn());
}
@Test
void testPolymorphism_StatusOverride() {
Device light = new Light("Bedroom Light");
light.turnOn();
Device thermostat = new Thermostat("Hall Thermostat");
thermostat.turnOn();
String lightStatus = light.getStatus();
String thermoStatus = thermostat.getStatus();
assertTrue(lightStatus.contains("Light"));
assertTrue(thermoStatus.contains("Thermostat"));
}
@Test
void testComposition_SmartHome() {
SmartHome home = new SmartHome();
Light light = new Light("Kitchen Light");
Thermostat thermostat = new Thermostat("Kitchen Thermostat");
home.addDevice(light);
home.addDevice(thermostat);
assertEquals(2, home.getDevices().size());
}
@Test
void testSmartHome_StatusAggregation() {
SmartHome home = new SmartHome();
Light light = new Light("Office Light");
Thermostat thermostat = new Thermostat("Office Thermostat");
light.turnOn();
thermostat.turnOn();
home.addDevice(light);
home.addDevice(thermostat);
String statuses = home.getAllStatuses();
assertTrue(statuses.contains("Office Light"));
assertTrue(statuses.contains("Office Thermostat"));
}
}