11package edu .luc .cs .consoleapp ;
22
3+ import static org .junit .jupiter .api .Assertions .assertEquals ;
4+
35import java .util .Arrays ;
46import java .util .Collection ;
57import java .util .Collections ;
@@ -16,7 +18,7 @@ public void testInteractiveBehavior() {
1618 // the test input
1719 final var input = List .of ("asdf" , "qwer" , "oiui" , "zxcv" );
1820 // the expected interaction trace
19- final var expectedTrace = List .<TraceEvent >of (
21+ final var expectedTrace = List .<IOEvent >of (
2022 new InputEvent ("asdf" ),
2123 new OutputEvent ("asdf" ),
2224 new InputEvent ("qwer" ),
@@ -31,23 +33,25 @@ public void testInteractiveBehavior() {
3133 sut .process ();
3234 // // make sure the expected and actual traces match
3335 final var actualTrace = sut .getTrace ();
36+ assertEquals (expectedTrace , actualTrace );
3437 }
3538}
3639
3740// A mini-framework for trace-based testing of interactive behavior (WIP)
3841
39- interface TraceEvent {}
42+ /** A common interface for user I/O events. */
43+ interface IOEvent {}
4044
4145/** A trace event representing user input. */
42- record InputEvent (String value ) implements TraceEvent {
46+ record InputEvent (String value ) implements IOEvent {
4347 @ Override
4448 public String toString () {
4549 return "InputEvent(" + value + ")" ;
4650 }
4751}
4852
4953/** A trace event representing system output. */
50- record OutputEvent (List <String > value ) implements TraceEvent {
54+ record OutputEvent (List <String > value ) implements IOEvent {
5155 public OutputEvent (String ... values ) {
5256 this (Arrays .asList (values ));
5357 }
@@ -68,7 +72,7 @@ public String toString() {
6872class SUTWithTracing {
6973 private final SlidingQueue sut ;
7074
71- private final LinkedList <TraceEvent > trace = new LinkedList <>();
75+ private final LinkedList <IOEvent > trace = new LinkedList <>();
7276
7377 SUTWithTracing (final int capacity , final Collection <String > input ) {
7478 this .sut = new SlidingQueue (capacity , wrapInput (input ), outputToTrace ());
@@ -78,7 +82,7 @@ void process() {
7882 sut .process ();
7983 }
8084
81- List <TraceEvent > getTrace () {
85+ List <IOEvent > getTrace () {
8286 return Collections .unmodifiableList (trace );
8387 }
8488
0 commit comments