22
33import org .apache .maven .plugin .MojoExecutionException ;
44import org .apache .maven .project .MavenProject ;
5- import org .junit .BeforeClass ;
65import org .junit .Test ;
76import org .utplsql .api .reporter .CoreReporters ;
87import org .utplsql .maven .plugin .model .ReporterParameter ;
1514
1615public class UtPlsqlMojoTest {
1716
18- private static UtPlsqlMojo utPLSQLMojo ;
17+ private UtPlsqlMojo createUtPlsqlMojo () {
18+ System .setProperty ("org.slf4j.simpleLogger.defaultLogLevel" , "debug" );
1919
20- @ BeforeClass
21- public static void setUp () {
22- utPLSQLMojo = new UtPlsqlMojo ();
23- utPLSQLMojo .project = new MavenProject ();
24- utPLSQLMojo .targetDir = "target" ;
20+ UtPlsqlMojo utPlsqlMojo = new UtPlsqlMojo ();
21+ utPlsqlMojo .project = new MavenProject ();
22+ utPlsqlMojo .targetDir = "target" ;
2523
26- utPLSQLMojo .url = "jdbc:oracle:thin:@127.0.0.1:1521:XE" ;
27- utPLSQLMojo .user = "UT3" ;
28- utPLSQLMojo .password = "UT3" ;
24+ utPlsqlMojo .url = "jdbc:oracle:thin:@127.0.0.1:1521:XE" ;
25+ utPlsqlMojo .user = "UT3" ;
26+ utPlsqlMojo .password = "UT3" ;
27+
28+ return utPlsqlMojo ;
2929 }
3030
3131 @ Test
3232 public void junitReporter () throws MojoExecutionException {
33+ UtPlsqlMojo utPlsqlMojo = createUtPlsqlMojo ();
34+
3335 ReporterParameter junitReporter = new ReporterParameter ();
3436 junitReporter .setConsoleOutput (true );
3537 junitReporter .setFileOutput ("junit-report.xml" );
3638 junitReporter .setName (CoreReporters .UT_JUNIT_REPORTER .name ());
37- utPLSQLMojo .reporters .add (junitReporter );
39+ utPlsqlMojo .reporters .add (junitReporter );
3840
39- utPLSQLMojo .execute ();
41+ utPlsqlMojo .execute ();
4042
4143 assertTrue (new File ("target/junit-report.xml" ).exists ());
4244 }
4345
4446 @ Test
4547 public void absolutPath () throws MojoExecutionException {
48+ UtPlsqlMojo utPlsqlMojo = createUtPlsqlMojo ();
49+
4650 ReporterParameter junitReporter = new ReporterParameter ();
4751 junitReporter .setConsoleOutput (true );
4852
@@ -53,9 +57,9 @@ public void absolutPath() throws MojoExecutionException {
5357 junitReporter .setFileOutput ("/tmp/junit-report.xml" );
5458 }
5559 junitReporter .setName (CoreReporters .UT_JUNIT_REPORTER .name ());
56- utPLSQLMojo .reporters .add (junitReporter );
60+ utPlsqlMojo .reporters .add (junitReporter );
5761
58- utPLSQLMojo .execute ();
62+ utPlsqlMojo .execute ();
5963 if (os .contains ("Windows" )) {
6064 assertTrue (new File ("c:/tmp/junit-report.xml" ).exists ());
6165 } else {
@@ -65,50 +69,58 @@ public void absolutPath() throws MojoExecutionException {
6569
6670 @ Test
6771 public void parentDoesNotExist () throws MojoExecutionException {
72+ UtPlsqlMojo utPlsqlMojo = createUtPlsqlMojo ();
73+
6874 ReporterParameter junitReporter = new ReporterParameter ();
6975 junitReporter .setConsoleOutput (true );
7076 junitReporter .setFileOutput ("not-exist/junit-report.xml" );
7177 junitReporter .setName (CoreReporters .UT_JUNIT_REPORTER .name ());
72- utPLSQLMojo .reporters .add (junitReporter );
78+ utPlsqlMojo .reporters .add (junitReporter );
7379
74- utPLSQLMojo .execute ();
80+ utPlsqlMojo .execute ();
7581
7682 assertTrue (new File ("target/not-exist/junit-report.xml" ).exists ());
7783 }
7884
7985 @ Test
8086 public void onlyConsoleOutput () throws MojoExecutionException {
87+ UtPlsqlMojo utPlsqlMojo = createUtPlsqlMojo ();
88+
8189 ReporterParameter junitReporter = new ReporterParameter ();
8290 junitReporter .setConsoleOutput (true );
8391 junitReporter .setName (CoreReporters .UT_JUNIT_REPORTER .name ());
84- utPLSQLMojo .reporters .add (junitReporter );
92+ utPlsqlMojo .reporters .add (junitReporter );
8593
86- utPLSQLMojo .execute ();
94+ utPlsqlMojo .execute ();
8795
8896 assertTrue (new File ("target/not-exist/junit-report.xml" ).exists ());
8997 }
9098
9199 @ Test
92100 public void onlyFileOutput () throws MojoExecutionException {
101+ UtPlsqlMojo utPlsqlMojo = createUtPlsqlMojo ();
102+
93103 ReporterParameter junitReporter = new ReporterParameter ();
94104 junitReporter .setConsoleOutput (false );
95105 junitReporter .setFileOutput ("not-exist/junit-report.xml" );
96106 junitReporter .setName (CoreReporters .UT_JUNIT_REPORTER .name ());
97- utPLSQLMojo .reporters .add (junitReporter );
107+ utPlsqlMojo .reporters .add (junitReporter );
98108
99- utPLSQLMojo .execute ();
109+ utPlsqlMojo .execute ();
100110
101111 assertTrue (new File ("target/not-exist/junit-report.xml" ).exists ());
102112 }
103113
104114 @ Test
105115 public void skipUtplsqlTests () throws MojoExecutionException {
106- utPLSQLMojo .skipUtplsqlTests = true ;
116+ UtPlsqlMojo utPlsqlMojo = createUtPlsqlMojo ();
117+
118+ utPlsqlMojo .skipUtplsqlTests = true ;
107119
108120 final ByteArrayOutputStream console = new ByteArrayOutputStream ();
109121 System .setOut (new PrintStream (console ));
110122
111- utPLSQLMojo .execute ();
123+ utPlsqlMojo .execute ();
112124
113125 String standardOutput = console .toString ();
114126
@@ -117,10 +129,12 @@ public void skipUtplsqlTests() throws MojoExecutionException {
117129
118130 @ Test
119131 public void defaultReportAndExcludes () throws MojoExecutionException {
120- utPLSQLMojo .excludeObject = "abc" ;
121- utPLSQLMojo .includeObject = "xyz" ;
132+ UtPlsqlMojo utPlsqlMojo = createUtPlsqlMojo ();
133+
134+ utPlsqlMojo .excludeObject = "abc" ;
135+ utPlsqlMojo .includeObject = "xyz" ;
122136
123- utPLSQLMojo .execute ();
137+ utPlsqlMojo .execute ();
124138 }
125139
126140}
0 commit comments