@Test public void testBindBean() { assertThat( dao.insert(ImmutableTrain.builder() .name("Zephyr") .carriages(8) .observationCar(true) .build())) .isEqualTo(1); assertThat(dao.getTrains().get(0)) .extracting("name", "carriages", "observationCar") .containsExactly("Zephyr", 8, true); }
/** * Fill a builder with attribute values from the provided {@code Train} instance. * Regular attribute values will be replaced with those from the given instance. * Absent optional values will not replace present values. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder from(ImmutablesTest.Train instance) { Objects.requireNonNull(instance, "instance"); name(instance.name()); carriages(instance.carriages()); observationCar(instance.observationCar()); return this; }
@Test public void simpleTest() { jdbi.getConfig(JdbiImmutables.class).registerImmutable(Train.class); try (Handle handle = jdbi.open()) { handle.execute("create table train (name varchar, carriages int, observation_car boolean)"); assertThat( handle.createUpdate("insert into train(name, carriages, observation_car) values (:name, :carriages, :observationCar)") .bindPojo(ImmutableTrain.builder().name("Zephyr").carriages(8).observationCar(true).build()) .execute()) .isEqualTo(1); assertThat( handle.createQuery("select * from train") .mapTo(Train.class) .findOnly()) .extracting("name", "carriages", "observationCar") .containsExactly("Zephyr", 8, true); } } // end::example[]
@Test public void testBindBean() { assertThat( dao.insert(ImmutableTrain.builder() .name("Zephyr") .carriages(8) .observationCar(true) .build())) .isEqualTo(1); assertThat(dao.getTrains().get(0)) .extracting("name", "carriages", "observationCar") .containsExactly("Zephyr", 8, true); }