use of org.dbflute.mock.MockValueType in project dbflute-core by dbflute.
the class TnValueTypesTest method test_getValueType_byInstance_enum_priority_plain.
public void test_getValueType_byInstance_enum_priority_plain() throws Exception {
// ## Arrange ##
Class<?> keyType = TestPlainStatus.class;
MockValueType mockValueType = new MockValueType();
// ## Act ##
TnValueTypes.registerBasicValueType(_currentDBDef, keyType, mockValueType);
ValueType valueType = TnValueTypes.getValueType(TestPlainStatus.FML);
// ## Assert ##
assertNotSame(TnValueTypes.CLASSIFICATION, valueType);
assertEquals(mockValueType, valueType);
}
use of org.dbflute.mock.MockValueType in project dbflute-core by dbflute.
the class TnScalarDynamicResultSetHandlerTest method test_handle_scalar.
public void test_handle_scalar() throws SQLException {
// ## Arrange ##
MockValueType valueType = new MockValueType() {
@Override
public Object getValue(ResultSet resultSet, int index) throws SQLException {
assertEquals(1, index);
return 99;
}
};
TnScalarDynamicResultSetHandler handler = new TnScalarDynamicResultSetHandler(valueType) {
@Override
protected <ELEMENT> List<ELEMENT> newArrayList() {
fail("should not be called");
return null;
}
};
MockResultSet rs = new MockResultSet() {
private boolean called;
@Override
public boolean next() throws SQLException {
try {
return !called;
} finally {
called = true;
}
}
};
// ## Act ##
Object actual = handler.handle(rs);
// ## Assert ##
log("actual=" + actual);
assertEquals(99, actual);
}
use of org.dbflute.mock.MockValueType in project dbflute-core by dbflute.
the class TnScalarDynamicResultSetHandlerTest method test_handle_scalarList.
public void test_handle_scalarList() throws SQLException {
// ## Arrange ##
MockValueType valueType = new MockValueType() {
private int count = 0;
@Override
public Object getValue(ResultSet resultSet, int index) throws SQLException {
// 1, 2, 3, ...
return ++count;
}
};
final String mark = "called";
final Set<String> markSet = new HashSet<String>();
TnScalarDynamicResultSetHandler handler = new TnScalarDynamicResultSetHandler(valueType) {
@Override
protected <ELEMENT> List<ELEMENT> newArrayList() {
if (markSet.contains(mark)) {
fail("should not be called twice");
}
markSet.add(mark);
return super.newArrayList();
}
};
MockResultSet rs = new MockResultSet() {
private List<Integer> countList = new ArrayList<Integer>();
{
countList.add(1);
countList.add(2);
countList.add(3);
}
@Override
public boolean next() throws SQLException {
if (countList.isEmpty()) {
return false;
}
countList.remove(0);
return true;
}
};
// ## Act ##
Object actual = handler.handle(rs);
// ## Assert ##
log("actual=" + actual);
assertEquals(Arrays.asList(new Integer[] { 1, 2, 3 }), actual);
assertTrue(markSet.contains(mark));
}
use of org.dbflute.mock.MockValueType in project dbflute-core by dbflute.
the class TnValueTypesTest method test_getValueType_byClassType_enum_priority_plain.
public void test_getValueType_byClassType_enum_priority_plain() throws Exception {
// ## Arrange ##
Class<?> keyType = TestPlainStatus.class;
MockValueType mockValueType = new MockValueType();
// ## Act ##
TnValueTypes.registerBasicValueType(_currentDBDef, keyType, mockValueType);
ValueType valueType = TnValueTypes.getValueType(keyType);
// ## Assert ##
assertNotSame(TnValueTypes.CLASSIFICATION, valueType);
assertEquals(mockValueType, valueType);
}
Aggregations