refactor(rest): Make sure resultBuffer is closed
@@ -22,27 +22,32 @@ import io.syndesis.inspector.Inspectors;
import io.syndesis.model.connection.Connector;
import io.syndesis.rest.v1.state.ClientSideState;
import io.syndesis.verifier.Verifier;
+
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
+
import okio.Buffer;
import okio.BufferedSink;
import okio.BufferedSource;
import okio.Okio;
+
import org.junit.Test;
import org.springframework.context.ApplicationContext;
+import java.awt.Dimension;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Iterator;
+
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.StreamingOutput;
-import java.awt.*;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.Iterator;
import static javax.ws.rs.core.HttpHeaders.CONTENT_LENGTH;
import static javax.ws.rs.core.HttpHeaders.CONTENT_TYPE;
+
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -59,19 +64,18 @@ public class ConnectorHandlerTest {
private static final Verifier NO_VERIFIER = null;
- private final DataManager dataManager = mock(DataManager.class);
-
private final ApplicationContext applicationContext = mock(ApplicationContext.class);
+ private final DataManager dataManager = mock(DataManager.class);
+
private final ConnectorHandler handler = new ConnectorHandler(dataManager, NO_VERIFIER, NO_CREDENTIALS, NO_INSPECTORS, NO_STATE,
NO_ENCRYPTION_COMPONENT, applicationContext);
@Test
public void connectorIconShouldHaveCorrectContentType() throws IOException {
- try (MockWebServer mockWebServer = new MockWebServer()) {
+ try (MockWebServer mockWebServer = new MockWebServer(); final Buffer resultBuffer = new Buffer()) {
mockWebServer.start();
- final Buffer resultBuffer = new Buffer();
resultBuffer.writeAll(Okio.source(getClass().getResourceAsStream("test-image.png")));
mockWebServer.enqueue(new MockResponse().setHeader(CONTENT_TYPE, "image/png").setBody(resultBuffer));
