From ce95fd6825e336ec227e3da118e3c81a709330ad Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 26 Mar 2020 16:11:43 +0000 Subject: [PATCH] Polish "Use @DynamicPropertySource for Neo4J and Redis data tests" See gh-20676 --- .../data/neo4j/DataNeo4jTestIntegrationTests.java | 12 ++++++------ .../DataNeo4jTestPropertiesIntegrationTests.java | 8 ++++---- ...taNeo4jTestWithIncludeFilterIntegrationTests.java | 8 ++++---- .../data/redis/DataRedisTestIntegrationTests.java | 10 +++++----- .../DataRedisTestPropertiesIntegrationTests.java | 6 +++--- ...taRedisTestWithIncludeFilterIntegrationTests.java | 10 +++++----- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestIntegrationTests.java index fba328b0eb..e34849cb0d 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestIntegrationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,11 +45,6 @@ class DataNeo4jTestIntegrationTests { @Container static final Neo4jContainer neo4j = new Neo4jContainer<>().withoutAuthentication(); - @DynamicPropertySource - static void neo4jProperties(DynamicPropertyRegistry registry) { - registry.add("spring.data.neo4j.uri", neo4j::getBoltUrl); - } - @Autowired private Session session; @@ -59,6 +54,11 @@ class DataNeo4jTestIntegrationTests { @Autowired private ApplicationContext applicationContext; + @DynamicPropertySource + static void neo4jProperties(DynamicPropertyRegistry registry) { + registry.add("spring.data.neo4j.uri", neo4j::getBoltUrl); + } + @Test void testRepository() { ExampleGraph exampleGraph = new ExampleGraph(); diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestPropertiesIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestPropertiesIntegrationTests.java index 77acadf9a5..91e289c719 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestPropertiesIntegrationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestPropertiesIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,14 +41,14 @@ class DataNeo4jTestPropertiesIntegrationTests { @Container static final Neo4jContainer neo4j = new Neo4jContainer<>().withoutAuthentication(); + @Autowired + private Environment environment; + @DynamicPropertySource static void neo4jProperties(DynamicPropertyRegistry registry) { registry.add("spring.data.neo4j.uri", neo4j::getBoltUrl); } - @Autowired - private Environment environment; - @Test void environmentWithNewProfile() { assertThat(this.environment.getActiveProfiles()).containsExactly("test"); diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestWithIncludeFilterIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestWithIncludeFilterIntegrationTests.java index 88ff5d3eb3..8f759adbf0 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestWithIncludeFilterIntegrationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestWithIncludeFilterIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,14 +42,14 @@ class DataNeo4jTestWithIncludeFilterIntegrationTests { @Container static final Neo4jContainer neo4j = new Neo4jContainer<>().withoutAuthentication(); + @Autowired + private ExampleService service; + @DynamicPropertySource static void neo4jProperties(DynamicPropertyRegistry registry) { registry.add("spring.data.neo4j.uri", neo4j::getBoltUrl); } - @Autowired - private ExampleService service; - @Test void testService() { assertThat(this.service.hasNode(ExampleGraph.class)).isFalse(); diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestIntegrationTests.java index fc26c3ca7a..2f8ae12cdc 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestIntegrationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestIntegrationTests.java @@ -49,11 +49,6 @@ class DataRedisTestIntegrationTests { @Container static RedisContainer redis = new RedisContainer(); - @DynamicPropertySource - static void redisProperties(DynamicPropertyRegistry registry) { - registry.add("spring.redis.port", redis::getFirstMappedPort); - } - @Autowired private RedisOperations operations; @@ -63,6 +58,11 @@ class DataRedisTestIntegrationTests { @Autowired private ApplicationContext applicationContext; + @DynamicPropertySource + static void redisProperties(DynamicPropertyRegistry registry) { + registry.add("spring.redis.port", redis::getFirstMappedPort); + } + @Test void testRepository() { PersonHash personHash = new PersonHash(); diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestPropertiesIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestPropertiesIntegrationTests.java index 0724fa06a4..c6d191dd3f 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestPropertiesIntegrationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestPropertiesIntegrationTests.java @@ -41,14 +41,14 @@ class DataRedisTestPropertiesIntegrationTests { @Container static final RedisContainer redis = new RedisContainer(); + @Autowired + private Environment environment; + @DynamicPropertySource static void redisProperties(DynamicPropertyRegistry registry) { registry.add("spring.redis.port", redis::getFirstMappedPort); } - @Autowired - private Environment environment; - @Test void environmentWithNewProfile() { assertThat(this.environment.getActiveProfiles()).containsExactly("test"); diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestWithIncludeFilterIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestWithIncludeFilterIntegrationTests.java index 362f6dffe1..fcdddb9b38 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestWithIncludeFilterIntegrationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestWithIncludeFilterIntegrationTests.java @@ -41,17 +41,17 @@ class DataRedisTestWithIncludeFilterIntegrationTests { @Container static final RedisContainer redis = new RedisContainer(); - @DynamicPropertySource - static void redisProperties(DynamicPropertyRegistry registry) { - registry.add("spring.redis.port", redis::getFirstMappedPort); - } - @Autowired private ExampleRepository exampleRepository; @Autowired private ExampleService service; + @DynamicPropertySource + static void redisProperties(DynamicPropertyRegistry registry) { + registry.add("spring.redis.port", redis::getFirstMappedPort); + } + @Test void testService() { PersonHash personHash = new PersonHash();