class Helper extends ErrorAware {

    public static long folderSize(File directory) {
        // from https://stackoverflow.com/a/2149807
        long length = 0;
        File[] content = directory.listFiles();
        if (content != null) {
            for (File file : content) {
                if (file.isFile())
                    length += file.length();
                else
                    length += folderSize(file);
            }
        }
        return length;
    }

}

class HelperTest {

    @Test
    public void testFolderSize() throws IOException {

        File dir = Files.createTempDir();
        assertEquals(Helper.folderSize(dir), 0);
        // write to a file
        // see https://stackoverflow.com/a/2885224
        byte data[] = new byte[100];
        FileOutputStream out = new FileOutputStream(dir.toString() + "/test.txt");
        out.write(data);
        out.close();
        long size = Helper.folderSize(dir);
        assertEquals(size, 100);
    }

}