WindowsDirectoryListingFormatterTest.groovy revision 1dfeab57f80c3a156a7ff11871c03f3f53033b9e
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 java.text.SimpleDateFormat 19import org.mockftpserver.test.AbstractGroovyTest 20 21/** 22 * Tests for WindowsDirectoryListingFormatter 23 * 24 * @version $Revision: 78 $ - $Date: 2008-07-02 20:47:17 -0400 (Wed, 02 Jul 2008) $ 25 * 26 * @author Chris Mair 27 */ 28class WindowsDirectoryListingFormatterTest extends AbstractGroovyTest { 29 30 static final NAME = "def.txt" 31 static final PATH = "/dir/$NAME" 32 static final LAST_MODIFIED = new Date() 33 static final SIZE_WIDTH = WindowsDirectoryListingFormatter.SIZE_WIDTH 34 35 private formatter 36 private dateFormat 37 private lastModifiedFormatted 38 39 void testFormat_File() { 40 def fileEntry = new FileEntry(path: PATH, contents: 'abcd', lastModified: LAST_MODIFIED) 41 def sizeStr = 4.toString().padLeft(SIZE_WIDTH) 42 def expected = "$lastModifiedFormatted $sizeStr $NAME" 43 def result = formatter.format(fileEntry) 44 LOG.info("result=$result") 45 assert result == expected 46 } 47 48 void testFormat_Directory() { 49 def fileEntry = new DirectoryEntry(path: PATH, lastModified: LAST_MODIFIED) 50 def dirStr = "<DIR>".padRight(SIZE_WIDTH) 51 def expected = "$lastModifiedFormatted $dirStr $NAME" 52 def result = formatter.format(fileEntry) 53 LOG.info("result=$result") 54 assert result == expected 55 } 56 57 void setUp() { 58 super.setUp() 59 formatter = new WindowsDirectoryListingFormatter() 60 dateFormat = new SimpleDateFormat(WindowsDirectoryListingFormatter.DATE_FORMAT) 61 lastModifiedFormatted = dateFormat.format(LAST_MODIFIED) 62 } 63}