1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-17 18:02:05 +01:00

Add test for PGPainlessCLI main class

This commit is contained in:
Paul Schaub 2021-05-29 14:03:27 +02:00
parent 82536eaa77
commit af6fe0aaf7
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -0,0 +1,50 @@
/*
* Copyright 2021 Paul Schaub.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pgpainless.sop;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
public class MainClassTest {
private static OutputStream originalSout;
@BeforeAll
public static void saveOriginalSout() {
originalSout = System.out;
}
@Test
public void testMainByVersionCommand() {
ByteArrayOutputStream out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));
PGPainlessCLI.main(new String[] {"version"});
String version = out.toString();
assertTrue(version.startsWith("PGPainlessCLI"));
}
@AfterAll
public static void restoreOriginalSout() {
System.setOut(new PrintStream(originalSout));
}
}