1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package org.apache.commons.io.file; 19 20 import static org.apache.commons.io.file.CounterAssertions.assertCounts; 21 22 import java.io.IOException; 23 import java.nio.file.Paths; 24 25 import org.apache.commons.io.file.Counters.PathCounters; 26 import org.junit.jupiter.api.Test; 27 28 /** 29 * Tests {@link PathUtils}. 30 */ 31 public class PathUtilsCountingTest { 32 33 /** 34 * Tests an empty folder. 35 */ 36 @Test testCountEmptyFolder()37 public void testCountEmptyFolder() throws IOException { 38 try (TempDirectory tempDir = TempDirectory.create(getClass().getCanonicalName())) { 39 final PathCounters pathCounts = PathUtils.countDirectory(tempDir.get()); 40 assertCounts(1, 0, 0, pathCounts); 41 } 42 } 43 44 /** 45 * Tests a directory with one file of size 0. 46 */ 47 @Test testCountFolders1FileSize0()48 public void testCountFolders1FileSize0() throws IOException { 49 final PathCounters pathCounts = PathUtils 50 .countDirectory(Paths.get("src/test/resources/org/apache/commons/io/dirs-1-file-size-0")); 51 assertCounts(1, 1, 0, pathCounts); 52 } 53 54 /** 55 * Tests a directory with one file of size 1. 56 */ 57 @Test testCountFolders1FileSize1()58 public void testCountFolders1FileSize1() throws IOException { 59 final PathCounters visitor = PathUtils 60 .countDirectory(Paths.get("src/test/resources/org/apache/commons/io/dirs-1-file-size-1")); 61 assertCounts(1, 1, 1, visitor); 62 } 63 64 /** 65 * Tests a directory with two subdirectories, each containing one file of size 1. 66 */ 67 @Test testCountFolders2FileSize2()68 public void testCountFolders2FileSize2() throws IOException { 69 final PathCounters pathCounts = PathUtils 70 .countDirectory(Paths.get("src/test/resources/org/apache/commons/io/dirs-2-file-size-2")); 71 assertCounts(3, 2, 2, pathCounts); 72 } 73 74 /** 75 * Tests a directory with two subdirectories, each containing one file of size 2. 76 */ 77 @Test testCountFolders2FileSize4()78 public void testCountFolders2FileSize4() throws IOException { 79 final PathCounters pathCounts = PathUtils 80 .countDirectory(Paths.get("src/test/resources/org/apache/commons/io/dirs-2-file-size-4")); 81 assertCounts(3, 4, 8, pathCounts); 82 } 83 } 84