|
1 | 1 | package org.utplsql.cli; |
2 | 2 |
|
| 3 | +import org.junit.jupiter.api.AfterEach; |
| 4 | +import org.junit.jupiter.api.BeforeEach; |
3 | 5 | import org.junit.jupiter.api.Test; |
| 6 | +import org.utplsql.cli.util.SystemOutCapturer; |
| 7 | + |
| 8 | +import java.io.IOException; |
| 9 | +import java.util.Arrays; |
4 | 10 |
|
5 | 11 | import static org.junit.jupiter.api.Assertions.assertEquals; |
6 | 12 |
|
7 | 13 | public class VersionInfoCommandIT { |
8 | 14 |
|
| 15 | + private SystemOutCapturer capturer; |
| 16 | + |
| 17 | + @BeforeEach |
| 18 | + public void setupCaptureSystemOut() { |
| 19 | + capturer = new SystemOutCapturer(); |
| 20 | + } |
| 21 | + |
| 22 | + private int getNonEmptyLines(String content) { |
| 23 | + return (int) Arrays.stream(content.split("[\n|\r]")) |
| 24 | + .filter(line -> !line.isEmpty()) |
| 25 | + .count(); |
| 26 | + } |
| 27 | + |
| 28 | + private void assertNumberOfLines( int expected, String content ) { |
| 29 | + int numOfLines = getNonEmptyLines(content); |
| 30 | + assertEquals(expected, numOfLines, String.format("Expected output to have %n lines, but got %n", expected, numOfLines)); |
| 31 | + } |
9 | 32 | @Test |
10 | 33 | public void infoCommandRunsWithoutConnection() throws Exception { |
11 | 34 |
|
| 35 | + capturer.start(); |
| 36 | + |
12 | 37 | int result = TestHelper.runApp("info"); |
13 | 38 |
|
| 39 | + String output = capturer.stop(); |
| 40 | + |
14 | 41 | assertEquals(0, result); |
| 42 | + assertNumberOfLines(2, output); |
15 | 43 | } |
16 | 44 | @Test |
17 | 45 | public void infoCommandRunsWithConnection() throws Exception { |
18 | 46 |
|
| 47 | + capturer.start(); |
| 48 | + |
19 | 49 | int result = TestHelper.runApp("info", TestHelper.getConnectionString()); |
20 | 50 |
|
| 51 | + String output = capturer.stop(); |
| 52 | + |
21 | 53 | assertEquals(0, result); |
| 54 | + assertNumberOfLines(3, output); |
| 55 | + } |
| 56 | + |
| 57 | + @AfterEach |
| 58 | + public void cleanupCaptureSystemOut() throws IOException { |
| 59 | + capturer.stop(); |
22 | 60 | } |
23 | 61 | } |
0 commit comments