cleanup work and starting new tests

This commit is contained in:
eugenp 2014-06-19 21:19:14 +03:00
parent f18520d30d
commit 59cd8a8baf
3 changed files with 51 additions and 3 deletions

View File

@ -1,4 +1,4 @@
package org.baeldung.java; package org.baeldung.java.io;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
@ -25,7 +25,7 @@ import com.google.common.base.Charsets;
import com.google.common.io.CharStreams; import com.google.common.io.CharStreams;
import com.google.common.io.InputSupplier; import com.google.common.io.InputSupplier;
public class CoreJavaIoUnitTest { public class JavaInputStreamToXUnitTest {
protected final Logger logger = LoggerFactory.getLogger(getClass()); protected final Logger logger = LoggerFactory.getLogger(getClass());
private static final int DEFAULT_SIZE = 150000000; private static final int DEFAULT_SIZE = 150000000;

View File

@ -0,0 +1,41 @@
package org.baeldung.java.io;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.io.CharSource;
@SuppressWarnings("unused")
public class JavaXToInputStreamUnitTest {
protected final Logger logger = LoggerFactory.getLogger(getClass());
@Test
public void givenUsingPlainJava_whenConvertingStringToInputStream_thenCorrect() throws IOException {
final String initialString = "text";
final InputStream targetStream = new ByteArrayInputStream(initialString.getBytes());
final byte[] buffer = new byte[targetStream.available()];
targetStream.read(buffer);
final String targetString = new String(buffer);
}
@Test
public void givenUsingGuava_whenConvertingStringToInputStream_thenCorrect() throws IOException {
final String initialString = "text";
final CharSource source = CharSource.wrap(initialString);
final Reader targetStream = source.openStream();
}
@Test
public void givenUsingCommonsIO_whenConvertingStringToInputStream_thenCorrect() throws IOException {
final String initialString = "text";
final InputStream targetStream = IOUtils.toInputStream(initialString);
}
}

View File

@ -1,5 +1,9 @@
package org.baeldung.httpclient; package org.baeldung.httpclient;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import org.apache.http.HttpException;
import org.apache.http.HttpHost; import org.apache.http.HttpHost;
import org.apache.http.client.protocol.HttpClientContext; import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.conn.ConnectionRequest; import org.apache.http.conn.ConnectionRequest;
@ -7,16 +11,19 @@ import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.impl.conn.BasicHttpClientConnectionManager; import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
import org.junit.Test; import org.junit.Test;
@SuppressWarnings("unused")
public class HttpClientConnectionManagementTest { public class HttpClientConnectionManagementTest {
// tests // tests
@Test @Test
public final void whenLowLevelConnectionIsEstablished_thenNoExceptions() { public final void whenLowLevelConnectionIsEstablished_thenNoExceptions() throws IOException, HttpException, InterruptedException, ExecutionException {
final HttpClientContext context = HttpClientContext.create(); final HttpClientContext context = HttpClientContext.create();
final BasicHttpClientConnectionManager connManager = new BasicHttpClientConnectionManager(); final BasicHttpClientConnectionManager connManager = new BasicHttpClientConnectionManager();
final HttpRoute route = new HttpRoute(new HttpHost("localhost", 80)); final HttpRoute route = new HttpRoute(new HttpHost("localhost", 80));
final ConnectionRequest connRequest = connManager.requestConnection(route, null); final ConnectionRequest connRequest = connManager.requestConnection(route, null);
connManager.shutdown();
} }
} }