"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "platform-tests/src/test/java/org/junit/platform/console/ConsoleLauncherTests.java" between
junit5-r5.3.2.tar.gz and junit5-r5.4.0.tar.gz

About: JUnit 5 is a unit testing framework for the Java programming language.

ConsoleLauncherTests.java  (junit5-r5.3.2):ConsoleLauncherTests.java  (junit5-r5.4.0)
/* /*
* Copyright 2015-2018 the original author or authors. * Copyright 2015-2019 the original author or authors.
* *
* All rights reserved. This program and the accompanying materials are * All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v2.0 which * made available under the terms of the Eclipse Public License v2.0 which
* accompanies this distribution and is available at * accompanies this distribution and is available at
* *
* http://www.eclipse.org/legal/epl-v20.html * http://www.eclipse.org/legal/epl-v20.html
*/ */
package org.junit.platform.console; package org.junit.platform.console;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertLinesMatch;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.platform.console.options.CommandLineOptions; import org.junit.platform.console.options.CommandLineOptions;
import org.junit.platform.console.options.CommandLineOptionsParser; import org.junit.platform.console.options.CommandLineOptionsParser;
/** /**
* @since 1.0 * @since 1.0
*/ */
class ConsoleLauncherTests { class ConsoleLauncherTests {
private final PrintStream printSink = new PrintStream(new ByteArrayOutput private final ByteArrayOutputStream printedBytes = new ByteArrayOutputStr
Stream()); eam(1000);
private final PrintStream printSink = new PrintStream(printedBytes);
@Test @Test
void displayHelp() { void displayHelp() {
CommandLineOptions options = new CommandLineOptions(); CommandLineOptions options = new CommandLineOptions();
options.setDisplayHelp(true); options.setDisplayHelp(true);
CommandLineOptionsParser commandLineOptionsParser = mock(CommandL ineOptionsParser.class); CommandLineOptionsParser commandLineOptionsParser = mock(CommandL ineOptionsParser.class);
when(commandLineOptionsParser.parse(any())).thenReturn(options); when(commandLineOptionsParser.parse(any())).thenReturn(options);
ConsoleLauncher consoleLauncher = new ConsoleLauncher(commandLine OptionsParser, printSink, printSink); ConsoleLauncher consoleLauncher = new ConsoleLauncher(commandLine OptionsParser, printSink, printSink);
int exitCode = consoleLauncher.execute("--help").getExitCode(); int exitCode = consoleLauncher.execute("--help").getExitCode();
assertEquals(0, exitCode); assertEquals(0, exitCode);
verify(commandLineOptionsParser).parse("--help"); verify(commandLineOptionsParser).parse("--help");
} }
@Test @Test
void displayBanner() {
CommandLineOptions options = new CommandLineOptions();
options.setBannerDisabled(false);
options.setDisplayHelp(true);
CommandLineOptionsParser commandLineOptionsParser = mock(CommandL
ineOptionsParser.class);
when(commandLineOptionsParser.parse(any())).thenReturn(options);
ConsoleLauncher consoleLauncher = new ConsoleLauncher(commandLine
OptionsParser, printSink, printSink);
int exitCode = consoleLauncher.execute("--help").getExitCode();
assertEquals(0, exitCode);
assertLinesMatch(
List.of("", "Thanks for using JUnit! Support its developm
ent at https://junit.org/sponsoring", ""),
printedBytes.toString().lines().collect(Collectors.toList
()));
}
@Test
void disableBanner() {
CommandLineOptions options = new CommandLineOptions();
options.setBannerDisabled(true);
options.setDisplayHelp(true);
CommandLineOptionsParser commandLineOptionsParser = mock(CommandL
ineOptionsParser.class);
when(commandLineOptionsParser.parse(any())).thenReturn(options);
ConsoleLauncher consoleLauncher = new ConsoleLauncher(commandLine
OptionsParser, printSink, printSink);
int exitCode = consoleLauncher.execute("--help", "--disable-banne
r").getExitCode();
assertEquals(0, exitCode);
assertLinesMatch(List.of(), printedBytes.toString().lines().colle
ct(Collectors.toList()));
}
@Test
void executeWithUnknownCommandLineOption() { void executeWithUnknownCommandLineOption() {
CommandLineOptionsParser commandLineOptionsParser = mock(CommandL ineOptionsParser.class); CommandLineOptionsParser commandLineOptionsParser = mock(CommandL ineOptionsParser.class);
when(commandLineOptionsParser.parse(any())).thenReturn(new Comman dLineOptions()); when(commandLineOptionsParser.parse(any())).thenReturn(new Comman dLineOptions());
ConsoleLauncher consoleLauncher = new ConsoleLauncher(commandLine OptionsParser, printSink, printSink); ConsoleLauncher consoleLauncher = new ConsoleLauncher(commandLine OptionsParser, printSink, printSink);
int exitCode = consoleLauncher.execute("--all").getExitCode(); int exitCode = consoleLauncher.execute("--all").getExitCode();
assertEquals(-1, exitCode); assertEquals(-1, exitCode);
verify(commandLineOptionsParser).parse("--all"); verify(commandLineOptionsParser).parse("--all");
} }
 End of changes. 5 change blocks. 
3 lines changed or deleted 49 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)