Merge pull request #75 from Doha2012/master

Move Class JavaFolderSizeTest
This commit is contained in:
Eugen 2014-11-20 11:00:12 +02:00
commit b349d6bbc9
1 changed files with 11 additions and 10 deletions

View File

@ -1,4 +1,4 @@
package org.baeldung.java.io;
package org.baeldung.java8;
import static org.junit.Assert.assertEquals;
@ -6,7 +6,6 @@ import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
//import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
@ -18,11 +17,12 @@ import java.util.stream.StreamSupport;
import org.apache.commons.io.FileUtils;
import org.junit.Test;
public class JavaFolderSizeTest {
@Test
public void whenGetFolderSizeRecursive_thenCorrect() {
final long expectedSize = 12607;
final long expectedSize = 124;
final File folder = new File("src/test/resources");
final long size = getFolderSize(folder);
@ -32,7 +32,7 @@ public class JavaFolderSizeTest {
@Test
public void whenGetFolderSizeUsingJava7_thenCorrect() throws IOException {
final long expectedSize = 12607;
final long expectedSize = 124;
final AtomicLong size = new AtomicLong(0);
final Path folder = Paths.get("src/test/resources");
@ -50,7 +50,7 @@ public class JavaFolderSizeTest {
@Test
public void whenGetFolderSizeUsingJava8_thenCorrect() throws IOException {
final long expectedSize = 12607;
final long expectedSize = 124;
final Path folder = Paths.get("src/test/resources");
final long size = Files.walk(folder).filter(p -> p.toFile().isFile()).mapToLong(p -> p.toFile().length()).sum();
@ -60,7 +60,7 @@ public class JavaFolderSizeTest {
@Test
public void whenGetFolderSizeUsingApacheCommonsIO_thenCorrect() {
final long expectedSize = 12607;
final long expectedSize = 124;
final File folder = new File("src/test/resources");
final long size = FileUtils.sizeOfDirectory(folder);
@ -70,7 +70,7 @@ public class JavaFolderSizeTest {
@Test
public void whenGetFolderSizeUsingGuava_thenCorrect() {
final long expectedSize = 12607;
final long expectedSize = 124;
final File folder = new File("src/test/resources");
@ -90,7 +90,7 @@ public class JavaFolderSizeTest {
final double unitValue = 1 << (unitIndex * 10);
final String readableSize = new DecimalFormat("#,##0.#").format(size / unitValue) + " " + units[unitIndex];
assertEquals("12.3 KB", readableSize);
assertEquals("124 B", readableSize);
}
private long getFolderSize(final File folder) {
@ -100,10 +100,11 @@ public class JavaFolderSizeTest {
final int count = files.length;
for (int i = 0; i < count; i++) {
if (files[i].isFile())
if (files[i].isFile()) {
length += files[i].length();
else
} else {
length += getFolderSize(files[i]);
}
}
return length;
}