BAEL-4623: Add a new section for Scanner article (#12453)
This commit is contained in:
parent
e33334d246
commit
44f273b735
|
@ -1,12 +1,21 @@
|
||||||
package com.baeldung.scanner;
|
package com.baeldung.scanner;
|
||||||
|
|
||||||
import org.junit.Test;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class JavaScannerUnitTest {
|
public class JavaScannerUnitTest {
|
||||||
|
|
||||||
|
@ -175,4 +184,17 @@ public class JavaScannerUnitTest {
|
||||||
scanner.close();
|
scanner.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected = NoSuchElementException.class)
|
||||||
|
public void givenClosingScanner_whenReading_thenThrowException() throws IOException {
|
||||||
|
final FileInputStream inputStream = new FileInputStream("src/test/resources/test_read.in");
|
||||||
|
|
||||||
|
final Scanner scanner = new Scanner(inputStream);
|
||||||
|
scanner.next();
|
||||||
|
scanner.close();
|
||||||
|
|
||||||
|
final Scanner scanner2 = new Scanner(inputStream);
|
||||||
|
scanner2.next();
|
||||||
|
scanner2.close();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue