summaryrefslogtreecommitdiffstats
blob: 53d6c7ad9fc2aec072347fe69c530c7203c677d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package org.eclipse.stardust.engine.core.persistence.jdbc;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

import java.sql.PreparedStatement;
import java.sql.SQLException;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;

public class DmlManagerTest
{
   private DBDescriptor dbDescriptor;

   @Mock
   PreparedStatement statement;

   @Before
   public void setup()
   {
      dbDescriptor = new DerbyDbDescriptor();
   }

   @Test
   public void testGetDoubleSQLValue()
   {
      assertEquals(new String("-2.225E-307"), getSQLValue(-2.225E-307));
      assertEquals(new String("2.225E-307"), getSQLValue(2.225E-307));
      assertEquals(new String("0.0"), getSQLValue(-439E-324));
      assertEquals(new String("0.0"), getSQLValue(439E-324));
      assertEquals(new String("-2.225E-300"), getSQLValue(-2.225E-300));
      assertEquals(new String("2.225E-300"), getSQLValue(2.225E-300));
      assertEquals(new String("-0.4567"), getSQLValue(-0.4567));
      assertEquals(new String("0.4567"), getSQLValue(0.4567));
      assertEquals(new String("25.123"), getSQLValue(25.123));
      assertEquals(new String("-25.123"), getSQLValue(-25.123));
   }

   private String getSQLValue(Object value)
   {
      return DmlManager.getSQLValue(Double.class, value, dbDescriptor);
   }

   @Test
   public void testSetSQLValuePreparedStatement() throws SQLException
   {
      assertSetSQLValue(-2.225E-307, -2.225E-307);
      assertSetSQLValue(2.225E-307, 2.225E-307);
      assertSetSQLValue(-2.225E-308, 0.0);
      assertSetSQLValue(2.225E-308, 0.0);
      assertSetSQLValue(-439E-324, 0.0);
      assertSetSQLValue(439E-324, 0.0);
      assertSetSQLValue(-2.225E-300, -2.225E-300);
      assertSetSQLValue(2.225E-300, 2.225E-300);
      assertSetSQLValue(-0.4567, -0.4567);
      assertSetSQLValue(0.4567, 0.4567);
      assertSetSQLValue(25.123, 25.123);
      assertSetSQLValue(-25.123, -25.123);
   }

   private void assertSetSQLValue(Double value, Double expected) throws SQLException
   {
      statement = mock(PreparedStatement.class);
      DmlManager.setSQLValue(statement, 1, Double.class, value, dbDescriptor);
      verify(statement).setDouble(1, expected);
   }

}