general cleanup work

This commit is contained in:
eugenp 2015-12-25 20:45:45 +02:00 committed by David Morley
parent 85dc59632e
commit 1edcb35d2c
2 changed files with 10 additions and 18 deletions

View File

@ -13,13 +13,12 @@ public class JavaTryWithResourcesTest {
private static final String TEST_STRING_HELLO_WORLD = "Hello World"; private static final String TEST_STRING_HELLO_WORLD = "Hello World";
private Date resource1Date, resource2Date; private Date resource1Date, resource2Date;
/* // tests
* Example for using Try_with_resources
*/ /* Example for using Try_with_resources */
@Test @Test
public void whenWritingToStringWriter_thenCorrectlyWritten() { public void whenWritingToStringWriter_thenCorrectlyWritten() {
final StringWriter sw = new StringWriter();
StringWriter sw = new StringWriter();
try (PrintWriter pw = new PrintWriter(sw, true)) { try (PrintWriter pw = new PrintWriter(sw, true)) {
pw.print(TEST_STRING_HELLO_WORLD); pw.print(TEST_STRING_HELLO_WORLD);
} }
@ -27,13 +26,11 @@ public class JavaTryWithResourcesTest {
Assert.assertEquals(sw.getBuffer().toString(), TEST_STRING_HELLO_WORLD); Assert.assertEquals(sw.getBuffer().toString(), TEST_STRING_HELLO_WORLD);
} }
/* /* Example for using multiple resources */
* Example for using multiple resources
*/
@Test @Test
public void givenStringToScanner_whenWritingToStringWriter_thenCorrectlyWritten() { public void givenStringToScanner_whenWritingToStringWriter_thenCorrectlyWritten() {
StringWriter sw = new StringWriter(); final StringWriter sw = new StringWriter();
try (Scanner sc = new Scanner(TEST_STRING_HELLO_WORLD); PrintWriter pw = new PrintWriter(sw, true)) { try (Scanner sc = new Scanner(TEST_STRING_HELLO_WORLD); PrintWriter pw = new PrintWriter(sw, true)) {
while (sc.hasNext()) { while (sc.hasNext()) {
pw.print(sc.nextLine()); pw.print(sc.nextLine());
@ -43,12 +40,9 @@ public class JavaTryWithResourcesTest {
Assert.assertEquals(sw.getBuffer().toString(), TEST_STRING_HELLO_WORLD); Assert.assertEquals(sw.getBuffer().toString(), TEST_STRING_HELLO_WORLD);
} }
/* /* Example to show order in which the resources are closed */
* Example to show order in which the resources are closed
*/
@Test @Test
public void whenFirstAutoClosableResourceIsinitializedFirst_thenFirstAutoClosableResourceIsReleasedFirst() throws Exception { public void whenFirstAutoClosableResourceIsinitializedFirst_thenFirstAutoClosableResourceIsReleasedFirst() throws Exception {
try (AutoCloseableResourcesFirst af = new AutoCloseableResourcesFirst(); AutoCloseableResourcesSecond as = new AutoCloseableResourcesSecond()) { try (AutoCloseableResourcesFirst af = new AutoCloseableResourcesFirst(); AutoCloseableResourcesSecond as = new AutoCloseableResourcesSecond()) {
af.doSomething(); af.doSomething();
as.doSomething(); as.doSomething();
@ -57,7 +51,6 @@ public class JavaTryWithResourcesTest {
} }
class AutoCloseableResourcesFirst implements AutoCloseable { class AutoCloseableResourcesFirst implements AutoCloseable {
public AutoCloseableResourcesFirst() { public AutoCloseableResourcesFirst() {
System.out.println("Constructor -> AutoCloseableResources_First"); System.out.println("Constructor -> AutoCloseableResources_First");
} }
@ -70,12 +63,10 @@ public class JavaTryWithResourcesTest {
public void close() throws Exception { public void close() throws Exception {
System.out.println("Closed AutoCloseableResources_First"); System.out.println("Closed AutoCloseableResources_First");
resource1Date = new Date(); resource1Date = new Date();
} }
} }
class AutoCloseableResourcesSecond implements AutoCloseable { class AutoCloseableResourcesSecond implements AutoCloseable {
public AutoCloseableResourcesSecond() { public AutoCloseableResourcesSecond() {
System.out.println("Constructor -> AutoCloseableResources_Second"); System.out.println("Constructor -> AutoCloseableResources_Second");
} }
@ -91,4 +82,5 @@ public class JavaTryWithResourcesTest {
Thread.sleep(10000); Thread.sleep(10000);
} }
} }
} }

View File

@ -38,8 +38,8 @@ import com.google.common.collect.ImmutableSet;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = CassandraConfig.class) @ContextConfiguration(classes = CassandraConfig.class)
public class CQLQueriesIntegrationTest { public class CqlQueriesIntegrationTest {
private static final Log LOGGER = LogFactory.getLog(CQLQueriesIntegrationTest.class); private static final Log LOGGER = LogFactory.getLog(CqlQueriesIntegrationTest.class);
public static final String KEYSPACE_CREATION_QUERY = "CREATE KEYSPACE IF NOT EXISTS testKeySpace " + "WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': '3' };"; public static final String KEYSPACE_CREATION_QUERY = "CREATE KEYSPACE IF NOT EXISTS testKeySpace " + "WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': '3' };";