Project

General

Profile

Download (4.38 KB) Statistics
| Branch: | Tag: | Revision:
1
//package eu.etaxonomy.cdm.hibernate;
2
//
3
//import static org.junit.Assert.*;
4
//
5
//import org.junit.Test;
6
//
7
//import static org.hamcrest.Matchers.*;
8
//import static org.junit.Assert.*;
9
//import static org.mockito.Mockito.*;
10
//
11
//import java.math.*;
12
//import java.sql.*;
13
//
14
//import org.hibernate.usertype.*;
15
//import org.junit.*;
16
//import org.junit.runner.*;
17
//import org.mockito.*;
18
//import org.mockito.runners.*;
19
//
20
///**
21
// * This software is public domain and carries NO WARRANTY.
22
// *
23
// * Patches, bug reports and feature requests welcome:
24
// *
25
// * https://bitbucket.org/ratkins/bigdecimalusertype/
26
// */
27
//@RunWith(MockitoJUnitRunner.class)
28
//public class BigDecimalUserTypeTest {
29
//	
30
//	@Mock ResultSet rs;
31
//	@Mock PreparedStatement st;
32
//	
33
//	private UserType userType;
34
//
35
//	@Before
36
//	public void setUp() throws Exception {
37
//		userType = new BigDecimalUserType();
38
//	}
39
//	
40
//	@Test
41
//	public void testNotMutable() throws Exception {
42
//		assertThat(userType.isMutable(), equalTo(false));
43
//	}
44
//	
45
//	@Test
46
//	public void testDeepCopyReturnsSelf() throws Exception {
47
//		BigDecimal foo = new BigDecimal("1.0");
48
//		assertThat((BigDecimal) userType.deepCopy(foo), sameInstance(foo));
49
//	}
50
//	
51
//	@Test
52
//	public void testReturnedClassIsBigDecimal() throws Exception {
53
////		The Eclipse compiler passes this, the jdk on the command line one doesn't
54
////		assertThat(userType.returnedClass(), equalTo(BigDecimal.class));
55
//		assertTrue(userType.returnedClass() == BigDecimal.class);
56
//	}
57
//	
58
//	@Test
59
//	public void testEqualsDelegatesToBigDecimalEquals() throws Exception {
60
//		assertThat(userType.equals(new BigDecimal("1.0"), new BigDecimal("1.0")), equalTo(true));
61
//		assertThat(userType.equals(new BigDecimal("1.0"), new BigDecimal("2.0")), equalTo(false));
62
//		assertThat(userType.equals(new BigDecimal("1.0"), new BigDecimal("1.00")), equalTo(false));
63
//	}
64
//	
65
//	@Test
66
//	public void testHashCodeDelegatesToBigDecimalHashCode() throws Exception {
67
//		assertThat(userType.hashCode(new BigDecimal("1.0")), equalTo(new BigDecimal("1.0").hashCode()));
68
//		assertThat(userType.hashCode(new BigDecimal("1.00")), not(equalTo(new BigDecimal("1.0").hashCode())));
69
//		assertThat(userType.hashCode(new BigDecimal("1.0")), not(equalTo(new BigDecimal("2.0").hashCode())));
70
//	}
71
//	
72
//	@Test
73
//	public void testAssembleReturnsSelf() throws Exception {
74
//		BigDecimal foo = new BigDecimal("1.0");
75
//		assertThat((BigDecimal) userType.assemble(foo, null), sameInstance(foo));
76
//	}
77
//	
78
//	@Test
79
//	public void testDisassembleReturnsSelf() throws Exception {
80
//		BigDecimal foo = new BigDecimal("1.0");
81
//		assertThat((BigDecimal) userType.disassemble(foo), sameInstance(foo));
82
//		assertThat((BigDecimal) userType.disassemble(null), equalTo((BigDecimal) null));
83
//	}
84
//	
85
//	@Test
86
//	public void testReplaceReturnsSelf() throws Exception {
87
//		BigDecimal foo = new BigDecimal("1.0");
88
//		assertThat((BigDecimal) userType.replace(foo, null, null), sameInstance(foo));
89
//		assertThat((BigDecimal) userType.disassemble(null), equalTo((BigDecimal) null));
90
//	}
91
//	
92
//	@Test
93
//	public void testSqlTypesAreNumberAndInteger() throws Exception {
94
//		assertThat(userType.sqlTypes().length, equalTo(2));
95
//		assertThat(userType.sqlTypes()[0], equalTo(Types.DECIMAL));
96
//		assertThat(userType.sqlTypes()[1], equalTo(Types.INTEGER));
97
//	}
98
//	
99
//	@Test
100
//	public void testNullSafeGet() throws Exception {
101
//		when(rs.getBigDecimal("a")).thenReturn(new BigDecimal("1.000000"));
102
//		when(rs.getInt("b")).thenReturn(1);
103
//		
104
//		assertThat((BigDecimal) userType.nullSafeGet(rs, new String[] {"a", "b"}, null), equalTo(new BigDecimal("1.0")));
105
//	}
106
//
107
//	@Test
108
//	public void testNullSafeGetWithNull() throws Exception {
109
//		when(rs.getBigDecimal("a")).thenReturn(null);
110
//		when(rs.getInt("b")).thenReturn(0);
111
//		
112
//		assertThat((BigDecimal) userType.nullSafeGet(rs, new String[] {"a", "b"}, null), equalTo((BigDecimal) null));
113
//	}
114
//	
115
//	@Test
116
//	public void testNullSafeSet() throws Exception {
117
//		userType.nullSafeSet(st, new BigDecimal("1.000"), 17);
118
//		
119
//		verify(st).setBigDecimal(17, new BigDecimal("1.000"));
120
//		verify(st).setInt(18, 3);
121
//	}
122
//
123
//	@Test
124
//	public void testNullSafeSetWithNull() throws Exception {
125
//		userType.nullSafeSet(st, null, 17);
126
//		
127
//		verify(st).setNull(17, Types.DECIMAL);
128
//		verify(st).setNull(18, Types.INTEGER);
129
//	}
130
//}
(1-1/3)