Skip to content

Commit

Permalink
Simplify assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
sormuras committed Aug 18, 2023
1 parent a034d97 commit cd2a133
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.nio.charset.Charset;

import org.apiguardian.api.API;
import org.junit.platform.commons.JUnitException;

/**
* Collection of utilities for working with {@code java.io.Console}
Expand All @@ -38,19 +37,7 @@ public class ConsoleUtils {
*/
public static Charset charset() {
Console console = System.console();
return console != null && isTerminal(console) ? console.charset() : Charset.defaultCharset();
return console != null ? console.charset() : Charset.defaultCharset();
}

private static boolean isTerminal(Console console) {
try {
//noinspection JavaReflectionMemberAccess
return (boolean) Console.class.getDeclaredMethod("isTerminal").invoke(console);
}
catch (NoSuchMethodException exception) {
return false; // Console::isTerminal was introduced in Java 22
}
catch (ReflectiveOperationException exception) {
throw new JUnitException("Failed to call Console.isTerminal()", exception);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ void displayBanner(String command) {
var consoleLauncher = new ConsoleLauncher(ConsoleTestExecutor::new, printSink, printSink);
consoleLauncher.run(command);

assertThat(stringWriter.toString()).contains(
"Thanks for using JUnit! Support its development at https://junit.org/sponsoring");
var actual = stringWriter.toString();
assertThat(actual).contains("Thanks for using JUnit!");
}

@ParameterizedTest(name = "{0}")
Expand Down

0 comments on commit cd2a133

Please sign in to comment.