-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppTest.java
More file actions
62 lines (46 loc) · 1.59 KB
/
Copy pathAppTest.java
File metadata and controls
62 lines (46 loc) · 1.59 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
package com.example;
import org.junit.jupiter.api.Test;
import picocli.CommandLine;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.PrintWriter;
import java.io.StringWriter;
/**
* Unit test for simple App.
*/
class AppTest {
@Test
void testVoidOption() {
App app = new App();
CommandLine cmd = new CommandLine(app);
StringWriter sw = new StringWriter();
cmd.setOut(new PrintWriter(sw));
int exitCode = cmd.execute();
System.out.println(sw.toString());
assertEquals(0, exitCode);
assertTrue(sw.toString().contains("No arguments provided. Displaying help."));
}
@Test
void testHelpOption() {
App app = new App();
CommandLine cmd = new CommandLine(app);
StringWriter sw = new StringWriter();
cmd.setOut(new PrintWriter(sw));
int exitCode = cmd.execute("--help");
System.out.println(sw.toString());
assertEquals(0, exitCode);
assertTrue(sw.toString().contains("Usage: App"));
}
@Test
void testQuery() {
App app = new App();
CommandLine cmd = new CommandLine(app);
StringWriter sw = new StringWriter();
cmd.setOut(new PrintWriter(sw));
cmd.setErr(new PrintWriter(sw));
int exitCode = cmd.execute("--query","SELECT_products.sql");
System.out.println(sw.toString());
assertEquals(0, exitCode);
assertTrue(sw.toString().contains("Connection to PostgreSQL established."));
}
}