View Javadoc
1   package org.melati.poem.test;
2   
3   import java.sql.Types;
4   import java.util.Enumeration;
5   
6   import org.melati.poem.DisplayLevelPoemType;
7   import org.melati.poem.IntegerPoemType;
8   import org.melati.poem.ParsingPoemException;
9   import org.melati.poem.SQLPoemType;
10  import org.melati.poem.TypeMismatchPoemException;
11  
12  /**
13   * @author timp
14   * @since 21 Dec 2006
15   *
16   */
17  public class NotNullableIntegerPoemTypeTest extends SQLPoemTypeSpec<Integer> {
18  
19    public NotNullableIntegerPoemTypeTest() {
20    }
21  
22    public NotNullableIntegerPoemTypeTest(String name) {
23      super(name);
24    }
25  
26    void setObjectUnderTest() {
27      it = new IntegerPoemType(false);
28    }
29  
30    /**
31     * Test method for {@link org.melati.poem.PoemType#canRepresent(org.melati.poem.PoemType)}.
32     */
33    public void testCanRepresent() {
34      assertTrue(it.canRepresent(new DisplayLevelPoemType()) instanceof IntegerPoemType);
35    }
36  
37    /**
38     * Only way to get doubleChecked to throw. 
39     * {@inheritDoc}
40     * @see org.melati.poem.test.SQLPoemTypeSpec#testRawOfCooked()
41     */
42    public void testRawOfCooked() {
43      super.testRawOfCooked();
44      try { 
45        it.rawOfCooked(new Long(0));
46        fail("should have blown up");
47      } catch (TypeMismatchPoemException e) { 
48        e = null;
49      }
50    }
51  
52    /**
53     * Test method for {@link org.melati.poem.SQLType#quotedRaw(java.lang.Object)}.
54     */
55    public void testQuotedRaw() {
56      assertEquals(((SQLPoemType<Integer>)it).sqlDefaultValue(getDb().getDbms()) , 
57          ((SQLPoemType<Integer>)it).quotedRaw(((SQLPoemType<Integer>)it).rawOfString(
58                  ((SQLPoemType<Integer>)it).sqlDefaultValue(getDb().getDbms()))));
59  
60    }
61  
62    public void testPossibleRaws() {
63      super.testPossibleRaws();
64      Enumeration<Integer> them = ((IntegerPoemType)it).possibleRaws();
65      if (!it.getNullable())
66        assertNull(them);
67      ((IntegerPoemType)it).setRawRange(new Integer(Integer.MAX_VALUE -5), (Integer)null);
68      them = it.possibleRaws();
69      int counter = 0;
70      while(them.hasMoreElements()) {
71        them.nextElement();
72        counter++;
73      }
74      if (it.getNullable())
75        assertEquals(6,counter);
76      else
77        assertEquals(5,counter);
78      ((IntegerPoemType)it).setRawRange(new Integer(2), new Integer(5));
79      them = it.possibleRaws();
80      counter = 0;
81      while(them.hasMoreElements()) {
82        them.nextElement();
83        counter++;
84      }
85      if (it.getNullable())
86        assertEquals(4,counter);
87      else
88        assertEquals(3,counter);
89    }
90  
91  
92    public void testRawOfString() {
93      super.testRawOfString();
94      try{
95        it.rawOfString("kk");
96        fail("Should have blown up");
97      } catch (ParsingPoemException e) {
98        e = null;
99      }
100     
101   }
102   /**
103    * Test full constructor.
104    */
105   public void testFullConstructor() {
106     IntegerPoemType it2 = new MyIntegerPoemType(it.getNullable());
107     assertEquals(it.getNullable(),it2.getNullable());
108   }
109   class MyIntegerPoemType extends IntegerPoemType {
110 
111     public MyIntegerPoemType(boolean nullable) {
112       super(Types.INTEGER, "INT", nullable);
113     }
114     
115   }
116 }