Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
7b77d38921
|
@ -14,7 +14,7 @@ import org.slf4j.LoggerFactory;
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
|
|
||||||
public class CoreJavaIoIntegrationTest {
|
public class JavaIoIntegrationTest {
|
||||||
protected final Logger logger = LoggerFactory.getLogger(getClass());
|
protected final Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
// tests - iterate lines in a file
|
// tests - iterate lines in a file
|
|
@ -7,7 +7,7 @@ import org.apache.commons.lang3.RandomStringUtils;
|
||||||
import org.apache.commons.math3.random.RandomDataGenerator;
|
import org.apache.commons.math3.random.RandomDataGenerator;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class CoreJavaRandomUnitTest {
|
public class JavaRandomUnitTest {
|
||||||
|
|
||||||
// tests - random long
|
// tests - random long
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
package org.baeldung.java;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class JavaTimerUnitTest {
|
||||||
|
|
||||||
|
// tests
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenUsingTimer_whenSchedulingTaskOnce_thenCorrect() throws InterruptedException {
|
||||||
|
final TimerTask timerTask = new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
System.out.println("Task performed on " + new Date() + "\n" + "Thread's name: " + Thread.currentThread().getName());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
final Timer timer = new Timer("Timer");
|
||||||
|
final long delay = 1000L;
|
||||||
|
timer.schedule(timerTask, delay);
|
||||||
|
|
||||||
|
Thread.sleep(delay * 2);
|
||||||
|
timer.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -30,6 +30,7 @@ public class JavaXToReaderUnitTest {
|
||||||
public void givenUsingPlainJava_whenConvertingStringIntoReader_thenCorrect() throws IOException {
|
public void givenUsingPlainJava_whenConvertingStringIntoReader_thenCorrect() throws IOException {
|
||||||
final String initialString = "With Plain Java";
|
final String initialString = "With Plain Java";
|
||||||
final Reader targetReader = new StringReader(initialString);
|
final Reader targetReader = new StringReader(initialString);
|
||||||
|
|
||||||
targetReader.close();
|
targetReader.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +38,7 @@ public class JavaXToReaderUnitTest {
|
||||||
public void givenUsingGuava_whenConvertingStringIntoReader_thenCorrect() throws IOException {
|
public void givenUsingGuava_whenConvertingStringIntoReader_thenCorrect() throws IOException {
|
||||||
final String initialString = "With Google Guava";
|
final String initialString = "With Google Guava";
|
||||||
final Reader targetReader = CharSource.wrap(initialString).openStream();
|
final Reader targetReader = CharSource.wrap(initialString).openStream();
|
||||||
|
|
||||||
targetReader.close();
|
targetReader.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +46,7 @@ public class JavaXToReaderUnitTest {
|
||||||
public void givenUsingCommonsIO_whenConvertingStringIntoReader_thenCorrect() throws IOException {
|
public void givenUsingCommonsIO_whenConvertingStringIntoReader_thenCorrect() throws IOException {
|
||||||
final String initialString = "With Apache Commons IO";
|
final String initialString = "With Apache Commons IO";
|
||||||
final Reader targetReader = new CharSequenceReader(initialString);
|
final Reader targetReader = new CharSequenceReader(initialString);
|
||||||
|
|
||||||
targetReader.close();
|
targetReader.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,6 +56,7 @@ public class JavaXToReaderUnitTest {
|
||||||
public void givenUsingPlainJava_whenConvertingByteArrayIntoReader_thenCorrect() throws IOException {
|
public void givenUsingPlainJava_whenConvertingByteArrayIntoReader_thenCorrect() throws IOException {
|
||||||
final byte[] initialArray = "Hello world!".getBytes();
|
final byte[] initialArray = "Hello world!".getBytes();
|
||||||
final Reader targetReader = new StringReader(new String(initialArray));
|
final Reader targetReader = new StringReader(new String(initialArray));
|
||||||
|
|
||||||
targetReader.close();
|
targetReader.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,6 +73,7 @@ public class JavaXToReaderUnitTest {
|
||||||
public void givenUsingCommonsIO_whenConvertingByteArrayIntoReader_thenCorrect() throws IOException {
|
public void givenUsingCommonsIO_whenConvertingByteArrayIntoReader_thenCorrect() throws IOException {
|
||||||
final byte[] initialArray = "With Commons IO".getBytes();
|
final byte[] initialArray = "With Commons IO".getBytes();
|
||||||
final Reader targetReader = new CharSequenceReader(new String(initialArray));
|
final Reader targetReader = new CharSequenceReader(new String(initialArray));
|
||||||
|
|
||||||
targetReader.close();
|
targetReader.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,6 +84,7 @@ public class JavaXToReaderUnitTest {
|
||||||
final File initialFile = new File("src/test/resources/initialFile.txt");
|
final File initialFile = new File("src/test/resources/initialFile.txt");
|
||||||
initialFile.createNewFile();
|
initialFile.createNewFile();
|
||||||
final Reader targetReader = new FileReader(initialFile);
|
final Reader targetReader = new FileReader(initialFile);
|
||||||
|
|
||||||
targetReader.close();
|
targetReader.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,6 +93,7 @@ public class JavaXToReaderUnitTest {
|
||||||
final File initialFile = new File("src/test/resources/initialFile.txt");
|
final File initialFile = new File("src/test/resources/initialFile.txt");
|
||||||
com.google.common.io.Files.touch(initialFile);
|
com.google.common.io.Files.touch(initialFile);
|
||||||
final Reader targetReader = com.google.common.io.Files.newReader(initialFile, Charset.defaultCharset());
|
final Reader targetReader = com.google.common.io.Files.newReader(initialFile, Charset.defaultCharset());
|
||||||
|
|
||||||
targetReader.close();
|
targetReader.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,6 +104,7 @@ public class JavaXToReaderUnitTest {
|
||||||
FileUtils.write(initialFile, "With Commons IO");
|
FileUtils.write(initialFile, "With Commons IO");
|
||||||
final byte[] buffer = FileUtils.readFileToByteArray(initialFile);
|
final byte[] buffer = FileUtils.readFileToByteArray(initialFile);
|
||||||
final Reader targetReader = new CharSequenceReader(new String(buffer));
|
final Reader targetReader = new CharSequenceReader(new String(buffer));
|
||||||
|
|
||||||
targetReader.close();
|
targetReader.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +115,6 @@ public class JavaXToReaderUnitTest {
|
||||||
final InputStream initialStream = new ByteArrayInputStream("With Java".getBytes());
|
final InputStream initialStream = new ByteArrayInputStream("With Java".getBytes());
|
||||||
final Reader targetReader = new InputStreamReader(initialStream);
|
final Reader targetReader = new InputStreamReader(initialStream);
|
||||||
|
|
||||||
initialStream.close();
|
|
||||||
targetReader.close();
|
targetReader.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +124,6 @@ public class JavaXToReaderUnitTest {
|
||||||
final byte[] buffer = ByteStreams.toByteArray(initialStream);
|
final byte[] buffer = ByteStreams.toByteArray(initialStream);
|
||||||
final Reader targetReader = CharSource.wrap(new String(buffer)).openStream();
|
final Reader targetReader = CharSource.wrap(new String(buffer)).openStream();
|
||||||
|
|
||||||
initialStream.close();
|
|
||||||
targetReader.close();
|
targetReader.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +133,6 @@ public class JavaXToReaderUnitTest {
|
||||||
final byte[] buffer = IOUtils.toByteArray(initialStream);
|
final byte[] buffer = IOUtils.toByteArray(initialStream);
|
||||||
final Reader targetReader = new CharSequenceReader(new String(buffer));
|
final Reader targetReader = new CharSequenceReader(new String(buffer));
|
||||||
|
|
||||||
initialStream.close();
|
|
||||||
targetReader.close();
|
targetReader.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue