Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
0f5f6f15
Commit
0f5f6f15
authored
Dec 29, 2018
by
dreis2211
Committed by
Stephane Nicoll
Dec 30, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use hasFieldOrPropertyWithValue where possible
Closes gh-15582
parent
c667a7ef
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
15 additions
and
50 deletions
+15
-50
RestClientAutoConfigurationTests.java
.../elasticsearch/rest/RestClientAutoConfigurationTests.java
+2
-7
GsonAutoConfigurationTests.java
...k/boot/autoconfigure/gson/GsonAutoConfigurationTests.java
+2
-19
AbstractJpaAutoConfigurationTests.java
...oconfigure/orm/jpa/AbstractJpaAutoConfigurationTests.java
+3
-6
SpringApplicationTests.java
...java/org/springframework/boot/SpringApplicationTests.java
+6
-10
ServletWebServerApplicationContextTests.java
...vlet/context/ServletWebServerApplicationContextTests.java
+2
-8
No files found.
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/rest/RestClientAutoConfigurationTests.java
View file @
0f5f6f15
...
@@ -16,7 +16,6 @@
...
@@ -16,7 +16,6 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
elasticsearch
.
rest
;
package
org
.
springframework
.
boot
.
autoconfigure
.
elasticsearch
.
rest
;
import
java.lang.reflect.Field
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -33,7 +32,6 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner;
...
@@ -33,7 +32,6 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import
org.springframework.boot.testsupport.testcontainers.ElasticsearchContainer
;
import
org.springframework.boot.testsupport.testcontainers.ElasticsearchContainer
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.util.ReflectionUtils
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
mock
;
...
@@ -71,11 +69,8 @@ public class RestClientAutoConfigurationTests {
...
@@ -71,11 +69,8 @@ public class RestClientAutoConfigurationTests {
.
run
((
context
)
->
{
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
RestClient
.
class
);
assertThat
(
context
).
hasSingleBean
(
RestClient
.
class
);
RestClient
restClient
=
context
.
getBean
(
RestClient
.
class
);
RestClient
restClient
=
context
.
getBean
(
RestClient
.
class
);
Field
field
=
ReflectionUtils
.
findField
(
RestClient
.
class
,
assertThat
(
restClient
)
"maxRetryTimeoutMillis"
);
.
hasFieldOrPropertyWithValue
(
"maxRetryTimeoutMillis"
,
42L
);
ReflectionUtils
.
makeAccessible
(
field
);
assertThat
(
ReflectionUtils
.
getField
(
field
,
restClient
))
.
isEqualTo
(
42L
);
});
});
}
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/gson/GsonAutoConfigurationTests.java
View file @
0f5f6f15
...
@@ -16,7 +16,6 @@
...
@@ -16,7 +16,6 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
gson
;
package
org
.
springframework
.
boot
.
autoconfigure
.
gson
;
import
java.lang.reflect.Field
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.LinkedHashMap
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -180,15 +179,7 @@ public class GsonAutoConfigurationTests {
...
@@ -180,15 +179,7 @@ public class GsonAutoConfigurationTests {
public
void
withoutLenient
()
{
public
void
withoutLenient
()
{
this
.
contextRunner
.
run
((
context
)
->
{
this
.
contextRunner
.
run
((
context
)
->
{
Gson
gson
=
context
.
getBean
(
Gson
.
class
);
Gson
gson
=
context
.
getBean
(
Gson
.
class
);
/*
assertThat
(
gson
).
hasFieldOrPropertyWithValue
(
"lenient"
,
false
);
* It seems that lenient setting not work in version 2.8.2. We get access to
* it via reflection
*/
Field
lenientField
=
gson
.
getClass
().
getDeclaredField
(
"lenient"
);
lenientField
.
setAccessible
(
true
);
boolean
lenient
=
lenientField
.
getBoolean
(
gson
);
assertThat
(
lenient
).
isFalse
();
});
});
}
}
...
@@ -197,15 +188,7 @@ public class GsonAutoConfigurationTests {
...
@@ -197,15 +188,7 @@ public class GsonAutoConfigurationTests {
this
.
contextRunner
.
withPropertyValues
(
"spring.gson.lenient:true"
)
this
.
contextRunner
.
withPropertyValues
(
"spring.gson.lenient:true"
)
.
run
((
context
)
->
{
.
run
((
context
)
->
{
Gson
gson
=
context
.
getBean
(
Gson
.
class
);
Gson
gson
=
context
.
getBean
(
Gson
.
class
);
/*
assertThat
(
gson
).
hasFieldOrPropertyWithValue
(
"lenient"
,
true
);
* It seems that lenient setting not work in version 2.8.2. We get
* access to it via reflection
*/
Field
lenientField
=
gson
.
getClass
().
getDeclaredField
(
"lenient"
);
lenientField
.
setAccessible
(
true
);
boolean
lenient
=
lenientField
.
getBoolean
(
gson
);
assertThat
(
lenient
).
isTrue
();
});
});
}
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/AbstractJpaAutoConfigurationTests.java
View file @
0f5f6f15
...
@@ -16,7 +16,6 @@
...
@@ -16,7 +16,6 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
orm
.
jpa
;
package
org
.
springframework
.
boot
.
autoconfigure
.
orm
.
jpa
;
import
java.lang.reflect.Field
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.UUID
;
import
java.util.UUID
;
...
@@ -232,11 +231,9 @@ public abstract class AbstractJpaAutoConfigurationTests {
...
@@ -232,11 +231,9 @@ public abstract class AbstractJpaAutoConfigurationTests {
.
run
((
context
)
->
{
.
run
((
context
)
->
{
LocalContainerEntityManagerFactoryBean
entityManagerFactoryBean
=
context
LocalContainerEntityManagerFactoryBean
entityManagerFactoryBean
=
context
.
getBean
(
LocalContainerEntityManagerFactoryBean
.
class
);
.
getBean
(
LocalContainerEntityManagerFactoryBean
.
class
);
Field
field
=
LocalContainerEntityManagerFactoryBean
.
class
assertThat
(
entityManagerFactoryBean
).
hasFieldOrPropertyWithValue
(
.
getDeclaredField
(
"persistenceUnitManager"
);
"persistenceUnitManager"
,
field
.
setAccessible
(
true
);
context
.
getBean
(
PersistenceUnitManager
.
class
));
assertThat
(
field
.
get
(
entityManagerFactoryBean
))
.
isEqualTo
(
context
.
getBean
(
PersistenceUnitManager
.
class
));
});
});
}
}
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java
View file @
0f5f6f15
...
@@ -16,7 +16,6 @@
...
@@ -16,7 +16,6 @@
package
org
.
springframework
.
boot
;
package
org
.
springframework
.
boot
;
import
java.lang.reflect.Field
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashMap
;
...
@@ -96,7 +95,6 @@ import org.springframework.core.io.Resource;
...
@@ -96,7 +95,6 @@ import org.springframework.core.io.Resource;
import
org.springframework.core.io.ResourceLoader
;
import
org.springframework.core.io.ResourceLoader
;
import
org.springframework.http.server.reactive.HttpHandler
;
import
org.springframework.http.server.reactive.HttpHandler
;
import
org.springframework.test.context.support.TestPropertySourceUtils
;
import
org.springframework.test.context.support.TestPropertySourceUtils
;
import
org.springframework.util.ReflectionUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.context.ConfigurableWebEnvironment
;
import
org.springframework.web.context.ConfigurableWebEnvironment
;
import
org.springframework.web.context.WebApplicationContext
;
import
org.springframework.web.context.WebApplicationContext
;
...
@@ -285,24 +283,22 @@ public class SpringApplicationTests {
...
@@ -285,24 +283,22 @@ public class SpringApplicationTests {
}
}
@Test
@Test
public
void
triggersConfigFileApplicationListenerBeforeBinding
()
throws
Exception
{
public
void
triggersConfigFileApplicationListenerBeforeBinding
()
{
SpringApplication
application
=
new
SpringApplication
(
ExampleConfig
.
class
);
SpringApplication
application
=
new
SpringApplication
(
ExampleConfig
.
class
);
application
.
setWebApplicationType
(
WebApplicationType
.
NONE
);
application
.
setWebApplicationType
(
WebApplicationType
.
NONE
);
this
.
context
=
application
.
run
(
"--spring.config.name=bindtoapplication"
);
this
.
context
=
application
.
run
(
"--spring.config.name=bindtoapplication"
);
Field
field
=
ReflectionUtils
.
findField
(
SpringApplication
.
class
,
"bannerMode"
);
assertThat
(
application
).
hasFieldOrPropertyWithValue
(
"bannerMode"
,
field
.
setAccessible
(
true
);
Banner
.
Mode
.
OFF
);
assertThat
((
Banner
.
Mode
)
field
.
get
(
application
)).
isEqualTo
(
Banner
.
Mode
.
OFF
);
}
}
@Test
@Test
public
void
bindsSystemPropertyToSpringApplication
()
throws
Exception
{
public
void
bindsSystemPropertyToSpringApplication
()
{
System
.
setProperty
(
"spring.main.banner-mode"
,
"off"
);
System
.
setProperty
(
"spring.main.banner-mode"
,
"off"
);
SpringApplication
application
=
new
SpringApplication
(
ExampleConfig
.
class
);
SpringApplication
application
=
new
SpringApplication
(
ExampleConfig
.
class
);
application
.
setWebApplicationType
(
WebApplicationType
.
NONE
);
application
.
setWebApplicationType
(
WebApplicationType
.
NONE
);
this
.
context
=
application
.
run
();
this
.
context
=
application
.
run
();
Field
field
=
ReflectionUtils
.
findField
(
SpringApplication
.
class
,
"bannerMode"
);
assertThat
(
application
).
hasFieldOrPropertyWithValue
(
"bannerMode"
,
field
.
setAccessible
(
true
);
Banner
.
Mode
.
OFF
);
assertThat
((
Banner
.
Mode
)
field
.
get
(
application
)).
isEqualTo
(
Banner
.
Mode
.
OFF
);
}
}
@Test
@Test
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContextTests.java
View file @
0f5f6f15
...
@@ -16,7 +16,6 @@
...
@@ -16,7 +16,6 @@
package
org
.
springframework
.
boot
.
web
.
servlet
.
context
;
package
org
.
springframework
.
boot
.
web
.
servlet
.
context
;
import
java.lang.reflect.Field
;
import
java.util.EnumSet
;
import
java.util.EnumSet
;
import
java.util.Properties
;
import
java.util.Properties
;
...
@@ -55,7 +54,6 @@ import org.springframework.boot.web.servlet.ServletRegistrationBean;
...
@@ -55,7 +54,6 @@ import org.springframework.boot.web.servlet.ServletRegistrationBean;
import
org.springframework.boot.web.servlet.server.MockServletWebServerFactory
;
import
org.springframework.boot.web.servlet.server.MockServletWebServerFactory
;
import
org.springframework.context.ApplicationContextException
;
import
org.springframework.context.ApplicationContextException
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.context.support.AbstractApplicationContext
;
import
org.springframework.context.support.PropertySourcesPlaceholderConfigurer
;
import
org.springframework.context.support.PropertySourcesPlaceholderConfigurer
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.core.annotation.Order
;
...
@@ -129,17 +127,13 @@ public class ServletWebServerApplicationContextTests {
...
@@ -129,17 +127,13 @@ public class ServletWebServerApplicationContextTests {
}
}
@Test
@Test
public
void
doesNotRegistersShutdownHook
()
throws
Exception
{
public
void
doesNotRegistersShutdownHook
()
{
// See gh-314 for background. We no longer register the shutdown hook
// See gh-314 for background. We no longer register the shutdown hook
// since it is really the callers responsibility. The shutdown hook could
// since it is really the callers responsibility. The shutdown hook could
// also be problematic in a classic WAR deployment.
// also be problematic in a classic WAR deployment.
addWebServerFactoryBean
();
addWebServerFactoryBean
();
this
.
context
.
refresh
();
this
.
context
.
refresh
();
Field
shutdownHookField
=
AbstractApplicationContext
.
class
assertThat
(
this
.
context
).
hasFieldOrPropertyWithValue
(
"shutdownHook"
,
null
);
.
getDeclaredField
(
"shutdownHook"
);
shutdownHookField
.
setAccessible
(
true
);
Object
shutdownHook
=
shutdownHookField
.
get
(
this
.
context
);
assertThat
(
shutdownHook
).
isNull
();
}
}
@Test
@Test
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment