upgraded to Java 11 and fixed build

This commit is contained in:
Tom Hombergs
2019-03-30 08:02:10 +01:00
parent b0ae545cd8
commit 8877f30ebc
58 changed files with 178 additions and 162 deletions

View File

@@ -1,16 +1,13 @@
package io.reflectoring.conditionals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class ConditionalsApplicationTests {
class ConditionalsApplicationTests {
@Test
public void contextLoads() {
void contextLoads() {
}
}

View File

@@ -1,17 +1,7 @@
package io.reflectoring.configuration.unknownfield;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.time.Duration;
import java.util.List;
import io.reflectoring.configuration.mail.Weight;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
import org.springframework.stereotype.Component;
import org.springframework.util.unit.DataSize;
import org.springframework.validation.annotation.Validated;
@Component
@ConfigurationProperties(prefix = "myapp.unknownfield", ignoreUnknownFields = false)

View File

@@ -1,5 +1,5 @@
myapp.mail.enabled=true
myapp.mail.defaultSubject=hello
myapp
myapp.mail.pauseBetweenMails=5s
myapp.mail.maxAttachmentSize=1MB
myapp.mail.smtpServers[0]=server1

View File

@@ -1,16 +0,0 @@
package io.reflectoring.configuration;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@ExtendWith(SpringExtension.class)
@SpringBootTest
class ConfigurationApplicationTests {
@Test
void contextLoads() {
}
}

View File

@@ -10,7 +10,6 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.util.unit.DataSize;
import static org.assertj.core.api.Assertions.*;
@ExtendWith(SpringExtension.class)
@SpringBootTest(properties = {
"myapp.mail.enabled=asd",
"myapp.mail.defaultSubject=hello",
@@ -22,17 +21,17 @@ import static org.assertj.core.api.Assertions.*;
})
class MailModuleTestWithAllProperties {
@Autowired(required = false)
private MailModuleProperties mailModuleProperties;
@Autowired(required = false)
private MailModuleProperties mailModuleProperties;
@Test
void propertiesAreLoaded() {
assertThat(mailModuleProperties).isNotNull();
assertThat(mailModuleProperties.getDefaultSubject()).isEqualTo("hello");
assertThat(mailModuleProperties.getEnabled()).isTrue();
assertThat(mailModuleProperties.getPauseBetweenMails()).isEqualByComparingTo(Duration.ofSeconds(5));
assertThat(mailModuleProperties.getMaxAttachmentSize()).isEqualByComparingTo(DataSize.ofMegabytes(1));
assertThat(mailModuleProperties.getSmtpServers()).hasSize(2);
assertThat(mailModuleProperties.getMaxAttachmentWeight().getGrams()).isEqualTo(5000L);
}
@Test
void propertiesAreLoaded() {
assertThat(mailModuleProperties).isNotNull();
assertThat(mailModuleProperties.getDefaultSubject()).isEqualTo("hello");
assertThat(mailModuleProperties.getEnabled()).isTrue();
assertThat(mailModuleProperties.getPauseBetweenMails()).isEqualByComparingTo(Duration.ofSeconds(5));
assertThat(mailModuleProperties.getMaxAttachmentSize()).isEqualByComparingTo(DataSize.ofMegabytes(1));
assertThat(mailModuleProperties.getSmtpServers()).hasSize(2);
assertThat(mailModuleProperties.getMaxAttachmentWeight().getGrams()).isEqualTo(5000L);
}
}

View File

@@ -2,24 +2,21 @@ package io.reflectoring.configuration.mail;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import static org.assertj.core.api.Assertions.*;
@ExtendWith(SpringExtension.class)
@SpringBootTest(properties = {
"myapp.mail.defaultSubject="
})
@Disabled("this test will fail due to invalid properties")
class MailModuleTestWithInvalidProperties {
@Autowired(required = false)
private MailModuleProperties mailModuleProperties;
@Autowired(required = false)
private MailModuleProperties mailModuleProperties;
@Test
void propertiesAreLoaded() {
assertThat(mailModuleProperties).isNotNull();
}
@Test
void propertiesAreLoaded() {
assertThat(mailModuleProperties).isNotNull();
}
}

View File

@@ -1,22 +0,0 @@
package io.reflectoring.configuration.mail;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import static org.assertj.core.api.Assertions.*;
@ExtendWith(SpringExtension.class)
@SpringBootTest
class MailModuleTestWithUnknownField {
@Autowired(required = false)
private MailModuleProperties mailModuleProperties;
@Test
void propertiesAreLoaded() {
assertThat(mailModuleProperties).isNotNull();
}
}

View File

@@ -8,7 +8,6 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import static org.assertj.core.api.Assertions.*;
@ExtendWith(SpringExtension.class)
@SpringBootTest(properties = {
"myapp.unknown-and-invalid-field-module.unknown-property=foo"
})

View File

@@ -8,7 +8,6 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import static org.assertj.core.api.Assertions.*;
@ExtendWith(SpringExtension.class)
@SpringBootTest(properties = {
"myapp.unknownfield.unknown-property=foo"
})

View File

@@ -15,7 +15,7 @@ apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
sourceCompatibility = 11
repositories {
mavenLocal()

View File

@@ -11,6 +11,10 @@ repositories {
dependencies {
compile("org.springframework.boot:spring-boot-starter:${springBootVersion}")
// adding javax.annotation since it's no longer included in Java 11
compile("javax.annotation:javax.annotation-api:1.3.2")
testCompile("org.springframework.boot:spring-boot-starter-test:${springBootVersion}")
}

View File

@@ -1,6 +0,0 @@
pluginManagement {
repositories {
gradlePluginPortal()
}
}
rootProject.name = 'pagination'

View File

@@ -1,15 +0,0 @@
package io.reflectoring.pagination;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration;
@SpringBootApplication
public class PaginationApplication {
public static void main(String[] args) {
SpringApplication.run(PaginationApplication.class, args);
}
}

View File

@@ -1,13 +0,0 @@
package io.reflectoring.pagination;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class PaginationApplicationTests {
@Test
void contextLoads() {
}
}

View File

@@ -1,4 +1,4 @@
package io.reflectoring.pagination;
package io.reflectoring.paging;
import lombok.Data;

View File

@@ -1,4 +1,4 @@
package io.reflectoring.pagination;
package io.reflectoring.paging;
import java.util.List;

View File

@@ -1,4 +1,4 @@
package io.reflectoring.pagination;
package io.reflectoring.paging;
import java.util.List;
@@ -15,7 +15,7 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequiredArgsConstructor
class PaginatedController {
class PagedController {
private final MovieCharacterRepository characterRepository;
@@ -25,7 +25,8 @@ class PaginatedController {
@SortDefault.SortDefaults({
@SortDefault(sort = "name", direction = Sort.Direction.DESC),
@SortDefault(sort = "id", direction = Sort.Direction.ASC)
}) Pageable pageable) {
})
Pageable pageable) {
return characterRepository.findAllPage(pageable);
}

View File

@@ -0,0 +1,13 @@
package io.reflectoring.paging;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class PagingApplication {
public static void main(String[] args) {
SpringApplication.run(PagingApplication.class, args);
}
}

View File

@@ -2,5 +2,6 @@ spring.data.web.pageable.size-parameter=size
spring.data.web.pageable.page-parameter=page
spring.data.web.pageable.default-page-size=10
spring.data.web.pageable.one-indexed-parameters=false
spring.data.web.pageable.prefix=2000
spring.data.web.pageable.max-page-size=2000
spring.data.web.pageable.prefix=
spring.data.web.pageable.qualifier-delimiter=_

View File

@@ -1,4 +1,4 @@
package io.reflectoring.pagination;
package io.reflectoring.paging;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

View File

@@ -1,4 +1,4 @@
package io.reflectoring.pagination;
package io.reflectoring.paging;
import java.util.Objects;

View File

@@ -1,4 +1,4 @@
package io.reflectoring.pagination;
package io.reflectoring.paging;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
@@ -10,19 +10,19 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.test.web.servlet.MockMvc;
import static io.reflectoring.pagination.PageableAssert.*;
import static io.reflectoring.pagination.SortAssert.*;
import static io.reflectoring.paging.PageableAssert.*;
import static io.reflectoring.paging.SortAssert.*;
import static org.mockito.Mockito.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@WebMvcTest(
controllers = PaginatedController.class
controllers = PagedController.class
// If we exclude SpringDataWebAutoConfiguration, the Pageable parameter will not be resolved.
// If we only exclude it on the Application class itself, the test will still work!!!
// excludeAutoConfiguration = SpringDataWebAutoConfiguration.class
)
class PaginatedControllerTest {
class PagedControllerTest {
@MockBean
private MovieCharacterRepository characterRepository;

View File

@@ -1,29 +1,27 @@
package io.reflectoring.pagination;
package io.reflectoring.paging;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.servlet.MockMvc;
import static io.reflectoring.pagination.PageableAssert.*;
import static io.reflectoring.paging.PageableAssert.*;
import static org.mockito.Mockito.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@WebMvcTest(controllers = PaginatedController.class)
@WebMvcTest(controllers = PagedController.class)
@TestPropertySource(properties = {
"spring.data.web.pageable.prefix=prefix_",
"spring.data.web.pageable.size-parameter=my-size",
"spring.data.web.pageable.page-parameter=my-page"
})
class PaginatedControllerWithCustomPagingPropertiesTest {
class PagedControllerWithCustomPagingPropertiesTest {
@MockBean
private MovieCharacterRepository characterRepository;

View File

@@ -1,4 +1,4 @@
package io.reflectoring.pagination;
package io.reflectoring.paging;
import org.assertj.core.api.AbstractAssert;
import org.springframework.data.domain.Sort;

View File

@@ -15,7 +15,7 @@ apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
sourceCompatibility = 11
repositories {
mavenLocal()

View File

@@ -17,7 +17,7 @@ apply plugin: 'io.spring.dependency-management'
group = 'io.reflectoring'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
sourceCompatibility = 11
repositories {
mavenCentral()

View File

@@ -17,7 +17,7 @@ apply plugin: 'io.spring.dependency-management'
group = 'reflectoring.io'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
sourceCompatibility = 11
repositories {
jcenter()

View File

@@ -18,8 +18,5 @@ public class Customer {
@GeneratedValue
private Long id;
@Version
private Long version;
private String name;
}

View File

@@ -9,7 +9,9 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
@@ -21,7 +23,8 @@ import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@WebMvcTest(controllers = BookingController.class)
@SpringBootTest
@AutoConfigureMockMvc
class BookingControllerTest {
@Autowired

View File

@@ -17,7 +17,7 @@ apply plugin: 'io.spring.dependency-management'
group = 'io.reflectoring'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
sourceCompatibility = 11
repositories {
mavenCentral()