File tree Expand file tree Collapse file tree
core-java-modules/core-java-io-4/src/test/java/com/baeldung/scanner Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .baeldung .scanner ;
2+
3+ import org .junit .Test ;
4+
5+ import java .util .*;
6+ import java .util .regex .*;
7+
8+ import static org .junit .jupiter .api .Assertions .assertEquals ;
9+
10+ public class ScannerUnitTest {
11+ @ Test public void scannerSkipUsingPattern () {
12+ String str = "Java scanner skip tutorial" ;
13+ // Instantiates Scanner
14+ Scanner sc = new Scanner (str );
15+ // By using skip(Pattern) method is to skip that meets the given pattern
16+ sc .skip (Pattern .compile (".ava" ));
17+ assertEquals (sc .nextLine (), " scanner skip tutorial" );
18+ // Scanner closed
19+ sc .close ();
20+ }
21+
22+ @ Test public void scannerSkipUsingStringPattern () {
23+ String str = "Java scanner skip tutorial" ;
24+ // Instantiates Scanner
25+ Scanner sc = new Scanner (str );
26+ // By using skip(String) method is to skip that meets the given
27+ // pattern constructed from the given String
28+ sc .skip ("Java" );
29+ assertEquals (sc .nextLine (), " scanner skip tutorial" );
30+
31+ // Scanner closed
32+ sc .close ();
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments