Skip to content

Commit

Permalink
Start a new, java 17+ module
Browse files Browse the repository at this point in the history
add some tests for records
  • Loading branch information
hgschmie committed Dec 17, 2022
1 parent 1ed54d6 commit f6c396f
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1109,8 +1109,8 @@
<id>fast</id>
<properties>
<basepom.check.skip-all>true</basepom.check.skip-all>
<skipTests>true</skipTests>
<skipITs>true</skipITs>
<skipTests>true</skipTests>
</properties>
</profile>

Expand Down
66 changes: 66 additions & 0 deletions java17/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.jdbi</groupId>
<artifactId>jdbi3-parent</artifactId>
<version>3.35.1-SNAPSHOT</version>
</parent>

<artifactId>jdbi3-java17</artifactId>
<name>jdbi3 - internal - java17</name>
<description>jdbi3 for Java 17 or better</description>

<properties>
<basepom.deploy.skip>true</basepom.deploy.skip>
<basepom.install.skip>true</basepom.install.skip>
<moduleName>org.jdbi.v3.java17</moduleName>
<project.build.targetJdk>17</project.build.targetJdk>
</properties>

<dependencies>
<dependency>
<groupId>org.jdbi</groupId>
<artifactId>jdbi3-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jdbi</groupId>
<artifactId>jdbi3-testing</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jdbi</groupId>
<artifactId>jdbi3-sqlobject</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
78 changes: 78 additions & 0 deletions java17/src/test/java/org/jdbi/v3/java17/TestRecord.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jdbi.v3.java17;

import java.util.List;
import java.util.Optional;

import org.jdbi.v3.core.mapper.RowMappers;
import org.jdbi.v3.core.mapper.reflect.ConstructorMapper;
import org.jdbi.v3.sqlobject.SqlObject;
import org.jdbi.v3.sqlobject.SqlObjectPlugin;
import org.jdbi.v3.sqlobject.statement.SqlQuery;
import org.jdbi.v3.testing.junit5.JdbiExtension;
import org.jdbi.v3.testing.junit5.internal.TestingInitializers;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import static org.assertj.core.api.Assertions.assertThat;

class TestRecord {

@RegisterExtension
JdbiExtension h2Extension = JdbiExtension.h2()
.withPlugin(new SqlObjectPlugin())
.withInitializer(TestingInitializers.usersWithData())
.withConfig(RowMappers.class, r -> r.register(User.class, ConstructorMapper.of(User.class)));

UserDao dao;

@BeforeEach
void setUp() {
this.dao = h2Extension.getSharedHandle().attach(UserDao.class);
}

@Test
void testMapping() {
var users = dao.getUsers();
assertThat(users).hasSize(2)
.containsExactly(new User(1, "Alice"), new User(2, "Bob"));
}

@Test
void testBinding() {
var handle = h2Extension.getSharedHandle();

try (var update = handle.createUpdate("INSERT INTO users (id, name) values <values>")) {
update.bindMethodsList("values", List.of(new User(3, "Charlie")), List.of("id", "name"))
.execute();
}

var user = dao.getUser(3);
assertThat(user).isPresent()
.contains(new User(3, "Charlie"));
}

public record User(int id, String name) {}

interface UserDao extends SqlObject {

@SqlQuery("SELECT * from users order by id")
List<User> getUsers();

@SqlQuery("SELECT * from users WHERE id = :id order by id")
Optional<User> getUser(int id);
}
}
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,16 @@
</dependency>
</dependencies>
</dependencyManagement>

<profiles>
<profile>
<id>java17</id>
<activation>
<jdk>[17,)</jdk>
</activation>
<modules>
<module>java17</module>
</modules>
</profile>
</profiles>
</project>

0 comments on commit f6c396f

Please sign in to comment.