1+ package pl .mperor .lab .common ;
2+
3+ import org .junit .jupiter .api .Assertions ;
4+ import org .junit .jupiter .api .Test ;
5+
6+ import java .util .NoSuchElementException ;
7+ import java .util .stream .Stream ;
8+
9+ class UtilsTest {
10+
11+ @ Test
12+ public void testReadableOutputReturnsReadableList () {
13+ var out = TestUtils .setTempSystemOut ();
14+ Stream .of ("One" , "Two" , "Three" )
15+ .forEach (System .out ::println );
16+ var readableList = out .lines ();
17+ Assertions .assertEquals ("One" , readableList .getFirst ());
18+ Assertions .assertEquals ("Two" , readableList .getSecond ());
19+ Assertions .assertEquals ("Three" , readableList .getThird ());
20+ TestUtils .resetSystemOut ();
21+ }
22+
23+ @ Test
24+ public void testNoOutPrintsReturnsEmptyReadableList () {
25+ var out = TestUtils .setTempSystemOut ();
26+ var readableList = out .lines ();
27+ Assertions .assertThrows (NoSuchElementException .class , () -> readableList .getFirst ());
28+ Assertions .assertThrows (NoSuchElementException .class , () -> readableList .getSecond ());
29+ Assertions .assertThrows (NoSuchElementException .class , () -> readableList .getThird ());
30+ Assertions .assertEquals ("" , out .all ());
31+ TestUtils .resetSystemOut ();
32+ }
33+
34+ }
0 commit comments