BAEL-4437 - System Rules (#10047)

Co-authored-by: Jonathan Cook <jcook@sciops.esa.int>
This commit is contained in:
Jonathan Cook
2020-09-17 23:22:49 +02:00
committed by GitHub
parent 4edf9bcfaa
commit 5289ea242b
12 changed files with 288 additions and 1 deletions

View File

@@ -0,0 +1,27 @@
package com.baeldung.systemrules;
import static com.github.stefanbirkner.systemlambda.SystemLambda.withTextFromSystemIn;
import static org.junit.Assert.assertEquals;
import java.util.Scanner;
import org.junit.jupiter.api.Test;
class SystemInUnitTest {
@Test
void givenTwoNames_whenSystemInMock_thenNamesJoinedTogether() throws Exception {
withTextFromSystemIn("Jonathan", "Cook").execute(() -> {
assertEquals("Names should be concatenated", "Jonathan Cook", getFullname());
});
}
private String getFullname() {
try (Scanner scanner = new Scanner(System.in)) {
String firstName = scanner.next();
String surname = scanner.next();
return String.join(" ", firstName, surname);
}
}
}