Skip to content

Commit

Permalink
[hibernate#1792] Add test for getSingleResultOrNull and getSingleResult
Browse files Browse the repository at this point in the history
We are checking that it doesn't throw a NullPointerException
if the result of the query doesn't have any columns names.
  • Loading branch information
DavideD committed Nov 23, 2023
1 parent 26d96e9 commit 684f317
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import io.vertx.junit5.VertxTestContext;
import jakarta.persistence.*;

import org.hibernate.HibernateException;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLInsert;
import org.hibernate.reactive.testing.DBSelectionExtension;
import org.hibernate.reactive.testing.ReactiveAssertions;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -23,6 +25,7 @@
import java.util.List;

import static java.util.concurrent.TimeUnit.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.*;
import static org.hibernate.reactive.testing.DBSelectionExtension.*;
import static org.junit.jupiter.api.Assertions.*;
Expand Down Expand Up @@ -84,6 +87,22 @@ public void populateDb(VertxTestContext context) {
);
}

@Test
public void testFailureWithGetSingleResultOrNull(VertxTestContext context) {
test( context, ReactiveAssertions.assertThrown( HibernateException.class, getMutinySessionFactory()
.withTransaction( s -> s.createNativeQuery( INSERT_DRIVER_LICENCE_SQL ).getSingleResultOrNull() ) )
.invoke( e -> assertThat( e ).hasMessageContainingAll( "HR000080:", INSERT_DRIVER_LICENCE_SQL ) )
);
}

@Test
public void testFailureWithGetSingleResult(VertxTestContext context) {
test( context, ReactiveAssertions.assertThrown( HibernateException.class, getSessionFactory()
.withTransaction( s -> s.createNativeQuery( INSERT_DRIVER_LICENCE_SQL ).getSingleResult() ) )
.thenAccept( e -> assertThat( e ).hasMessageContainingAll( "HR000080:", INSERT_DRIVER_LICENCE_SQL ) )
);
}

@Test
public void testInsertStoredProcedureDriverLicence(VertxTestContext context) {
test( context, openSession().thenCompose( session -> session
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
import java.util.Collection;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLInsert;
import org.hibernate.annotations.SQLUpdate;
import org.hibernate.reactive.testing.DBSelectionExtension;
import org.hibernate.reactive.testing.ReactiveAssertions;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -29,6 +31,7 @@
import jakarta.persistence.Table;

import static java.util.concurrent.TimeUnit.MINUTES;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.POSTGRESQL;
import static org.hibernate.reactive.testing.DBSelectionExtension.runOnlyFor;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -102,6 +105,22 @@ public void populateDb(VertxTestContext context) {
);
}

@Test
public void testFailureWithGetSingleResultOrNull(VertxTestContext context) {
test( context, ReactiveAssertions.assertThrown( HibernateException.class, getMutinySessionFactory()
.withTransaction( s -> s.createNativeQuery( INSERT_SP_SQL ).getSingleResultOrNull() ) )
.invoke( e -> assertThat( e ).hasMessageContainingAll( "HR000080:", INSERT_SP_SQL ) )
);
}

@Test
public void testFailureWithGetSingleResult(VertxTestContext context) {
test( context, ReactiveAssertions.assertThrown( HibernateException.class, getSessionFactory()
.withTransaction( s -> s.createNativeQuery( INSERT_SP_SQL ).getSingleResult() ) )
.thenAccept( e -> assertThat( e ).hasMessageContainingAll( "HR000080:", INSERT_SP_SQL ) )
);
}

@Test
public void testInsertStoredProcedure(VertxTestContext context) {
test( context, openSession().thenCompose( session -> session
Expand Down

0 comments on commit 684f317

Please sign in to comment.