blob: 04eed350e1213abe4d73188ec53e19a3bd994b3c [file] [log] [blame]
chrismair00dc7bd2014-05-11 21:21:28 +00001/*
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.AbstractGroovyTestCase
20
21/**
22 * Tests for WindowsDirectoryListingFormatter
23 *
24 * @version $Revision$ - $Date$
25 *
26 * @author Chris Mair
27 */
28class WindowsDirectoryListingFormatterTest extends AbstractGroovyTestCase {
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 private defaultLocale
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 testFormat_File_NonEnglishDefaultLocale() {
59 Locale.setDefault(Locale.GERMAN)
60 def fileEntry = new FileEntry(path: PATH, contents: 'abcd', lastModified: LAST_MODIFIED)
61 def sizeStr = 4.toString().padLeft(SIZE_WIDTH)
62 def expected = "$lastModifiedFormatted $sizeStr $NAME"
63 def result = formatter.format(fileEntry)
64 LOG.info("result=$result")
65 assert result == expected
66 }
67
68 void setUp() {
69 super.setUp()
70 formatter = new WindowsDirectoryListingFormatter()
71 dateFormat = new SimpleDateFormat(WindowsDirectoryListingFormatter.DATE_FORMAT)
72 lastModifiedFormatted = dateFormat.format(LAST_MODIFIED)
73 defaultLocale = Locale.default
74 }
75
76 void tearDown() {
77 super.tearDown()
78 Locale.setDefault(defaultLocale)
79 }
80
81}