source: ether_2012/service/test/com/ether/OtherTest.java @ 319

Last change on this file since 319 was 319, checked in by vmipsl, 12 years ago

Import du projet Ether pour le nouveau look 2012

File size: 1.7 KB
Line 
1package com.ether;
2
3import org.junit.Assert;
4import org.junit.Test;
5
6import java.text.DateFormat;
7import java.text.SimpleDateFormat;
8import java.util.ArrayList;
9import java.util.Calendar;
10import java.util.Date;
11import java.util.HashSet;
12import java.util.List;
13import java.util.Set;
14
15/**
16 * @author vmipsl
17 * @date 2011
18 */
19public 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}
Note: See TracBrowser for help on using the repository browser.