From af6fe0aaf709b9dda290f3d72f618b736db5c762 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Sat, 29 May 2021 14:03:27 +0200 Subject: [PATCH] Add test for PGPainlessCLI main class --- .../org/pgpainless/sop/MainClassTest.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 pgpainless-sop/src/test/java/org/pgpainless/sop/MainClassTest.java diff --git a/pgpainless-sop/src/test/java/org/pgpainless/sop/MainClassTest.java b/pgpainless-sop/src/test/java/org/pgpainless/sop/MainClassTest.java new file mode 100644 index 00000000..9c86ee9e --- /dev/null +++ b/pgpainless-sop/src/test/java/org/pgpainless/sop/MainClassTest.java @@ -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)); + } +}