Changeset 3142 for AnalyzerBeans


Ignore:
Timestamp:
02/07/12 10:30:06 (4 months ago)
Author:
kasper
Message:

Made unittest locale-independent

File:
1 edited

Legend:

Unmodified
Added
Removed
  • AnalyzerBeans/trunk/core/src/test/java/org/eobjects/analyzer/beans/transform/TimestampConverterTest.java

    r2777 r3142  
    2222import java.text.SimpleDateFormat; 
    2323import java.util.Date; 
     24import java.util.TimeZone; 
    2425 
    2526import org.eobjects.analyzer.beans.transform.TimestampConverter.Unit; 
     
    3132public class TimestampConverterTest extends TestCase { 
    3233 
     34        private TimeZone _defaultTimeZone; 
     35 
     36        protected void setUp() throws Exception { 
     37                _defaultTimeZone = TimeZone.getDefault(); 
     38                TimeZone.setDefault(TimeZone.getTimeZone("UTC")); 
     39        }; 
     40 
     41        @Override 
     42        protected void tearDown() throws Exception { 
     43                TimeZone.setDefault(_defaultTimeZone); 
     44        } 
     45 
    3346        public void testTransform() throws Exception { 
    3447                TimestampConverter trans = new TimestampConverter(); 
    35                 MockInputColumn<Object> col = new MockInputColumn<Object>("my timestamps", Object.class); 
     48                MockInputColumn<Object> col = new MockInputColumn<Object>( 
     49                                "my timestamps", Object.class); 
    3650                trans.timestampColumn = col; 
    37                  
     51 
    3852                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); 
    39                  
     53 
    4054                Date[] result; 
    4155                result = trans.transform(new MockInputRow().put(col, "1320244696")); 
    4256                assertEquals(1, result.length); 
    43                 assertEquals("2011-11-02 15:38", dateFormat.format(result[0])); 
    44                  
     57                assertEquals("2011-11-02 14:38", dateFormat.format(result[0])); 
     58 
    4559                result = trans.transform(new MockInputRow().put(col, 1234)); 
    4660                assertEquals(1, result.length); 
    47                 assertEquals("1970-01-01 01:20", dateFormat.format(result[0])); 
    48                  
     61                assertEquals("1970-01-01 00:20", dateFormat.format(result[0])); 
     62 
    4963                result = trans.transform(new MockInputRow().put(col, null)); 
    5064                assertEquals(1, result.length); 
    5165                assertNull(result[0]); 
    52                  
     66 
    5367                result = trans.transform(new MockInputRow().put(col, "foobar")); 
    5468                assertEquals(1, result.length); 
    5569                assertNull(result[0]); 
    56                  
     70 
    5771                trans.unit = Unit.DAYS; 
    5872                result = trans.transform(new MockInputRow().put(col, 20)); 
    5973                assertEquals(1, result.length); 
    60                 assertEquals("1970-01-21 01:00", dateFormat.format(result[0])); 
     74                assertEquals("1970-01-21 00:00", dateFormat.format(result[0])); 
    6175        } 
    6276} 
Note: See TracChangeset for help on using the changeset viewer.