17
17
*/
18
18
19
19
import junit .framework .TestCase ;
20
+
21
+ import org .codehaus .plexus .components .io .attributes .AttributeParser .NumericUserIDAttributeParser ;
20
22
import org .codehaus .plexus .logging .Logger ;
21
23
import org .codehaus .plexus .logging .console .ConsoleLogger ;
22
24
import org .codehaus .plexus .util .Os ;
@@ -33,6 +35,25 @@ public class PlexusIoResourceAttributeUtilsTest
33
35
extends TestCase
34
36
{
35
37
38
+ private Locale origSystemLocale ;
39
+
40
+ @ Override
41
+ protected void setUp ()
42
+ throws Exception
43
+ {
44
+ this .origSystemLocale = Locale .getDefault ();
45
+ // sample ls output files have US date format and we use SimpleDateFormt with system locale for ls date format parsing
46
+ // otherwise test could fail on systems with non-US locales
47
+ Locale .setDefault ( Locale .US );
48
+ }
49
+
50
+ @ Override
51
+ protected void tearDown ()
52
+ throws Exception
53
+ {
54
+ Locale .setDefault ( origSystemLocale );
55
+ }
56
+
36
57
public void testGetAttributesForThisTestClass ()
37
58
throws IOException
38
59
{
@@ -147,6 +168,32 @@ public void testSingleLine()
147
168
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream ( output .getBytes () );
148
169
AttributeParser parser = getNumericParser ();
149
170
parse ( byteArrayInputStream , parser );
171
+ }
172
+
173
+ public void testReversedMonthDayOrder ()
174
+ throws Exception
175
+ {
176
+ String output = //
177
+ "-rw-r--r-- 1 501 80 7683 31 May 10:06 pom_newer.xml\n " + //
178
+ "-rwxr--r-- 1 502 81 7683 1 Jun 2010 pom_older.xml" ;
179
+ InputStream byteArrayInputStream = new ByteArrayInputStream ( output .getBytes () );
180
+ NumericUserIDAttributeParser parser = getNumericParser ();
181
+ parse ( byteArrayInputStream , parser );
182
+ Map <String , PlexusIoResourceAttributes > map = parser .getAttributesByPath ();
183
+
184
+ // 6 months or newer ls date format
185
+ FileAttributes newerFileAttr = (FileAttributes ) map .get ( "pom_newer.xml" );
186
+ assertNotNull ( newerFileAttr );
187
+ assertEquals ( "-rw-r--r--" , new String ( newerFileAttr .getLsModeParts () ) );
188
+ assertEquals ( 501 , newerFileAttr .getUserId ().intValue () );
189
+ assertEquals ( 80 , newerFileAttr .getGroupId ().intValue () );
190
+
191
+ // older than 6 months ls date format
192
+ FileAttributes olderFileAttr = (FileAttributes ) map .get ( "pom_older.xml" );
193
+ assertNotNull ( olderFileAttr );
194
+ assertEquals ( "-rwxr--r--" , new String ( olderFileAttr .getLsModeParts () ) );
195
+ assertEquals ( 502 , olderFileAttr .getUserId ().intValue () );
196
+ assertEquals ( 81 , olderFileAttr .getGroupId ().intValue () );
150
197
}
151
198
152
199
public void testOddLinuxFormatWithExtermelyLargeNumericsSingleLine ()
0 commit comments