View Javadoc
1   package org.melati.poem.test;
2   
3   import java.sql.Time;
4   import java.sql.Types;
5   import java.text.DateFormat;
6   
7   import org.melati.poem.ParsingPoemException;
8   import org.melati.poem.PoemLocale;
9   import org.melati.poem.SQLPoemType;
10  import org.melati.poem.TimePoemType;
11  
12  /**
13   * @author timp
14   * @since 2011/06/11
15   *
16   */
17  public class NotNullableTimePoemTypeTest extends SQLPoemTypeSpec<Time> {
18  
19    public NotNullableTimePoemTypeTest() {
20    }
21  
22    public NotNullableTimePoemTypeTest(String name) {
23      super(name);
24    }
25  
26    /**
27     * {@inheritDoc}
28     * @see org.melati.poem.test.SQLPoemTypeSpec#setObjectUnderTest()
29     */
30    void setObjectUnderTest() {
31      it = new TimePoemType(false);
32    }
33  
34    public void testStringOfCooked() {
35      super.testStringOfCooked();
36      long now = System.currentTimeMillis();
37      Time nowT = new Time(now);
38      String result = it.stringOfCooked(nowT, PoemLocale.HERE, DateFormat.MEDIUM);
39      int expected = 20;
40      if (System.getProperty("java.version").startsWith("11")) {
41        expected = 21;
42      }
43      assertEquals(result,expected, result.length());
44    }
45  
46    /**
47     * Test method for {@link org.melati.poem.SQLType#quotedRaw(java.lang.Object)}.
48     */
49    public void testQuotedRaw() {
50      long now = System.currentTimeMillis();
51      Time nowT = new Time(now);
52      assertEquals("'" + TimePoemType.format.format(nowT) + "'", 
53          ((SQLPoemType<Time>)it).quotedRaw(nowT));
54  
55    }
56  
57    public void testAssertValidCooked() {
58      super.testAssertValidCooked();
59    }
60  
61    public void testPossibleRaws() {
62      super.testPossibleRaws();
63      
64    }
65    public void testRawOfString() {
66      super.testRawOfString();
67      try{
68        it.rawOfString("kk");
69        fail("Should have blown up");
70      } catch (ParsingPoemException e) {
71        e = null;
72      }
73      
74    }
75  
76    public void testRawOfCooked() {
77      super.testRawOfCooked();
78    }
79  
80    /**
81     * Test the full constructor. 
82     */
83    public void testFullConstructor() {
84      TimePoemType it2 = new MyTimePoemType(it.getNullable());
85      assertEquals(it.getNullable(),it2.getNullable());
86    }
87    class MyTimePoemType extends TimePoemType {
88  
89      public MyTimePoemType(boolean nullable) {
90        super(Types.TIME, "TIME", nullable);
91      }
92      
93    }
94  }