@Test public void testGetterStyle() { final Getter expected = Getter.builder().setFoo(42).setBar(true).build(); h.execute("create table getter(foo int, bar boolean)"); assertThat(h.createUpdate("insert into getter(foo, bar) values (:foo, :bar)") .bindPojo(expected) .execute()) .isEqualTo(1); assertThat(h.createQuery("select * from getter") .mapTo(Getter.class) .findOnly()) .isEqualTo(expected); } }
@Test public void parameterizedTest() { assertThat( h.createUpdate("insert into immutables(t, x) values (:t, :x)") .bindPojo(ImmutableSubValue.<String, Integer>builder().t(42).x("foo").build()) .execute()) .isEqualTo(1); assertThat( h.createQuery("select * from immutables") .mapTo(new GenericType<SubValue<String, Integer>>() {}) .findOnly()) .extracting("t", "x") .containsExactly(42, "foo"); }
@Test public void testModifiable() { h.execute("create table fbb (id serial, foo varchar, bar int, baz real)"); assertThat(h.createUpdate("insert into fbb (id, foo, bar, baz) values (:id, :foo, :bar, :baz)") .bindPojo(ModifiableFooBarBaz.create().setFoo("foo").setBar(42).setBaz(1.0)) .execute()) .isEqualTo(1); assertThat(h.createQuery("select * from fbb") .mapTo(ModifiableFooBarBaz.class) .findOnly()) .extracting("id", "foo", "bar", "baz") .containsExactly(1, Optional.of("foo"), OptionalInt.of(42), OptionalDouble.of(1.0)); assertThat(h.createQuery("select * from fbb") .mapTo(ImmutableFooBarBaz.class) .findOnly()) .extracting("id", "foo", "bar", "baz") // FIXME: https://github.com/joel-costigliola/assertj-core/pull/1360 .containsExactly(1, "foo", 42, 1.0); }
@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[]