1616
1717package org .springframework .boot .ansi ;
1818
19+ import java .util .stream .Stream ;
20+
1921import org .junit .jupiter .api .AfterAll ;
2022import org .junit .jupiter .api .BeforeAll ;
2123import org .junit .jupiter .api .Test ;
24+ import org .junit .jupiter .params .ParameterizedTest ;
25+ import org .junit .jupiter .params .provider .Arguments ;
26+ import org .junit .jupiter .params .provider .MethodSource ;
2227
2328import org .springframework .boot .ansi .AnsiOutput .Enabled ;
2429
2530import static org .assertj .core .api .Assertions .assertThat ;
31+ import static org .junit .jupiter .api .Assertions .assertEquals ;
2632
2733/**
2834 * Tests for {@link AnsiOutput}.
2935 *
3036 * @author Phillip Webb
37+ * @author Philemon Hilscher
3138 */
3239class AnsiOutputTests {
3340
@@ -48,4 +55,42 @@ void encoding() {
4855 assertThat (encoded ).isEqualTo ("A[31;1mB[0mD[32mE[2mF[0;39m" );
4956 }
5057
58+ private static Stream <Arguments > provideOsNames () {
59+ return Stream .of (
60+ Arguments .of ("" , false ),
61+ Arguments .of ("Windows 7" , true ),
62+ Arguments .of ("Windows 8" , true ),
63+ Arguments .of ("Windows 8.1" , true ),
64+ Arguments .of ("Windows 10" , true ),
65+ Arguments .of ("Windows 11" , true ),
66+ Arguments .of ("Linux" , false ),
67+ Arguments .of ("Mac OS X" , false ),
68+ Arguments .of ("Mac OS" , false )
69+ );
70+ }
71+
72+ @ ParameterizedTest
73+ @ MethodSource ("provideOsNames" )
74+ void testDetectIfIsWindows (String osName , boolean expected ) {
75+ boolean actual = AnsiOutput .isWindows (osName );
76+ assertEquals (expected , actual );
77+ }
78+
79+ private static Stream <Arguments > provideOsVersionNumbers () {
80+ return Stream .of (
81+ Arguments .of ("" , false ),
82+ Arguments .of ("6.1" , false ), // Windows 7 / Server 2008 R2
83+ Arguments .of ("6.2" , false ), // Windows 8 / Server 2012
84+ Arguments .of ("6.3" , false ), // Windows 8.1 / Server 2012 R2
85+ Arguments .of ("10.0" , true ) // Windows 10 / 11 / Server 2016+
86+ );
87+ }
88+
89+ @ ParameterizedTest
90+ @ MethodSource ("provideOsVersionNumbers" )
91+ void testDetectIfIsWindowsAnsiCapable (String osVersion , boolean expected ) {
92+ boolean actual = AnsiOutput .isWindowsAnsiCapable (osVersion );
93+ assertEquals (expected , actual );
94+ }
95+
5196}
0 commit comments