@@ -74,32 +74,59 @@ void promptForExclusionsKeepsAllWhenInputIsEmpty() {
7474 @ Test
7575 void promptForExclusionsRemovesSome () {
7676 List <String > pkgs = List .of ("nano" , "vim" , "htop" , "curl" );
77- Scanner scanner = new Scanner (new ByteArrayInputStream ("2,4\n " .getBytes (StandardCharsets .UTF_8 )));
77+ Scanner scanner = mock (Scanner .class );
78+ when (scanner .nextLine ()).thenReturn ("2,4\n " );
7879
7980 List <String > result = promptForExclusions (pkgs , scanner );
8081
8182 assertEquals (List .of ("nano" , "htop" ), result );
83+
84+ when (scanner .nextLine ()).thenReturn ("4\n " );
85+ result = promptForExclusions (pkgs , scanner );
86+ assertEquals (List .of ("nano" , "vim" , "htop" ), result );
87+
88+ when (scanner .nextLine ()).thenReturn ("1,3..4\n " );
89+ result = promptForExclusions (pkgs , scanner );
90+ assertEquals (List .of ("vim" ), result );
91+
92+ when (scanner .nextLine ()).thenReturn ("1..3\n " );
93+ result = promptForExclusions (pkgs , scanner );
94+ assertEquals (List .of ("curl" ), result );
95+
96+ when (scanner .nextLine ()).thenReturn ("3..4,2\n " );
97+ result = promptForExclusions (pkgs , scanner );
98+ assertEquals (List .of ("nano" ), result );
8299 }
83100
84101 @ Test
85102 void promptForExclusionsHandlesInvalidIndexes () {
86103 List <String > pkgs = List .of ("pkg1" , "pkg2" , "pkg3" );
87- Scanner scanner = new Scanner (new ByteArrayInputStream ("0,5,2\n " .getBytes (StandardCharsets .UTF_8 )));
104+ Scanner scanner = mock (Scanner .class );
105+ when (scanner .nextLine ()).thenReturn ("0,5,2\n " );
88106
89107 List <String > result = promptForExclusions (pkgs , scanner );
90108
91109 assertEquals (List .of ("pkg1" , "pkg3" ), result );
110+
111+ when (scanner .nextLine ()).thenReturn ("0..1\n " );
112+ result = promptForExclusions (pkgs , scanner );
113+ assertEquals (pkgs , result );
114+
115+ when (scanner .nextLine ()).thenReturn ("1..99\n " );
116+ result = promptForExclusions (pkgs , scanner );
117+ assertEquals (pkgs , result );
92118 }
93119
94120 @ ParameterizedTest
95121 @ ValueSource (strings = {
96- "1,,3" , // multiple consecutive commas
97- "1,3," , // trailing comma
98- ",1,3" , // leading comma
99- "1a,2" , // invalid characters mixed with valid numbers
100- "1,abc,2" , // non-numeric characters
101- "qwerty" , // completely non-numeric input
102- "!@#, $%^, &*()" // special characters
122+ "1,,3" , // multiple consecutive commas
123+ "1,3," , // trailing comma
124+ ",1,3" , // leading comma
125+ "1a,2" , "3, 5" , // invalid characters mixed with valid numbers
126+ "1,abc,2" , // non-numeric characters
127+ "qwerty" , // completely non-numeric input
128+ "!@#, $%^, &*()" , // special characters
129+ "1.54" , "1...54" , "6.-.12" // malformed range
103130 })
104131 void promptForExclusionsThrowsRuntimeExceptionWhenInvalidInputRead (String input ) {
105132 List <String > pkgs = List .of ("pkg" );
0 commit comments