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