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
9
* http://www.apache.org/licenses/LICENSE-2.0
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.
17
package org.apache.commons.io.comparator;
20
import junit.framework.Test;
21
import junit.framework.TestSuite;
22
import junit.textui.TestRunner;
25
* Test case for {@link SizeFileComparator}.
27
public class SizeFileComparatorTest extends ComparatorAbstractTestCase {
29
private File smallerDir;
30
private File largerDir;
31
private File smallerFile;
32
private File largerFile;
37
* @param args arguments
39
public static void main(String[] args) {
40
TestRunner.run(suite());
44
* Create a test suite.
46
* @return The test suite
48
public static Test suite() {
49
return new TestSuite(SizeFileComparatorTest.class);
53
* Construct a new test case with the specified name.
55
* @param name Name of the test
57
public SizeFileComparatorTest(String name) {
61
/** @see junit.framework.TestCase#setUp() */
62
protected void setUp() throws Exception {
64
comparator = SizeFileComparator.SIZE_COMPARATOR;
65
reverse = SizeFileComparator.SIZE_REVERSE;
66
File dir = getTestDirectory();
67
smallerDir = new File(dir, "smallerdir");
68
largerDir = new File(dir, "largerdir");
69
smallerFile = new File(smallerDir, "smaller.txt");
70
largerFile = new File(largerDir, "larger.txt");
73
createFile(smallerFile, 32);
74
createFile(largerFile, 64);
75
equalFile1 = smallerFile;
76
equalFile2 = smallerFile;
77
lessFile = smallerFile;
78
moreFile = largerFile;
82
* Test a file which doesn't exist.
84
public void testNonexistantFile() {
85
File nonexistantFile = new File(new File("."), "nonexistant.txt");
86
assertFalse(nonexistantFile.exists());
87
assertTrue("less", comparator.compare(nonexistantFile, moreFile) < 0);
91
* Test a file which doesn't exist.
93
public void testCompareDirectorySizes() {
94
assertEquals("sumDirectoryContents=false", 0, comparator.compare(smallerDir, largerDir));
95
assertEquals("less", -1, SizeFileComparator.SIZE_SUMDIR_COMPARATOR.compare(smallerDir, largerDir));
96
assertEquals("less", 1, SizeFileComparator.SIZE_SUMDIR_REVERSE.compare(smallerDir, largerDir));