19d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair/* 29d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Copyright 2008 the original author or authors. 39d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * 49d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Licensed under the Apache License, Version 2.0 (the "License"); 59d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * you may not use this file except in compliance with the License. 69d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * You may obtain a copy of the License at 79d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * 89d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * http://www.apache.org/licenses/LICENSE-2.0 99d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * 109d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Unless required by applicable law or agreed to in writing, software 119d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * distributed under the License is distributed on an "AS IS" BASIS, 129d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 139d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * See the License for the specific language governing permissions and 149d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * limitations under the License. 159d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */ 169d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairpackage org.mockftpserver.fake.filesystem 179d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 189d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport org.mockftpserver.test.AbstractGroovyTest 199d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 209d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair/** 219d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Tests for FileInfo 229d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * 239d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * @version $Revision: $ - $Date: $ 249d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * 259d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * @author Chris Mair 269d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */ 279d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairpublic final class FileInfoTest extends AbstractGroovyTest { 289d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 299d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair private static final String NAME = "def.txt" 309d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair private static final long SIZE = 1234567L 319d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair private static final Date LAST_MODIFIED = new Date() 329d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 339d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair private FileInfo fileInfoFile 349d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair private FileInfo fileInfoDirectory 359d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 369d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair /** 379d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Test the forFile() constructor 389d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */ 399d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair void testFileConstructor() { 409d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assert fileInfoFile.isDirectory() == false 419d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assert fileInfoFile.getName() == NAME 429d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assert fileInfoFile.getSize() == SIZE 439d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assert fileInfoFile.lastModified == LAST_MODIFIED 449d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 459d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 469d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair /** 479d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Test the forDirectory() constructor 489d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */ 499d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair void testDirectoryConstructor() { 509d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assert fileInfoDirectory.isDirectory() 519d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assert fileInfoDirectory.getName() == NAME 529d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assert fileInfoDirectory.getSize() == 0 539d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assert fileInfoDirectory.lastModified == LAST_MODIFIED 549d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 559d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 569d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair /** 579d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Test the equals() method 589d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */ 599d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair void testEquals() { 609d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assert fileInfoFile.equals(fileInfoFile) 619d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assert fileInfoFile.equals(FileInfo.forFile(NAME, SIZE, LAST_MODIFIED)) 629d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assert fileInfoFile.equals(FileInfo.forFile(NAME, SIZE, new Date())) // lastModified ignored 639d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 649d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assert !fileInfoFile.equals(FileInfo.forFile("xyz", SIZE, LAST_MODIFIED)) 659d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assert !fileInfoFile.equals(FileInfo.forFile(NAME, 999L, LAST_MODIFIED)) 669d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assert !fileInfoFile.equals("ABC") 679d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assert !fileInfoFile.equals(null) 689d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 699d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 709d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair /** 719d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Test the hashCode() method 729d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */ 739d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair void testHashCode() { 749d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assert fileInfoFile.hashCode() == fileInfoFile.hashCode() 759d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assert fileInfoFile.hashCode() == FileInfo.forFile(NAME, SIZE, LAST_MODIFIED).hashCode() 769d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assert fileInfoFile.hashCode() == FileInfo.forFile(NAME, SIZE, new Date()).hashCode() // lastModified ignored 779d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 789d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assert fileInfoFile.hashCode() != FileInfo.forFile("xyz", SIZE, LAST_MODIFIED).hashCode() 799d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assert fileInfoFile.hashCode() != FileInfo.forFile(NAME, 33, LAST_MODIFIED).hashCode() 809d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 819d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assert fileInfoDirectory.hashCode() == FileInfo.forDirectory(NAME, LAST_MODIFIED).hashCode() 829d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 839d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 849d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair /** 859d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Test the toString() method 869d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */ 879d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair void testToString() { 889d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair String toString = fileInfoFile.toString() 899d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assert toString.contains(NAME) 909d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assert toString.contains(Long.toString(SIZE)) 919d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assert toString.contains(LAST_MODIFIED.toString()) 929d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 939d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 949d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair /** 959d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * @see org.mockftpserver.test.AbstractTest#setUp() 969d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */ 979d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair void setUp() { 989d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair super.setUp() 999d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair fileInfoFile = FileInfo.forFile(NAME, SIZE, LAST_MODIFIED) 1009d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair fileInfoDirectory = FileInfo.forDirectory(NAME, LAST_MODIFIED) 1019d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 1029d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair} 103