Created
May 27, 2014 00:31
-
-
Save brianm/53f6e3cc50daa6486e1c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.jdbi; | |
import com.google.common.collect.ImmutableList; | |
import org.junit.Rule; | |
import org.junit.Test; | |
import javax.sql.DataSource; | |
import java.sql.Connection; | |
import java.sql.PreparedStatement; | |
import java.sql.ResultSet; | |
import java.util.List; | |
import java.util.stream.Collectors; | |
import static org.fest.assertions.Assertions.assertThat; | |
public class ResultsTest | |
{ | |
@Rule | |
public H2Rule h2 = new H2Rule().withFixture("create table something (id integer primary key, name varchar)") | |
.withFixture("insert into something (id, name) values (1, 'Brian'), (2, 'Steven')"); | |
@Test | |
public void testFoo() throws Exception | |
{ | |
DataSource ds = h2.getDatasource(); | |
try (Connection c = ds.getConnection()) { | |
try (PreparedStatement ps = c.prepareStatement("select name from something order by id")) { | |
try (ResultSet rs = ps.executeQuery()) { | |
UncheckedResultSet urs = Results.unchecked(rs); | |
List<String> names = urs.stream() | |
.map((r) -> r.getString(1)) | |
.collect(Collectors.toList()); | |
assertThat(names).isEqualTo(ImmutableList.of("Brian", "Steven")); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment