Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit 7129c3a

Browse files
author
Aleksi Salmela
committed
Fix document command test in Windows.
1 parent 4f186c5 commit 7129c3a

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/test/java/fi/helsinki/cs/tmc/cli/command/DocumentCommandTest.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
package fi.helsinki.cs.tmc.cli.command;
22

3+
import static org.mockito.Mockito.when;
4+
import static org.powermock.api.mockito.PowerMockito.mockStatic;
5+
36
import fi.helsinki.cs.tmc.cli.Application;
47
import fi.helsinki.cs.tmc.cli.CliContext;
8+
import fi.helsinki.cs.tmc.cli.io.EnvironmentUtil;
59
import fi.helsinki.cs.tmc.cli.io.TestIo;
610

711
import org.junit.Before;
812
import org.junit.Test;
13+
import org.junit.runner.RunWith;
14+
import org.powermock.core.classloader.annotations.PrepareForTest;
15+
import org.powermock.modules.junit4.PowerMockRunner;
916

17+
@RunWith(PowerMockRunner.class)
18+
@PrepareForTest(EnvironmentUtil.class)
1019
public class DocumentCommandTest {
1120

1221
private Application app;
@@ -18,14 +27,28 @@ public void setUp() {
1827
io = new TestIo();
1928
ctx = new CliContext(io);
2029
app = new Application(ctx);
30+
31+
mockStatic(EnvironmentUtil.class);
32+
when(EnvironmentUtil.getTerminalWidth()).thenReturn(100);
2133
}
2234

2335
@Test
2436
public void run() throws InterruptedException {
37+
when(EnvironmentUtil.isWindows()).thenReturn(false);
38+
app = new Application(ctx);
39+
40+
String[] args = {"document", "-s", "0"};
41+
app.run(args);
42+
io.assertContains("Original dev team");
43+
}
44+
45+
@Test
46+
public void failOnWindows() throws InterruptedException {
47+
when(EnvironmentUtil.isWindows()).thenReturn(true);
2548
app = new Application(ctx);
2649

2750
String[] args = {"document", "-s", "0"};
2851
app.run(args);
29-
io.assertContains("dev team");
52+
io.assertContains("Command document doesn't exist");
3053
}
3154
}

0 commit comments

Comments
 (0)