33import com .fasterxml .jackson .core .JsonProcessingException ;
44import com .fasterxml .jackson .databind .ObjectMapper ;
55import com .github .tomakehurst .wiremock .junit .WireMockRule ;
6- import com .google .common .collect .ImmutableList ;
7- import com .google .common .collect .ImmutableMap ;
86import com .smartling .api .filetranslations .v2 .pto .Error ;
97import com .smartling .api .filetranslations .v2 .pto .FileType ;
108import com .smartling .api .filetranslations .v2 .pto .LanguagePTO ;
4442import java .io .ByteArrayInputStream ;
4543import java .io .IOException ;
4644import java .io .InputStream ;
47- import java .io .UnsupportedEncodingException ;
4845import java .nio .charset .StandardCharsets ;
46+ import java .util .Arrays ;
47+ import java .util .Collections ;
4948import java .util .LinkedHashMap ;
5049import java .util .Map ;
5150
5958public class FileTranslationsApiTest
6059{
6160 private static final String SUCCESS_RESPONSE_ENVELOPE = "{\" response\" :{\" code\" :\" SUCCESS\" ,\" data\" :%s}})" ;
62- private static final String ACCOUNT_UID = RandomStringUtils .randomAlphabetic (10 );
63- private static final String FILE_UID = RandomStringUtils .randomAlphabetic (10 );
64- private static final String MT_UID = RandomStringUtils .randomAlphabetic (10 );
65- private static final String LANGUAGE_DETECTION_UID = RandomStringUtils .randomAlphabetic (10 );
66- private static final String SOURCE_LOCALE_ID = RandomStringUtils .randomAlphabetic (10 );
67- private static final String TARGET_LOCALE_ID_1 = RandomStringUtils .randomAlphabetic (5 );
68- private static final String TARGET_LOCALE_ID_2 = RandomStringUtils .randomAlphabetic (5 );
61+ private static final String ACCOUNT_UID = RandomStringUtils .insecure (). nextAlphabetic (10 );
62+ private static final String FILE_UID = RandomStringUtils .insecure (). nextAlphabetic (10 );
63+ private static final String MT_UID = RandomStringUtils .insecure (). nextAlphabetic (10 );
64+ private static final String LANGUAGE_DETECTION_UID = RandomStringUtils .insecure (). nextAlphabetic (10 );
65+ private static final String SOURCE_LOCALE_ID = RandomStringUtils .insecure (). nextAlphabetic (10 );
66+ private static final String TARGET_LOCALE_ID_1 = RandomStringUtils .insecure (). nextAlphabetic (5 );
67+ private static final String TARGET_LOCALE_ID_2 = RandomStringUtils .insecure (). nextAlphabetic (5 );
6968
7069 private MockWebServer mockWebServer ;
7170 private FileTranslationsApi sut ;
@@ -123,21 +122,21 @@ public void mtFile() throws InterruptedException
123122
124123 MtRequest request = new MtRequest ();
125124 request .setSourceLocaleId (SOURCE_LOCALE_ID );
126- request .setTargetLocaleIds (ImmutableList . of (TARGET_LOCALE_ID_1 , TARGET_LOCALE_ID_2 ));
125+ request .setTargetLocaleIds (Arrays . asList (TARGET_LOCALE_ID_1 , TARGET_LOCALE_ID_2 ));
127126
128127 MtResponse response = sut .mtFile (ACCOUNT_UID , FILE_UID , request );
129128
130129 MtRequest recordedRequest = toObj (getRequestWithValidation (HttpMethod .POST ,
131130 String .format ("/file-translations-api/v2/accounts/%s/files/%s/mt" , ACCOUNT_UID , FILE_UID )).getBody ().readUtf8 (), MtRequest .class );
132131 assertThat (recordedRequest .getSourceLocaleId (), is (SOURCE_LOCALE_ID ));
133- assertThat (recordedRequest .getTargetLocaleIds (), is (ImmutableList . of (TARGET_LOCALE_ID_1 , TARGET_LOCALE_ID_2 )));
132+ assertThat (recordedRequest .getTargetLocaleIds (), is (Arrays . asList (TARGET_LOCALE_ID_1 , TARGET_LOCALE_ID_2 )));
134133
135134 assertNotNull (response );
136135 assertEquals (MT_UID , response .getMtUid ());
137136 }
138137
139138 @ Test
140- public void cancelFileProcessing () throws InterruptedException , UnsupportedEncodingException
139+ public void cancelFileProcessing () throws InterruptedException
141140 {
142141 assignResponse (HttpStatus .SC_OK , String .format (SUCCESS_RESPONSE_ENVELOPE , "{}" ));
143142
@@ -192,7 +191,7 @@ public void getMTStatus() throws InterruptedException, IOException
192191 MtStatusResponse response = new MtStatusResponse ();
193192 response .setState (MtState .COMPLETED );
194193 response .setRequestedStringCount (100L );
195- Error <Map <String ,String >> error = new Error <>("some.key" , "some message" , ImmutableMap . of ("key1" , "val1" ));
194+ Error <Map <String ,String >> error = new Error <>("some.key" , "some message" , Collections . singletonMap ("key1" , "val1" ));
196195 response .setError (error );
197196 MtLocaleStatus locale1Status = new MtLocaleStatus ();
198197 locale1Status .setLocaleId (TARGET_LOCALE_ID_1 );
@@ -226,7 +225,7 @@ public void getMTStatus() throws InterruptedException, IOException
226225 assertEquals (response .getRequestedStringCount (), status .getRequestedStringCount ());
227226 assertThat (response .getError ().getKey (), is ("some.key" ));
228227 assertThat (response .getError ().getMessage (), is ("some message" ));
229- assertThat (response .getError ().getDetails (), is (ImmutableMap . of ("key1" , "val1" )));
228+ assertThat (response .getError ().getDetails (), is (Collections . singletonMap ("key1" , "val1" )));
230229 assertEquals (response .getLocaleProcessStatuses ().size (), status .getLocaleProcessStatuses ().size ());
231230 assertEquals (response .getLocaleProcessStatuses ().get (0 ).getLocaleId (), status .getLocaleProcessStatuses ().get (0 ).getLocaleId ());
232231 assertEquals (response .getLocaleProcessStatuses ().get (0 ).getProcessedStringCount (), status .getLocaleProcessStatuses ().get (0 ).getProcessedStringCount ());
@@ -258,7 +257,7 @@ public void detectSourceLanguage() throws InterruptedException
258257 public void getLDStatus () throws InterruptedException , IOException
259258 {
260259 LanguageDetectionStatusResponse response = new LanguageDetectionStatusResponse ();
261- Error <Map <String ,String >> error = new Error <>("some.key" , "some message" , ImmutableMap . of ("key1" , "val1" ));
260+ Error <Map <String ,String >> error = new Error <>("some.key" , "some message" , Collections . singletonMap ("key1" , "val1" ));
262261 response .setError (error );
263262 response .setState (LanguageDetectionState .COMPLETED );
264263 LanguagePTO languagePTO1 = new LanguagePTO ();
@@ -267,7 +266,7 @@ public void getLDStatus() throws InterruptedException, IOException
267266 LanguagePTO languagePTO2 = new LanguagePTO ();
268267 languagePTO2 .setLanguageId ("de" );
269268 languagePTO2 .setDefaultLocaleId ("de-DE" );
270- response .setDetectedSourceLanguages (ImmutableList . of (languagePTO1 , languagePTO2 ));
269+ response .setDetectedSourceLanguages (Arrays . asList (languagePTO1 , languagePTO2 ));
271270 String responseBody = objectMapper .writeValueAsString (response );
272271 assignResponse (HttpStatus .SC_OK , String .format (SUCCESS_RESPONSE_ENVELOPE , responseBody ));
273272
@@ -279,7 +278,7 @@ public void getLDStatus() throws InterruptedException, IOException
279278 assertEquals (response .getState (), status .getState ());
280279 assertThat (response .getError ().getKey (), is ("some.key" ));
281280 assertThat (response .getError ().getMessage (), is ("some message" ));
282- assertThat (response .getError ().getDetails (), is (ImmutableMap . of ("key1" , "val1" )));
281+ assertThat (response .getError ().getDetails (), is (Collections . singletonMap ("key1" , "val1" )));
283282
284283 assertEquals (response .getDetectedSourceLanguages ().size (), status .getDetectedSourceLanguages ().size ());
285284
@@ -335,12 +334,10 @@ private LinkedHashMap<String, Part> toParts(RecordedRequest recordedRequest)
335334
336335 private static class Part
337336 {
338- private okhttp3 .Headers headers ;
339- private byte [] body ;
337+ private final byte [] body ;
340338
341339 public Part (Headers headers , byte [] body )
342340 {
343- this .headers = headers ;
344341 this .body = body ;
345342 }
346343
0 commit comments