### Question:
ScalarProvider extends AbstractObjectProvider<CONTAINER> { @Override public CONTAINER get(ResultSet resultSet) throws SQLException { if (!columnCountValidated) { validateColumnCount(resultSet); } Scalar<BASIC, CONTAINER> scalar = supplier.get(); fetch(resultSet, scalar, 1, jdbcMappingVisitor); return scalar.get(); } ScalarProvider(Supplier<Scalar<BASIC, CONTAINER>> supplier, Query query); @Override CONTAINER get(ResultSet resultSet);  }### Answer:
@Test public void testBasic() throws Exception { MockResultSetMetaData metaData = new MockResultSetMetaData(); metaData.columns.add(new ColumnMetaData("aaa")); MockResultSet resultSet = new MockResultSet(metaData); resultSet.rows.add(new RowData("hoge")); resultSet.next(); ScalarProvider<String, String> provider = new ScalarProvider<>( () -> new org.seasar.doma.internal.jdbc.scalar.BasicScalar<>(StringWrapper::new), new MySelectQuery()); String result = provider.get(resultSet); assertEquals("hoge", result); }
@Test public void testOptionalBasic() throws Exception { MockResultSetMetaData metaData = new MockResultSetMetaData(); metaData.columns.add(new ColumnMetaData("aaa")); MockResultSet resultSet = new MockResultSet(metaData); resultSet.rows.add(new RowData("hoge")); resultSet.next(); ScalarProvider<String, Optional<String>> provider = new ScalarProvider<>( () -> new org.seasar.doma.internal.jdbc.scalar.OptionalBasicScalar<>(StringWrapper::new), new MySelectQuery()); Optional<String> result = provider.get(resultSet); assertEquals("hoge", result.get()); }
@Test public void testDomain() throws Exception { MockResultSetMetaData metaData = new MockResultSetMetaData(); metaData.columns.add(new ColumnMetaData("aaa")); MockResultSet resultSet = new MockResultSet(metaData); resultSet.rows.add(new RowData("hoge")); resultSet.next(); DomainType<String, PhoneNumber> domainType = _PhoneNumber.getSingletonInternal(); ScalarProvider<String, PhoneNumber> provider = new ScalarProvider<>(domainType::createScalar, new MySelectQuery()); PhoneNumber result = provider.get(resultSet); assertEquals("hoge", result.getValue()); }
@Test public void testOptionalDomain() throws Exception { MockResultSetMetaData metaData = new MockResultSetMetaData(); metaData.columns.add(new ColumnMetaData("aaa")); MockResultSet resultSet = new MockResultSet(metaData); resultSet.rows.add(new RowData("hoge")); resultSet.next(); DomainType<String, PhoneNumber> domainType = _PhoneNumber.getSingletonInternal(); ScalarProvider<String, Optional<PhoneNumber>> provider = new ScalarProvider<>(domainType::createOptionalScalar, new MySelectQuery()); Optional<PhoneNumber> result = provider.get(resultSet); assertEquals("hoge", result.get().getValue()); }