WindowsDirectoryListingFormatterTest.groovy revision 7d00fd0c9917e59d8ee38543e25fcabb0d04f965
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 SIZE = 1234567L
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 fileInfo = FileInfo.forFile(NAME, SIZE, LAST_MODIFIED)
41        def sizeStr = SIZE.toString().padLeft(SIZE_WIDTH)
42        def expected = "$lastModifiedFormatted  $sizeStr  $NAME"
43        def result = formatter.format(fileInfo)
44        LOG.info("result=$result")
45        assert result == expected
46    }
47
48    void testFormat_Directory() {
49        def fileInfo = FileInfo.forDirectory(NAME, LAST_MODIFIED)
50        def dirStr = "<DIR>".padRight(SIZE_WIDTH)
51        def expected = "$lastModifiedFormatted  $dirStr  $NAME"
52        def result = formatter.format(fileInfo)
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}