55package io .flutter .plugins .videoplayer ;
66
77import static org .junit .Assert .assertEquals ;
8- import static org .mockito .Mockito .any ;
98import static org .mockito .Mockito .mock ;
10- import static org .mockito .Mockito .never ;
11- import static org .mockito .Mockito .spy ;
129import static org .mockito .Mockito .verify ;
1310import static org .mockito .Mockito .when ;
1411
1512import com .google .android .exoplayer2 .ExoPlayer ;
1613import com .google .android .exoplayer2 .Format ;
17- import com .google .android .exoplayer2 .upstream .DefaultHttpDataSource ;
1814import io .flutter .plugin .common .EventChannel ;
1915import io .flutter .view .TextureRegistry ;
2016import java .util .HashMap ;
21- import java .util .Map ;
2217import org .junit .Before ;
2318import org .junit .Test ;
2419import org .junit .runner .RunWith ;
@@ -34,7 +29,6 @@ public class VideoPlayerTest {
3429 private TextureRegistry .SurfaceTextureEntry fakeSurfaceTextureEntry ;
3530 private VideoPlayerOptions fakeVideoPlayerOptions ;
3631 private QueuingEventSink fakeEventSink ;
37- private DefaultHttpDataSource .Factory httpDataSourceFactorySpy ;
3832
3933 @ Captor private ArgumentCaptor <HashMap <String , Object >> eventCaptor ;
4034
@@ -47,76 +41,6 @@ public void before() {
4741 fakeSurfaceTextureEntry = mock (TextureRegistry .SurfaceTextureEntry .class );
4842 fakeVideoPlayerOptions = mock (VideoPlayerOptions .class );
4943 fakeEventSink = mock (QueuingEventSink .class );
50- httpDataSourceFactorySpy = spy (new DefaultHttpDataSource .Factory ());
51- }
52-
53- @ Test
54- public void videoPlayer_buildsHttpDataSourceFactoryProperlyWhenHttpHeadersNull () {
55- VideoPlayer videoPlayer =
56- new VideoPlayer (
57- fakeExoPlayer ,
58- fakeEventChannel ,
59- fakeSurfaceTextureEntry ,
60- fakeVideoPlayerOptions ,
61- fakeEventSink ,
62- httpDataSourceFactorySpy );
63-
64- videoPlayer .buildHttpDataSourceFactory (new HashMap <>());
65-
66- verify (httpDataSourceFactorySpy ).setUserAgent ("ExoPlayer" );
67- verify (httpDataSourceFactorySpy ).setAllowCrossProtocolRedirects (true );
68- verify (httpDataSourceFactorySpy , never ()).setDefaultRequestProperties (any ());
69- }
70-
71- @ Test
72- public void
73- videoPlayer_buildsHttpDataSourceFactoryProperlyWhenHttpHeadersNonNullAndUserAgentSpecified () {
74- VideoPlayer videoPlayer =
75- new VideoPlayer (
76- fakeExoPlayer ,
77- fakeEventChannel ,
78- fakeSurfaceTextureEntry ,
79- fakeVideoPlayerOptions ,
80- fakeEventSink ,
81- httpDataSourceFactorySpy );
82- Map <String , String > httpHeaders =
83- new HashMap <String , String >() {
84- {
85- put ("header" , "value" );
86- put ("User-Agent" , "userAgent" );
87- }
88- };
89-
90- videoPlayer .buildHttpDataSourceFactory (httpHeaders );
91-
92- verify (httpDataSourceFactorySpy ).setUserAgent ("userAgent" );
93- verify (httpDataSourceFactorySpy ).setAllowCrossProtocolRedirects (true );
94- verify (httpDataSourceFactorySpy ).setDefaultRequestProperties (httpHeaders );
95- }
96-
97- @ Test
98- public void
99- videoPlayer_buildsHttpDataSourceFactoryProperlyWhenHttpHeadersNonNullAndUserAgentNotSpecified () {
100- VideoPlayer videoPlayer =
101- new VideoPlayer (
102- fakeExoPlayer ,
103- fakeEventChannel ,
104- fakeSurfaceTextureEntry ,
105- fakeVideoPlayerOptions ,
106- fakeEventSink ,
107- httpDataSourceFactorySpy );
108- Map <String , String > httpHeaders =
109- new HashMap <String , String >() {
110- {
111- put ("header" , "value" );
112- }
113- };
114-
115- videoPlayer .buildHttpDataSourceFactory (httpHeaders );
116-
117- verify (httpDataSourceFactorySpy ).setUserAgent ("ExoPlayer" );
118- verify (httpDataSourceFactorySpy ).setAllowCrossProtocolRedirects (true );
119- verify (httpDataSourceFactorySpy ).setDefaultRequestProperties (httpHeaders );
12044 }
12145
12246 @ Test
@@ -127,8 +51,7 @@ public void sendInitializedSendsExpectedEvent_90RotationDegrees() {
12751 fakeEventChannel ,
12852 fakeSurfaceTextureEntry ,
12953 fakeVideoPlayerOptions ,
130- fakeEventSink ,
131- httpDataSourceFactorySpy );
54+ fakeEventSink );
13255 Format testFormat =
13356 new Format .Builder ().setWidth (100 ).setHeight (200 ).setRotationDegrees (90 ).build ();
13457
@@ -156,8 +79,7 @@ public void sendInitializedSendsExpectedEvent_270RotationDegrees() {
15679 fakeEventChannel ,
15780 fakeSurfaceTextureEntry ,
15881 fakeVideoPlayerOptions ,
159- fakeEventSink ,
160- httpDataSourceFactorySpy );
82+ fakeEventSink );
16183 Format testFormat =
16284 new Format .Builder ().setWidth (100 ).setHeight (200 ).setRotationDegrees (270 ).build ();
16385
@@ -185,8 +107,7 @@ public void sendInitializedSendsExpectedEvent_0RotationDegrees() {
185107 fakeEventChannel ,
186108 fakeSurfaceTextureEntry ,
187109 fakeVideoPlayerOptions ,
188- fakeEventSink ,
189- httpDataSourceFactorySpy );
110+ fakeEventSink );
190111 Format testFormat =
191112 new Format .Builder ().setWidth (100 ).setHeight (200 ).setRotationDegrees (0 ).build ();
192113
@@ -214,8 +135,7 @@ public void sendInitializedSendsExpectedEvent_180RotationDegrees() {
214135 fakeEventChannel ,
215136 fakeSurfaceTextureEntry ,
216137 fakeVideoPlayerOptions ,
217- fakeEventSink ,
218- httpDataSourceFactorySpy );
138+ fakeEventSink );
219139 Format testFormat =
220140 new Format .Builder ().setWidth (100 ).setHeight (200 ).setRotationDegrees (180 ).build ();
221141
0 commit comments