1/* 2 * Copyright 2008 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16package org.mockftpserver.fake.filesystem 17 18import org.mockftpserver.test.AbstractGroovyTest 19 20/** 21 * Tests for FileInfo 22 * 23 * @version $Revision: $ - $Date: $ 24 * 25 * @author Chris Mair 26 */ 27public final class FileInfoTest extends AbstractGroovyTest { 28 29 private static final String NAME = "def.txt" 30 private static final long SIZE = 1234567L 31 private static final Date LAST_MODIFIED = new Date() 32 33 private FileInfo fileInfoFile 34 private FileInfo fileInfoDirectory 35 36 /** 37 * Test the forFile() constructor 38 */ 39 void testFileConstructor() { 40 assert fileInfoFile.isDirectory() == false 41 assert fileInfoFile.getName() == NAME 42 assert fileInfoFile.getSize() == SIZE 43 assert fileInfoFile.lastModified == LAST_MODIFIED 44 } 45 46 /** 47 * Test the forDirectory() constructor 48 */ 49 void testDirectoryConstructor() { 50 assert fileInfoDirectory.isDirectory() 51 assert fileInfoDirectory.getName() == NAME 52 assert fileInfoDirectory.getSize() == 0 53 assert fileInfoDirectory.lastModified == LAST_MODIFIED 54 } 55 56 /** 57 * Test the equals() method 58 */ 59 void testEquals() { 60 assert fileInfoFile.equals(fileInfoFile) 61 assert fileInfoFile.equals(FileInfo.forFile(NAME, SIZE, LAST_MODIFIED)) 62 assert fileInfoFile.equals(FileInfo.forFile(NAME, SIZE, new Date())) // lastModified ignored 63 64 assert !fileInfoFile.equals(FileInfo.forFile("xyz", SIZE, LAST_MODIFIED)) 65 assert !fileInfoFile.equals(FileInfo.forFile(NAME, 999L, LAST_MODIFIED)) 66 assert !fileInfoFile.equals("ABC") 67 assert !fileInfoFile.equals(null) 68 } 69 70 /** 71 * Test the hashCode() method 72 */ 73 void testHashCode() { 74 assert fileInfoFile.hashCode() == fileInfoFile.hashCode() 75 assert fileInfoFile.hashCode() == FileInfo.forFile(NAME, SIZE, LAST_MODIFIED).hashCode() 76 assert fileInfoFile.hashCode() == FileInfo.forFile(NAME, SIZE, new Date()).hashCode() // lastModified ignored 77 78 assert fileInfoFile.hashCode() != FileInfo.forFile("xyz", SIZE, LAST_MODIFIED).hashCode() 79 assert fileInfoFile.hashCode() != FileInfo.forFile(NAME, 33, LAST_MODIFIED).hashCode() 80 81 assert fileInfoDirectory.hashCode() == FileInfo.forDirectory(NAME, LAST_MODIFIED).hashCode() 82 } 83 84 /** 85 * Test the toString() method 86 */ 87 void testToString() { 88 String toString = fileInfoFile.toString() 89 assert toString.contains(NAME) 90 assert toString.contains(Long.toString(SIZE)) 91 assert toString.contains(LAST_MODIFIED.toString()) 92 } 93 94 /** 95 * @see org.mockftpserver.test.AbstractTest#setUp() 96 */ 97 void setUp() { 98 super.setUp() 99 fileInfoFile = FileInfo.forFile(NAME, SIZE, LAST_MODIFIED) 100 fileInfoDirectory = FileInfo.forDirectory(NAME, LAST_MODIFIED) 101 } 102} 103