Skip to content

Commit 52f5009

Browse files
committed
Fixed compilation warnings
1 parent 334aa51 commit 52f5009

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

src/main/java/cd/go/contrib/elasticagent/utils/Util.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,12 @@
1616

1717
package cd.go.contrib.elasticagent.utils;
1818

19-
import cd.go.contrib.elasticagent.executors.GetViewRequestExecutor;
20-
import com.google.common.io.ByteStreams;
21-
import com.google.common.io.CharStreams;
2219
import com.google.gson.Gson;
2320
import com.google.gson.GsonBuilder;
2421

22+
import java.io.ByteArrayOutputStream;
2523
import java.io.IOException;
2624
import java.io.InputStream;
27-
import java.io.InputStreamReader;
2825
import java.io.StringReader;
2926
import java.nio.charset.StandardCharsets;
3027
import java.text.DecimalFormat;
@@ -45,21 +42,27 @@ public static SimpleDateFormat getSimpleDateFormat() {
4542
}
4643

4744
public static String readResource(String resourceFile) {
48-
try (InputStreamReader reader = new InputStreamReader(GetViewRequestExecutor.class.getResourceAsStream(resourceFile), StandardCharsets.UTF_8)) {
49-
return CharStreams.toString(reader);
50-
} catch (IOException e) {
51-
throw new RuntimeException("Could not find resource " + resourceFile, e);
52-
}
45+
return new String(readResourceBytes(resourceFile), StandardCharsets.UTF_8);
5346
}
5447

5548
public static byte[] readResourceBytes(String resourceFile) {
56-
try (InputStream in = GetViewRequestExecutor.class.getResourceAsStream(resourceFile)) {
57-
return ByteStreams.toByteArray(in);
49+
try (InputStream is = Util.class.getResourceAsStream(resourceFile)) {
50+
return readFully(is);
5851
} catch (IOException e) {
5952
throw new RuntimeException("Could not find resource " + resourceFile, e);
6053
}
6154
}
6255

56+
private static byte[] readFully(InputStream input) throws IOException {
57+
byte[] buffer = new byte[8192];
58+
int bytesRead;
59+
ByteArrayOutputStream output = new ByteArrayOutputStream();
60+
while ((bytesRead = input.read(buffer)) != -1) {
61+
output.write(buffer, 0, bytesRead);
62+
}
63+
return output.toByteArray();
64+
}
65+
6366
public static String pluginId() {
6467
String s = readResource("/plugin.properties");
6568
try {

src/test/java/cd/go/contrib/elasticagent/executors/GetPluginConfigurationExecutorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class GetPluginConfigurationExecutorTest {
3333
@Test
3434
public void shouldSerializeAllFields() {
3535
GoPluginApiResponse response = new GetPluginConfigurationExecutor().execute();
36-
Map hashMap = new Gson().fromJson(response.responseBody(), new TypeToken<Map<String, Object>>() {
36+
Map<String, Object> hashMap = new Gson().fromJson(response.responseBody(), new TypeToken<Map<String, Object>>() {
3737
}.getType());
3838
assertEquals("Are you using anonymous inner classes — see https://github.com/google/gson/issues/298",
3939
hashMap.size(),

src/test/java/cd/go/contrib/elasticagent/executors/GetViewRequestExecutorTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
import cd.go.contrib.elasticagent.model.Field;
2020
import cd.go.contrib.elasticagent.utils.Util;
2121
import com.google.gson.Gson;
22+
import com.google.gson.reflect.TypeToken;
2223
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse;
2324
import org.hamcrest.Matchers;
2425
import org.jsoup.Jsoup;
2526
import org.jsoup.nodes.Document;
2627
import org.jsoup.select.Elements;
2728
import org.junit.Test;
2829

29-
import java.util.HashMap;
3030
import java.util.Map;
3131

3232
import static org.hamcrest.Matchers.hasSize;
@@ -38,7 +38,8 @@ public class GetViewRequestExecutorTest {
3838
public void shouldRenderTheTemplateInJSON() throws Exception {
3939
GoPluginApiResponse response = new GetViewRequestExecutor().execute();
4040
assertThat(response.responseCode(), is(200));
41-
Map<String, String> hashSet = new Gson().fromJson(response.responseBody(), HashMap.class);
41+
Map<String, String> hashSet = new Gson().fromJson(response.responseBody(), new TypeToken<Map<String, String>>() {
42+
}.getType());
4243
assertThat(hashSet, Matchers.hasEntry("template", Util.readResource("/plugin-settings.template.html")));
4344
}
4445

src/test/java/cd/go/contrib/elasticagent/executors/ServerPingRequestExecutorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class ServerPingRequestExecutorTest extends BaseTest {
5151
@Mock
5252
private Pod mockedPod;
5353
@Mock
54-
private PodResource podResource;
54+
private PodResource<Pod, DoneablePod> podResource;
5555
private ObjectMeta objectMetadata;
5656

5757
@Before

0 commit comments

Comments
 (0)