2727
2828import java .util .ArrayList ;
2929import java .util .Arrays ;
30+ import java .util .Collections ;
31+ import java .util .List ;
3032import java .util .Optional ;
3133
3234/**
3840@ DisplayName ("测试 TextStreamChoir" )
3941class TextStreamChoirTest {
4042 private static class TestSubscriber <T > extends EmptySubscriber <T > {
41- private final ArrayList <String > records ;
43+ private final List <String > records ;
4244
43- public TestSubscriber (ArrayList <String > records ) {
45+ public TestSubscriber (List <String > records ) {
4446 this .records = records ;
4547 }
4648
@@ -95,7 +97,7 @@ void shouldReturnDataAndCompleteWhenDataEmittedBeforeSubscribeCompleted() {
9597 stringEmitter .complete ();
9698 });
9799 TextStreamChoir <String > textStreamChoir = createStringTextStreamChoir (convertedChoir , 200 );
98- ArrayList <String > records = new ArrayList <>();
100+ List <String > records = Collections . synchronizedList ( new ArrayList <>() );
99101 Subscriber <String > mySubscriber = new TestSubscriber <>(records );
100102 textStreamChoir .subscribe (mySubscriber );
101103 records .add ("after subscribe" );
@@ -112,7 +114,7 @@ void shouldReturnDataAndCompleteWhenDataEmittedAfterSubscribeCompleted() {
112114 Emitter <String > emitter = new DefaultEmitter <>();
113115 Choir <String > convertedChoir = Choir .fromEmitter (emitter );
114116 TextStreamChoir <String > textStreamChoir = createStringTextStreamChoir (convertedChoir , 200 );
115- ArrayList <String > records = new ArrayList <>();
117+ List <String > records = Collections . synchronizedList ( new ArrayList <>() );
116118 Subscriber <String > mySubscriber = new TestSubscriber <>(records );
117119 textStreamChoir .subscribe (mySubscriber );
118120 records .add ("after subscribe" );
@@ -140,7 +142,7 @@ void shouldReturnDataAndCompleteWhenDataEmittedAfterSubscribeCompletedWithNewThr
140142 }).start ();
141143 });
142144 TextStreamChoir <String > textStreamChoir = createStringTextStreamChoir (convertedChoir , 200 );
143- ArrayList <String > records = new ArrayList <>();
145+ List <String > records = Collections . synchronizedList ( new ArrayList <>() );
144146 Subscriber <String > mySubscriber = new TestSubscriber <>(records );
145147 textStreamChoir .subscribe (mySubscriber );
146148 records .add ("after subscribe" );
@@ -164,7 +166,7 @@ void shouldReturnDataAndFailWhenHttpExchangeFailAndChoirCreateByCreate() {
164166 stringEmitter .complete ();
165167 });
166168 TextStreamChoir <String > textStreamChoir = createStringTextStreamChoir (convertedChoir , 500 );
167- ArrayList <String > records = new ArrayList <>();
169+ List <String > records = Collections . synchronizedList ( new ArrayList <>() );
168170 Subscriber <String > mySubscriber = new TestSubscriber <>(records );
169171 textStreamChoir .subscribe (mySubscriber );
170172 records .add ("after subscribe" );
@@ -177,7 +179,7 @@ void shouldReturnDataAndFailWhenHttpExchangeFailAndChoirCreateByFromEmitter() {
177179 Emitter <String > emitter = new DefaultEmitter <>();
178180 Choir <String > convertedChoir = Choir .fromEmitter (emitter );
179181 TextStreamChoir <String > textStreamChoir = createStringTextStreamChoir (convertedChoir , 400 );
180- ArrayList <String > records = new ArrayList <>();
182+ List <String > records = Collections . synchronizedList ( new ArrayList <>() );
181183 Subscriber <String > mySubscriber = new TestSubscriber <>(records );
182184 textStreamChoir .subscribe (mySubscriber );
183185 records .add ("after subscribe" );
@@ -194,7 +196,7 @@ void shouldReturnDataAndFailWhenDataEmittedBeforeSubscribeCompleted() {
194196 stringEmitter .fail (new RuntimeException ("" ));
195197 });
196198 TextStreamChoir <String > textStreamChoir = createStringTextStreamChoir (convertedChoir , 200 );
197- ArrayList <String > records = new ArrayList <>();
199+ List <String > records = Collections . synchronizedList ( new ArrayList <>() );
198200 Subscriber <String > mySubscriber = new TestSubscriber <>(records );
199201 textStreamChoir .subscribe (mySubscriber );
200202 records .add ("after subscribe" );
@@ -211,7 +213,7 @@ void shouldReturnDataAndFailWhenDataEmittedAfterSubscribeCompleted() {
211213 Emitter <String > emitter = new DefaultEmitter <>();
212214 Choir <String > convertedChoir = Choir .fromEmitter (emitter );
213215 TextStreamChoir <String > textStreamChoir = createStringTextStreamChoir (convertedChoir , 200 );
214- ArrayList <String > records = new ArrayList <>();
216+ List <String > records = Collections . synchronizedList ( new ArrayList <>() );
215217 Subscriber <String > mySubscriber = new TestSubscriber <>(records );
216218 textStreamChoir .subscribe (mySubscriber );
217219 records .add ("after subscribe" );
@@ -239,7 +241,7 @@ void shouldReturnDataAndFailWhenDataEmittedAfterSubscribeCompletedWithNewThread(
239241 }).start ();
240242 });
241243 TextStreamChoir <String > textStreamChoir = createStringTextStreamChoir (convertedChoir , 200 );
242- ArrayList <String > records = new ArrayList <>();
244+ List <String > records = Collections . synchronizedList ( new ArrayList <>() );
243245 Subscriber <String > mySubscriber = new TestSubscriber <>(records );
244246 textStreamChoir .subscribe (mySubscriber );
245247 records .add ("after subscribe" );
0 commit comments