Skip to content

Commit 5ce39c7

Browse files
fix(pom): upgrade sdk-core (#1220)
This upgrade is mainly to remove the vulnerable guava dependency
1 parent 0b5ec7e commit 5ce39c7

File tree

5 files changed

+38
-18
lines changed

5 files changed

+38
-18
lines changed

common/src/test/java/com/ibm/watson/common/WatsonServiceUnitTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@
1313
package com.ibm.watson.common;
1414

1515
import com.google.gson.Gson;
16+
import com.google.gson.reflect.TypeToken;
1617
import com.ibm.cloud.sdk.core.http.HttpMediaType;
1718
import com.ibm.cloud.sdk.core.util.GsonSingleton;
1819
import java.io.IOException;
20+
import java.lang.reflect.Type;
21+
import java.util.HashMap;
1922
import okhttp3.mockwebserver.MockResponse;
2023
import okhttp3.mockwebserver.MockWebServer;
2124
import org.apache.commons.lang3.StringUtils;
@@ -81,4 +84,18 @@ protected static MockResponse jsonResponse(Object body) {
8184
.addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON)
8285
.setBody(GSON.toJson(body));
8386
}
87+
88+
/**
89+
* Create a MockResponse with JSON content type and the object serialized to JSON as body.
90+
* For HashMaps
91+
*
92+
* @param body the body
93+
* @return the mock response
94+
*/
95+
protected static MockResponse hashmapToJsonResponse(Object body) {
96+
Type typeObject = new TypeToken<HashMap>() {}.getType();
97+
return new MockResponse()
98+
.addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON)
99+
.setBody(GSON.toJson(body, typeObject));
100+
}
84101
}

language-translator/src/test/java/com/ibm/watson/language_translator/v3/LanguageTranslatorIT.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
import static org.junit.Assert.assertNotNull;
1818
import static org.junit.Assert.assertTrue;
1919

20-
import com.google.common.collect.ImmutableList;
21-
import com.google.common.collect.ImmutableMap;
2220
import com.ibm.cloud.sdk.core.http.HttpMediaType;
2321
import com.ibm.cloud.sdk.core.http.Response;
2422
import com.ibm.cloud.sdk.core.security.Authenticator;
@@ -32,6 +30,7 @@
3230
import java.io.FileNotFoundException;
3331
import java.io.IOException;
3432
import java.io.InputStream;
33+
import java.util.ArrayList;
3534
import java.util.HashMap;
3635
import java.util.List;
3736
import java.util.Map;
@@ -47,12 +46,11 @@ public class LanguageTranslatorIT extends WatsonServiceTest {
4746
private LanguageTranslator service;
4847

4948
private final Map<String, String> translations =
50-
ImmutableMap.of(
51-
"The IBM Watson team is awesome",
52-
"El equipo de IBM Watson es impresionante",
53-
"Welcome to the cognitive era",
54-
"Bienvenido a la era cognitiva");
55-
private final List<String> texts = ImmutableList.copyOf(translations.keySet());
49+
new HashMap<String, String>() {{
50+
put("The IBM Watson team is awesome", "El equipo de IBM Watson es impresionante");
51+
put("Welcome to the cognitive era", "Bienvenido a la era cognitiva");
52+
}};
53+
private final List<String> texts = new ArrayList<>(translations.keySet());
5654

5755
/**
5856
* Sets up the tests.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<properties>
1818
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1919

20-
<sdk-core-version>9.17.3</sdk-core-version>
20+
<sdk-core-version>9.18.4</sdk-core-version>
2121

2222
<!-- >>> Replace this with the name of your SDK's github repository -->
2323
<git-repository-name>java-sdk</git-repository-name>

text-to-speech/src/test/java/com/ibm/watson/text_to_speech/v1/CustomizationsIT.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import static org.junit.Assert.assertNotNull;
1919
import static org.junit.Assert.fail;
2020

21-
import com.google.common.collect.ImmutableList;
2221
import com.ibm.cloud.sdk.core.http.HttpMediaType;
2322
import com.ibm.cloud.sdk.core.security.Authenticator;
2423
import com.ibm.cloud.sdk.core.security.IamAuthenticator;
@@ -28,6 +27,8 @@
2827
import com.ibm.watson.text_to_speech.v1.model.*;
2928
import java.io.IOException;
3029
import java.io.InputStream;
30+
import java.util.Arrays;
31+
import java.util.Collections;
3132
import java.util.List;
3233
import org.junit.After;
3334
import org.junit.Before;
@@ -79,7 +80,7 @@ private List<Word> instantiateWords() {
7980
.word("shocking")
8081
.translation("<phoneme alphabet='ibm' ph='.1Sa.0kIG'></phoneme>")
8182
.build();
82-
return ImmutableList.of(word1, word2);
83+
return Collections.unmodifiableList(Arrays.asList(word1, word2));
8384
}
8485

8586
private List<Word> instantiateWordsJapanese() {
@@ -95,7 +96,7 @@ private List<Word> instantiateWordsJapanese() {
9596
.translation("close the door")
9697
.partOfSpeech(Word.PartOfSpeech.HOKA)
9798
.build();
98-
return ImmutableList.of(word1, word2);
99+
return Collections.unmodifiableList(Arrays.asList(word1, word2));
99100
}
100101

101102
private CustomModel createCustomModel() {

text-to-speech/src/test/java/com/ibm/watson/text_to_speech/v1/CustomizationsTest.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@
1717
import static org.junit.Assert.assertNotNull;
1818
import static org.junit.Assert.assertNull;
1919

20-
import com.google.common.collect.ImmutableList;
21-
import com.google.common.collect.ImmutableMap;
2220
import com.ibm.cloud.sdk.core.security.NoAuthAuthenticator;
2321
import com.ibm.watson.common.WatsonServiceUnitTest;
2422
import com.ibm.watson.text_to_speech.v1.model.*;
25-
import java.util.List;
23+
import java.util.*;
2624
import okhttp3.mockwebserver.MockResponse;
2725
import okhttp3.mockwebserver.RecordedRequest;
2826
import org.junit.Before;
@@ -80,7 +78,7 @@ private static Word instantiateWord() {
8078
}
8179

8280
private static List<Word> instantiateWords() {
83-
return ImmutableList.of(instantiateWord());
81+
return Collections.unmodifiableList(Arrays.asList(instantiateWord()));
8482
}
8583

8684
/**
@@ -331,7 +329,9 @@ public void testDeleteVoiceModel() throws InterruptedException {
331329
public void testListWords() throws InterruptedException {
332330
final List<Word> expected = instantiateWords();
333331

334-
server.enqueue(jsonResponse(ImmutableMap.of(WORDS, expected)));
332+
server.enqueue(hashmapToJsonResponse(new HashMap<String, List<Word>>() {{
333+
put(WORDS, expected);
334+
}}));
335335
ListWordsOptions listOptions =
336336
new ListWordsOptions.Builder().customizationId(CUSTOMIZATION_ID).build();
337337
final Words result = service.listWords(listOptions).execute().getResult();
@@ -351,7 +351,11 @@ public void testListWords() throws InterruptedException {
351351
public void testGetWord() throws InterruptedException {
352352
final Word expected = instantiateWords().get(0);
353353

354-
server.enqueue(jsonResponse(ImmutableMap.of(TRANSLATION, expected.translation())));
354+
Map<String, String> map = new HashMap<String, String>() {{
355+
put(TRANSLATION, expected.translation());
356+
}};
357+
358+
server.enqueue(hashmapToJsonResponse(map));
355359
GetWordOptions getOptions =
356360
new GetWordOptions.Builder()
357361
.customizationId(CUSTOMIZATION_ID)

0 commit comments

Comments
 (0)