2222import org .junit .Before ;
2323import org .junit .Test ;
2424import org .junit .runner .RunWith ;
25- import org .mockito .Matchers ;
25+ import org .mockito .ArgumentMatchers ;
2626import org .mockito .Mock ;
2727import org .mockito .invocation .InvocationOnMock ;
2828import org .mockito .junit .MockitoJUnitRunner ;
@@ -72,23 +72,25 @@ public void processWithLengthAndMetadata() throws Exception {
7272 servletRequest .addHeader (HttpHeader .UPLOAD_METADATA , "encoded-metadata" );
7373
7474 final UUID id = UUID .randomUUID ();
75- when (uploadStorageService .create (Matchers .any (UploadInfo .class ), nullable (String .class ))).then (new Answer <UploadInfo >() {
76- @ Override
77- public UploadInfo answer (InvocationOnMock invocation ) throws Throwable {
78- UploadInfo upload = invocation .getArgument (0 );
79- assertThat (upload .getLength (), is (10L ));
80- assertThat (upload .getEncodedMetadata (), is ("encoded-metadata" ));
75+ when (uploadStorageService .create (ArgumentMatchers .any (UploadInfo .class ), nullable (String .class ))).then (
76+ new Answer <UploadInfo >() {
77+ @ Override
78+ public UploadInfo answer (InvocationOnMock invocation ) throws Throwable {
79+ UploadInfo upload = invocation .getArgument (0 );
80+ assertThat (upload .getLength (), is (10L ));
81+ assertThat (upload .getEncodedMetadata (), is ("encoded-metadata" ));
8182
82- upload .setId (id );
83+ upload .setId (id );
8384
84- return upload ;
85- }
86- });
85+ return upload ;
86+ }
87+ });
8788
8889 handler .process (HttpMethod .POST , new TusServletRequest (servletRequest ),
8990 new TusServletResponse (servletResponse ), uploadStorageService , null );
9091
91- verify (uploadStorageService , times (1 )).create (Matchers .any (UploadInfo .class ), nullable (String .class ));
92+ verify (uploadStorageService , times (1 )).create (ArgumentMatchers .any (UploadInfo .class ),
93+ nullable (String .class ));
9294 assertThat (servletResponse .getHeader (HttpHeader .LOCATION ), endsWith ("/test/upload/" + id .toString ()));
9395 assertThat (servletResponse .getStatus (), is (HttpServletResponse .SC_CREATED ));
9496 }
@@ -100,23 +102,25 @@ public void processWithLengthAndNoMetadata() throws Exception {
100102 //servletRequest.addHeader(HttpHeader.UPLOAD_METADATA, null);
101103
102104 final UUID id = UUID .randomUUID ();
103- when (uploadStorageService .create (Matchers .any (UploadInfo .class ), nullable (String .class ))).then (new Answer <UploadInfo >() {
104- @ Override
105- public UploadInfo answer (InvocationOnMock invocation ) throws Throwable {
106- UploadInfo upload = invocation .getArgument (0 );
107- assertThat (upload .getLength (), is (10L ));
108- assertThat (upload .getEncodedMetadata (), is (nullValue ()));
105+ when (uploadStorageService .create (ArgumentMatchers .any (UploadInfo .class ), nullable (String .class ))).then (
106+ new Answer <UploadInfo >() {
107+ @ Override
108+ public UploadInfo answer (InvocationOnMock invocation ) throws Throwable {
109+ UploadInfo upload = invocation .getArgument (0 );
110+ assertThat (upload .getLength (), is (10L ));
111+ assertThat (upload .getEncodedMetadata (), is (nullValue ()));
109112
110- upload .setId (id );
113+ upload .setId (id );
111114
112- return upload ;
113- }
114- });
115+ return upload ;
116+ }
117+ });
115118
116119 handler .process (HttpMethod .POST , new TusServletRequest (servletRequest ),
117120 new TusServletResponse (servletResponse ), uploadStorageService , null );
118121
119- verify (uploadStorageService , times (1 )).create (Matchers .any (UploadInfo .class ), nullable (String .class ));
122+ verify (uploadStorageService , times (1 )).create (ArgumentMatchers .any (UploadInfo .class ),
123+ nullable (String .class ));
120124 assertThat (servletResponse .getHeader (HttpHeader .LOCATION ), endsWith ("/test/upload/" + id .toString ()));
121125 assertThat (servletResponse .getStatus (), is (HttpServletResponse .SC_CREATED ));
122126 }
@@ -128,23 +132,25 @@ public void processWithNoLengthAndMetadata() throws Exception {
128132 servletRequest .addHeader (HttpHeader .UPLOAD_METADATA , "encoded-metadata" );
129133
130134 final UUID id = UUID .randomUUID ();
131- when (uploadStorageService .create (Matchers .any (UploadInfo .class ), nullable (String .class ))).then (new Answer <UploadInfo >() {
132- @ Override
133- public UploadInfo answer (InvocationOnMock invocation ) throws Throwable {
134- UploadInfo upload = invocation .getArgument (0 );
135- assertThat (upload .getLength (), is (nullValue ()));
136- assertThat (upload .getEncodedMetadata (), is ("encoded-metadata" ));
135+ when (uploadStorageService .create (ArgumentMatchers .any (UploadInfo .class ), nullable (String .class ))).then (
136+ new Answer <UploadInfo >() {
137+ @ Override
138+ public UploadInfo answer (InvocationOnMock invocation ) throws Throwable {
139+ UploadInfo upload = invocation .getArgument (0 );
140+ assertThat (upload .getLength (), is (nullValue ()));
141+ assertThat (upload .getEncodedMetadata (), is ("encoded-metadata" ));
137142
138- upload .setId (id );
143+ upload .setId (id );
139144
140- return upload ;
141- }
142- });
145+ return upload ;
146+ }
147+ });
143148
144149 handler .process (HttpMethod .POST , new TusServletRequest (servletRequest ),
145150 new TusServletResponse (servletResponse ), uploadStorageService , null );
146151
147- verify (uploadStorageService , times (1 )).create (Matchers .any (UploadInfo .class ), nullable (String .class ));
152+ verify (uploadStorageService , times (1 )).create (ArgumentMatchers .any (UploadInfo .class ),
153+ nullable (String .class ));
148154 assertThat (servletResponse .getHeader (HttpHeader .LOCATION ), endsWith ("/test/upload/" + id .toString ()));
149155 assertThat (servletResponse .getStatus (), is (HttpServletResponse .SC_CREATED ));
150156 }
@@ -156,23 +162,25 @@ public void processWithNoLengthAndNoMetadata() throws Exception {
156162 //servletRequest.addHeader(HttpHeader.UPLOAD_METADATA, null);
157163
158164 final UUID id = UUID .randomUUID ();
159- when (uploadStorageService .create (Matchers .any (UploadInfo .class ), nullable (String .class ))).then (new Answer <UploadInfo >() {
160- @ Override
161- public UploadInfo answer (InvocationOnMock invocation ) throws Throwable {
162- UploadInfo upload = invocation .getArgument (0 );
163- assertThat (upload .getLength (), is (nullValue ()));
164- assertThat (upload .getEncodedMetadata (), is (nullValue ()));
165+ when (uploadStorageService .create (ArgumentMatchers .any (UploadInfo .class ), nullable (String .class ))).then (
166+ new Answer <UploadInfo >() {
167+ @ Override
168+ public UploadInfo answer (InvocationOnMock invocation ) throws Throwable {
169+ UploadInfo upload = invocation .getArgument (0 );
170+ assertThat (upload .getLength (), is (nullValue ()));
171+ assertThat (upload .getEncodedMetadata (), is (nullValue ()));
165172
166- upload .setId (id );
173+ upload .setId (id );
167174
168- return upload ;
169- }
170- });
175+ return upload ;
176+ }
177+ });
171178
172179 handler .process (HttpMethod .POST , new TusServletRequest (servletRequest ),
173180 new TusServletResponse (servletResponse ), uploadStorageService , null );
174181
175- verify (uploadStorageService , times (1 )).create (Matchers .any (UploadInfo .class ), nullable (String .class ));
182+ verify (uploadStorageService , times (1 )).create (ArgumentMatchers .any (UploadInfo .class ),
183+ nullable (String .class ));
176184 assertThat (servletResponse .getHeader (HttpHeader .LOCATION ), endsWith ("/test/upload/" + id .toString ()));
177185 assertThat (servletResponse .getStatus (), is (HttpServletResponse .SC_CREATED ));
178186 }
0 commit comments