Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
* Use uppercase "L" for long types
* Replace lambdas with method references
  • Loading branch information
DavideD committed Nov 27, 2023
1 parent d26a0e8 commit 836cb05
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public IllegalStateException implementationInjectionMissing() {
public Uni<Integer> executeUpdate(Class<?> entityClass, String panacheQuery, Object... params) {

if (PanacheJpaUtil.isNamedQuery(panacheQuery))
return (Uni) getSession().chain(session -> {
return getSession().chain(session -> {
String namedQueryName = panacheQuery.substring(1);
NamedQueryUtil.checkNamedQuery(entityClass, namedQueryName);
return bindParameters(session.createNamedQuery(namedQueryName), params).executeUpdate();
Expand All @@ -333,7 +333,7 @@ public Uni<Integer> executeUpdate(Class<?> entityClass, String panacheQuery, Obj
public Uni<Integer> executeUpdate(Class<?> entityClass, String panacheQuery, Map<String, Object> params) {

if (PanacheJpaUtil.isNamedQuery(panacheQuery))
return (Uni) getSession().chain(session -> {
return getSession().chain(session -> {
String namedQueryName = panacheQuery.substring(1);
NamedQueryUtil.checkNamedQuery(entityClass, namedQueryName);
return bindParameters(session.createNamedQuery(namedQueryName), params).executeUpdate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;
import jakarta.persistence.PersistenceException;

import org.hibernate.reactive.mutiny.Mutiny;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order;
Expand Down Expand Up @@ -70,7 +70,7 @@ public void testPanacheSerialisation() {
@RunOnVertxContext
@Test
public void testPanacheInTest(UniAsserter asserter) {
asserter.assertEquals(() -> Panache.withSession(() -> Person.count()), 0l);
asserter.assertEquals(() -> Panache.withSession(Person::count), 0L);
}

@Test
Expand Down Expand Up @@ -163,14 +163,14 @@ public void testSortByNullPrecedence() {
@RunOnVertxContext
@Test
void testTransaction(UniAsserter asserter) {
asserter.assertNotNull(() -> Panache.withTransaction(() -> Panache.currentTransaction()));
asserter.assertNotNull(() -> Panache.withTransaction(Panache::currentTransaction));
}

@DisabledOnIntegrationTest
@RunOnVertxContext
@Test
void testNoTransaction(UniAsserter asserter) {
asserter.assertNull(() -> Panache.withSession(() -> Panache.currentTransaction()));
asserter.assertNull(() -> Panache.withSession(Panache::currentTransaction));
}

@DisabledOnIntegrationTest
Expand Down Expand Up @@ -218,36 +218,36 @@ Uni<Person> getBug7102(Long id) {
@Test
@Order(100)
public void testTestTransaction(UniAsserter asserter) {
asserter.assertNotNull(() -> Panache.currentTransaction());
asserter.assertEquals(() -> Person.count(), 0l);
asserter.assertNotNull(Panache::currentTransaction);
asserter.assertEquals(Person::count, 0L);
asserter.assertNotNull(() -> new Person().persist());
asserter.assertEquals(() -> Person.count(), 1l);
asserter.assertEquals(Person::count, 1L);
}

@DisabledOnIntegrationTest
@TestReactiveTransaction
@Test
@Order(101)
public void testTestTransaction2(UniAsserter asserter) {
asserter.assertNotNull(() -> Panache.currentTransaction());
asserter.assertNotNull(Panache::currentTransaction);
// make sure the previous one was rolled back
asserter.assertEquals(() -> Person.count(), 0l);
asserter.assertEquals(Person::count, 0L);
}

@DisabledOnIntegrationTest
@RunOnVertxContext
@Test
@Order(200)
public void testReactiveTransactional(UniAsserter asserter) {
asserter.assertEquals(() -> reactiveTransactional(), 1l);
asserter.assertEquals(this::reactiveTransactional, 1L);
}

@WithTransaction
Uni<Long> reactiveTransactional() {
return Panache.currentTransaction()
.invoke(tx -> assertNotNull(tx))
.invoke(Assertions::assertNotNull)
.chain(tx -> Person.count())
.invoke(count -> assertEquals(0l, count))
.invoke(count -> assertEquals(0L, count))
.call(() -> new Person().persist())
.chain(tx -> Person.count());
}
Expand All @@ -257,19 +257,19 @@ Uni<Long> reactiveTransactional() {
@Test
@Order(201)
public void testReactiveTransactional2(UniAsserter asserter) {
asserter.assertTrue(() -> reactiveTransactional2());
asserter.assertTrue(this::reactiveTransactional2);
}

@WithTransaction
Uni<Boolean> reactiveTransactional2() {
return Panache.currentTransaction()
.invoke(tx -> assertNotNull(tx))
.invoke(Assertions::assertNotNull)
.chain(tx -> Person.count())
.invoke(count -> assertEquals(1l, count))
.chain(() -> Person.deleteAll())
.invoke(count -> assertEquals(1l, count))
.chain(() -> Panache.currentTransaction())
.invoke(tx -> tx.markForRollback())
.invoke(count -> assertEquals(1L, count))
.chain(Person::deleteAll)
.invoke(count -> assertEquals(1L, count))
.chain(Panache::currentTransaction)
.invoke(Mutiny.Transaction::markForRollback)
.map(tx -> true);
}

Expand All @@ -278,17 +278,17 @@ Uni<Boolean> reactiveTransactional2() {
@Test
@Order(202)
public void testReactiveTransactional3(UniAsserter asserter) {
asserter.assertEquals(() -> testReactiveTransactional3(), 1l);
asserter.assertEquals(this::testReactiveTransactional3, 1L);
}

@ReactiveTransactional
Uni<Long> testReactiveTransactional3() {
return Panache.currentTransaction()
.invoke(tx -> assertNotNull(tx))
.invoke(Assertions::assertNotNull)
.chain(tx -> Person.count())
// make sure it was rolled back
.invoke(count -> assertEquals(1l, count))
.call(() -> Person.deleteAll());
.invoke(count -> assertEquals(1L, count))
.call(Person::deleteAll);
}

@DisabledOnIntegrationTest
Expand Down

0 comments on commit 836cb05

Please sign in to comment.