Java 16 migration for R2DBC examples.

See #606.
This commit is contained in:
Mark Paluch
2021-04-28 10:14:45 +02:00
parent 75e2763054
commit a4c9302780
10 changed files with 83 additions and 76 deletions

View File

@@ -20,32 +20,29 @@ import reactor.test.StepVerifier;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.r2dbc.core.DatabaseClient;
import org.springframework.test.context.junit4.SpringRunner;
/**
* @author Oliver Gierke
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = InfrastructureConfiguration.class)
public class CustomerRepositoryIntegrationTests {
class CustomerRepositoryIntegrationTests {
@Autowired CustomerRepository customers;
@Autowired DatabaseClient database;
@Before
public void setUp() {
@BeforeEach
void setUp() {
Hooks.onOperatorDebug();
List<String> statements = Arrays.asList(//
var statements = Arrays.asList(//
"DROP TABLE IF EXISTS customer;",
"CREATE TABLE customer ( id SERIAL PRIMARY KEY, firstname VARCHAR(100) NOT NULL, lastname VARCHAR(100) NOT NULL);");
@@ -58,31 +55,31 @@ public class CustomerRepositoryIntegrationTests {
}
@Test
public void executesFindAll() throws IOException {
void executesFindAll() throws IOException {
Customer dave = new Customer(null, "Dave", "Matthews");
Customer carter = new Customer(null, "Carter", "Beauford");
var dave = new Customer(null, "Dave", "Matthews");
var carter = new Customer(null, "Carter", "Beauford");
insertCustomers(dave, carter);
customers.findAll() //
.as(StepVerifier::create) //
.assertNext(dave::equals) //
.assertNext(carter::equals) //
.expectNext(dave) //
.expectNext(carter) //
.verifyComplete();
}
@Test
public void executesAnnotatedQuery() throws IOException {
void executesAnnotatedQuery() throws IOException {
Customer dave = new Customer(null, "Dave", "Matthews");
Customer carter = new Customer(null, "Carter", "Beauford");
var dave = new Customer(null, "Dave", "Matthews");
var carter = new Customer(null, "Carter", "Beauford");
insertCustomers(dave, carter);
customers.findByLastname("Matthews") //
.as(StepVerifier::create) //
.assertNext(dave::equals) //
.expectNext(dave) //
.verifyComplete();
}

View File

@@ -21,13 +21,12 @@ import reactor.test.StepVerifier;
import java.util.Arrays;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.r2dbc.core.DatabaseClient;
import org.springframework.test.context.junit4.SpringRunner;
/**
* Integration tests for {@link TransactionalService}.
@@ -35,20 +34,19 @@ import org.springframework.test.context.junit4.SpringRunner;
* @author Oliver Drotbohm
* @soundtrack Shame - Tedeschi Trucks Band (Signs)
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = InfrastructureConfiguration.class)
public class TransactionalServiceIntegrationTests {
class TransactionalServiceIntegrationTests {
@Autowired TransactionalService service;
@Autowired CustomerRepository repository;
@Autowired DatabaseClient database;
@Before
public void setUp() {
@BeforeEach
void setUp() {
Hooks.onOperatorDebug();
List<String> statements = Arrays.asList(//
var statements = Arrays.asList(//
"DROP TABLE IF EXISTS customer;",
"CREATE TABLE customer ( id SERIAL PRIMARY KEY, firstname VARCHAR(100) NOT NULL, lastname VARCHAR(100) NOT NULL);");
@@ -61,7 +59,7 @@ public class TransactionalServiceIntegrationTests {
}
@Test // #500
public void exceptionTriggersRollback() {
void exceptionTriggersRollback() {
service.save(new Customer(null, "Dave", "Matthews")) //
.as(StepVerifier::create) //
@@ -75,7 +73,7 @@ public class TransactionalServiceIntegrationTests {
}
@Test // #500
public void insertsDataTransactionally() {
void insertsDataTransactionally() {
service.save(new Customer(null, "Carter", "Beauford")) //
.as(StepVerifier::create) //

View File

@@ -21,13 +21,11 @@ import reactor.test.StepVerifier;
import java.io.IOException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.r2dbc.core.DatabaseClient;
import org.springframework.test.context.junit4.SpringRunner;
/**
* Integration test using {@link org.springframework.data.r2dbc.mapping.event.BeforeConvertCallback} to auto-generate an
@@ -36,24 +34,23 @@ import org.springframework.test.context.junit4.SpringRunner;
* @author Mark Paluch
* @see ApplicationConfiguration#idGeneratingCallback(DatabaseClient)
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class CustomerRepositoryIntegrationTests {
class CustomerRepositoryIntegrationTests {
@Autowired CustomerRepository customers;
@Autowired DatabaseClient database;
@Test
public void generatesIdOnInsert() throws IOException {
void generatesIdOnInsert() throws IOException {
Customer dave = new Customer(null, "Dave", "Matthews");
var dave = new Customer(null, "Dave", "Matthews");
this.customers.save(dave) //
.as(StepVerifier::create) //
.assertNext(actual -> {
assertThat(dave.getId()).isNull(); // immutable before save
assertThat(actual.getId()).isNotNull(); // after save
assertThat(dave.id()).isNull(); // immutable before save
assertThat(actual.id()).isNotNull(); // after save
}).verifyComplete();
}
}