-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPrimaryControllerTest.java
More file actions
32 lines (26 loc) · 1.08 KB
/
PrimaryControllerTest.java
File metadata and controls
32 lines (26 loc) · 1.08 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
package ratemate;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import java.io.IOException;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
public class PrimaryControllerTest {
@Test
public void testSwitchToSecondary() {
try (MockedStatic<App> appMock = Mockito.mockStatic(App.class)) {
appMock.when(() -> App.setRoot("secondary")).thenReturn(null); // Simulate App.setRoot()
PrimaryController controller = new PrimaryController();
assertDoesNotThrow(controller::switchToSecondary);
}
}
@Test
public void testSwitchToSecondaryIOException() {
try (MockedStatic<App> appMock = Mockito.mockStatic(App.class)) {
appMock.when(() -> App.setRoot("secondary"))
.thenThrow(new IOException("File not found"));
PrimaryController controller = new PrimaryController();
IOException ex = assertThrows(IOException.class, controller::switchToSecondary);
assertEquals("File not found", ex.getMessage());
}
}
}