### Question:
AbstractArgumentFactory implements ArgumentFactory.Preparable { @Override public final Optional<Argument> build(Type type, Object value, ConfigRegistry config) { if (!isInstance.test(type, value)) { return Optional.empty(); } return innerBuild(value, config); } protected  AbstractArgumentFactory(int sqlType); @Override Optional<Function<Object, Argument>> prepare(Type type, ConfigRegistry config); @Override Collection<Type> prePreparedTypes(); @Override final Optional<Argument> build(Type type, Object value, ConfigRegistry config);  }### Answer:
@Test public void testExpectedClass() throws SQLException { Argument argument = new SimpleArgumentFactory().build(SimpleType.class, new SimpleType("foo"), config).orElse(null); assertThat(argument).isNotNull(); argument.apply(1, statement, ctx); verify(statement).setString(1, "foo"); }
@Test public void testObjectClassWithInstanceOfExpectedType() throws SQLException { Argument argument = new SimpleArgumentFactory().build(Object.class, new SimpleType("bar"), config).orElse(null); assertThat(argument).isNotNull(); argument.apply(2, statement, ctx); verify(statement).setString(2, "bar"); }
@Test public void testNullOfExpectedClass() throws SQLException { Argument argument = new SimpleArgumentFactory().build(SimpleType.class, null, config).orElse(null); assertThat(argument).isNotNull(); argument.apply(3, statement, ctx); verify(statement).setNull(3, Types.VARCHAR); }
@Test public void testValueOfDifferentType() { assertThat(new SimpleArgumentFactory().build(int.class, 1, config)).isEmpty(); }
@Test public void testNullOfDifferentType() { assertThat(new SimpleArgumentFactory().build(Integer.class, null, config)).isEmpty(); }
@Test public void testExpectedGenericType() throws SQLException { Argument argument = new BoxOfStringArgumentFactory().build(BOX_OF_STRING_TYPE, new Box<>("foo"), config).orElse(null); assertThat(argument).isNotNull(); argument.apply(1, statement, ctx); verify(statement).setString(1, "foo"); }
@Test public void testExpectedGenericTypeWithDifferentParameter() { assertThat(new BoxOfStringArgumentFactory().build(BOX_OF_OBJECT_TYPE, new Box<Object>("foo"), config)) .isEmpty(); }
@Test public void testNullOfExpectedGenericType() throws SQLException { Argument argument = new BoxOfStringArgumentFactory().build(BOX_OF_STRING_TYPE, null, config).orElse(null); assertThat(argument).isNotNull(); argument.apply(2, statement, ctx); verify(statement).setNull(2, Types.VARCHAR); }