Skip to content

Commit 082208b

Browse files
committed
Merge branch 'coverall'
2 parents f9ef0a6 + 536164b commit 082208b

File tree

6 files changed

+505
-44
lines changed

6 files changed

+505
-44
lines changed

src/main/java/com/googlecode/scheme2ddl/Main.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class Main {
3434
private static boolean stopOnWarning = false;
3535
private static boolean replaceSequenceValues = false;
3636
private static String customConfigLocation = null;
37-
private static String defaultConfigLocation = "scheme2ddl.config.xml";
37+
private static final String defaultConfigLocation = "scheme2ddl.config.xml";
3838
private static String dbUrl = null;
3939
private static String schemas;
4040
private static boolean isLaunchedByDBA;
@@ -79,7 +79,7 @@ private static void testDBConnection(ConfigurableApplicationContext context) thr
7979
if (connectionDao.isConnectionAvailable()) {
8080
System.out.println("OK success connection to " + dataSource.getURL());
8181
} else {
82-
System.out.println("FAIL connect to " + dataSource.getURL());
82+
System.out.println("FAIL connect to " + dataSource.getURL()); //todo unreacheble statement
8383
}
8484
}
8585

@@ -337,7 +337,7 @@ private static void collectArgs(String[] args) throws Exception {
337337
String msg = "Unknown argument: " + arg;
338338
System.err.println(msg);
339339
printUsage();
340-
throw new Exception("");
340+
throw new Exception(msg);
341341
}
342342
}
343343
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package com.googlecode.scheme2ddl;
2+
3+
import org.springframework.test.util.ReflectionTestUtils;
4+
import org.testng.annotations.AfterMethod;
5+
import org.testng.annotations.BeforeMethod;
6+
import org.testng.annotations.DataProvider;
7+
import org.testng.annotations.Test;
8+
9+
import java.io.ByteArrayOutputStream;
10+
import java.io.PrintStream;
11+
12+
import static org.hamcrest.MatcherAssert.assertThat;
13+
import static org.hamcrest.core.StringContains.containsString;
14+
import static org.testng.Assert.*;
15+
16+
/**
17+
* Created by Anton Reshetnikov on 06 Dec 2016.
18+
*/
19+
20+
public class MainCLITest {
21+
22+
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
23+
private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
24+
25+
private final PrintStream outOriginal = System.out;
26+
private final PrintStream errorOriginal = System.err;
27+
28+
@BeforeMethod
29+
public void setUp() throws Exception {
30+
ReflectionTestUtils.setField(Main.class, "justPrintUsage", false);
31+
ReflectionTestUtils.setField(Main.class, "justPrintVersion", false);
32+
ReflectionTestUtils.setField(Main.class, "justTestConnection", false);
33+
ReflectionTestUtils.setField(Main.class, "dbUrl", null);
34+
}
35+
36+
@BeforeMethod
37+
public void setUpStreams() {
38+
System.setOut(new PrintStream(outContent));
39+
System.setErr(new PrintStream(errContent));
40+
}
41+
42+
@AfterMethod
43+
public void cleanUpStreams() {
44+
System.setOut(outOriginal);
45+
System.setErr(errorOriginal);
46+
outContent.reset();
47+
errContent.reset();
48+
}
49+
50+
51+
@DataProvider
52+
public static Object[][] testPrintUsageOptionsParams() {
53+
return new Object[][]{
54+
new String[][]{{"-h"}},
55+
new String[][]{{"--help"}},
56+
new String[][]{{"-help"}},
57+
new String[][]{{"-h"}},
58+
new String[][]{{"-url", "1", "-tc", "-h"}},
59+
new String[][]{{"-tc", "--help"}},
60+
};
61+
}
62+
63+
64+
@Test(dataProvider = "testPrintUsageOptionsParams")
65+
public void testPrintUsageOptions(String[] args) throws Exception {
66+
Main.main(args);
67+
assertThat(outContent.toString(), containsString("java -jar scheme2ddl.jar"));
68+
assertThat(outContent.toString(), containsString("example: scott/tiger@localhost:1521:ORCL"));
69+
}
70+
71+
@Test
72+
public void testPrintVersionOption() throws Exception {
73+
String[] args = {"-version"};
74+
Main.main(args);
75+
assertThat(outContent.toString(), containsString("scheme2ddl version "));
76+
}
77+
78+
@Test(expectedExceptions = Exception.class, expectedExceptionsMessageRegExp = "Unknown argument: .*")
79+
public void testUnknownArgument() throws Exception {
80+
String[] args = {"-xYx"};
81+
Main.main(args);
82+
}
83+
84+
85+
}

0 commit comments

Comments
 (0)