source: ether_megapoli/trunk/service/test/com/ether/OtherTest.java @ 171

Last change on this file since 171 was 171, checked in by vmipsl, 13 years ago

Fixe application : english/french _ ok before applet

File size: 3.4 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
57    /**
58     * Test transform List<Pair> en Pair<List, List>
59     * Method used in getListsByPlateformByParameterByPeriodForTimeSerie
60     */
61    @Test
62    public void testListPairToPairLists()
63    {
64        final List<Object[]> objects = new ArrayList<Object[]>( 3 );
65        final Object[] obj1 = new Object[2];
66        obj1[0] = 2.2;
67        obj1[1] = new Date();
68        objects.add( obj1 );
69
70        final Object[] obj2 = new Object[2];
71        obj2[0] = 2.5;
72        obj2[1] = new Date();
73        objects.add( obj2 );
74
75        final Object[] obj3 = new Object[2];
76        obj3[0] = 2.7;
77        obj3[1] = new Date();
78        objects.add( obj3 );
79
80        if( objects.get( 0 )[0] instanceof Double && objects.get( 0 )[1] instanceof Date )
81        {
82            final double[] firstValues = new double[objects.size()];
83            final Date[] secondValues = new Date[objects.size()];
84            int i = 0;
85            for( final Object[] value : objects )
86            {
87                secondValues[i] = (Date) value[1];
88                firstValues[i] = (Double) value[0];
89                i++;
90            }
91            final Pair<double[], Date[]> values = new Pair( firstValues, secondValues );
92
93            Assert.assertEquals( values.getFirstValue().length, objects.size() );
94            Assert.assertEquals( values.getSecondValue().length, objects.size() );
95            Assert.assertEquals( values.getFirstValue()[0], obj1[0] );
96            Assert.assertEquals( values.getSecondValue()[0], obj1[1] );
97            Assert.assertEquals( values.getFirstValue()[1], obj2[0] );
98            Assert.assertEquals( values.getSecondValue()[1], obj2[1] );
99            Assert.assertEquals( values.getFirstValue()[2], obj3[0] );
100            Assert.assertEquals( values.getSecondValue()[2], obj3[1] );
101        }
102
103    }
104}
Note: See TracBrowser for help on using the repository browser.