1 | package com.ether; |
---|
2 | |
---|
3 | import org.junit.Assert; |
---|
4 | import org.junit.Test; |
---|
5 | |
---|
6 | import java.text.DateFormat; |
---|
7 | import java.text.SimpleDateFormat; |
---|
8 | import java.util.ArrayList; |
---|
9 | import java.util.Calendar; |
---|
10 | import java.util.Date; |
---|
11 | import java.util.HashSet; |
---|
12 | import java.util.List; |
---|
13 | import java.util.Set; |
---|
14 | |
---|
15 | /** |
---|
16 | * @author vmipsl |
---|
17 | * @date 2011 |
---|
18 | */ |
---|
19 | public class OtherTest |
---|
20 | { |
---|
21 | @Test |
---|
22 | public void testDatesMoisPlusUn() |
---|
23 | throws Exception |
---|
24 | { |
---|
25 | final DateFormat shortDateFormat = new SimpleDateFormat( "MMyyyy" ); |
---|
26 | final DateFormat completDateFormat = new SimpleDateFormat( "dd-MM-yyyy" ); |
---|
27 | final Date firstMois = shortDateFormat.parse( "102008" ); |
---|
28 | final String firstMoisString = completDateFormat.format( firstMois ); |
---|
29 | Assert.assertEquals( firstMoisString, "01-10-2008" ); |
---|
30 | |
---|
31 | final Calendar calendar = Calendar.getInstance(); |
---|
32 | calendar.setTime( firstMois ); |
---|
33 | calendar.add( Calendar.MONTH, 1 ); |
---|
34 | final Date secondMois = calendar.getTime(); |
---|
35 | final String secondMoisString = completDateFormat.format( secondMois ); |
---|
36 | Assert.assertEquals( secondMoisString, "01-11-2008" ); |
---|
37 | } |
---|
38 | |
---|
39 | @Test |
---|
40 | public void testDates() |
---|
41 | throws Exception |
---|
42 | { |
---|
43 | List<Date> dates = new ArrayList<Date>(); |
---|
44 | final DateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd" ); |
---|
45 | |
---|
46 | dates.add( dateFormat.parse( "2007-01-01" ) ); |
---|
47 | dates.add( dateFormat.parse( "2007-01-02" ) ); |
---|
48 | |
---|
49 | final DateFormat shortFormat = new SimpleDateFormat( "yyyy" ); |
---|
50 | Set<String> shortDates = new HashSet<String>(); |
---|
51 | for ( final Date aDate : dates ) |
---|
52 | { |
---|
53 | shortDates.add( shortFormat.format( aDate ) ); |
---|
54 | } |
---|
55 | } |
---|
56 | } |
---|