Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests that lock down current scanner behaviour with home-made stream #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,45 @@ void system_in_throws_requested_IOException_on_first_read_if_no_text_has_been_sp
});
}

@Test
void scanner_can_read_all_lines_when_exception_at_end(
) throws Exception {
withTextFromSystemIn("arbitrary", "text")
.andExceptionThrownOnInputEnd(DUMMY_IO_EXCEPTION)
.execute(() -> {
Scanner scanner = new Scanner(System.in);
scanner.nextLine();
scanner.nextLine();
});
}

@Test
void scanner_cannot_read_beyond_last_line(
) throws Exception {
withTextFromSystemIn("arbitrary", "text")
.execute(() -> {
Scanner scanner = new Scanner(System.in);
scanner.nextLine();
scanner.nextLine();
Throwable exception = exceptionThrownBy(scanner::nextLine);
assertThat(exception).hasMessage("No line found");
});
}

@Test
void scanner_fails_with_thrown_exception_when_exception_at_end(
) throws Exception {
withTextFromSystemIn("arbitrary", "text")
.andExceptionThrownOnInputEnd(DUMMY_RUNTIME_EXCEPTION)
.execute(() -> {
Scanner scanner = new Scanner(System.in);
scanner.nextLine();
scanner.nextLine();
Throwable exception = exceptionThrownBy(scanner::nextLine);
assertThat(exception).isSameAs(DUMMY_RUNTIME_EXCEPTION);
});
}

@Test
void system_in_provides_specified_text_and_throws_requested_RuntimeException_afterwards(
) throws Exception {
Expand Down