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
a869d25d
Commit
a869d25d
authored
Jul 27, 2017
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
eac4c7e8
Changes
17
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
566 additions
and
573 deletions
+566
-573
SpringApplicationAdminJmxAutoConfigurationTests.java
...dmin/SpringApplicationAdminJmxAutoConfigurationTests.java
+20
-19
RabbitAutoConfigurationTests.java
...boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java
+253
-222
AopAutoConfigurationTests.java
...ork/boot/autoconfigure/aop/AopAutoConfigurationTests.java
+6
-6
BatchAutoConfigurationTests.java
...boot/autoconfigure/batch/BatchAutoConfigurationTests.java
+135
-116
BatchAutoConfigurationWithoutJpaTests.java
...onfigure/batch/BatchAutoConfigurationWithoutJpaTests.java
+36
-33
JobLauncherCommandLineRunnerTests.java
...utoconfigure/batch/JobLauncherCommandLineRunnerTests.java
+1
-2
CassandraAutoConfigurationTests.java
...oconfigure/cassandra/CassandraAutoConfigurationTests.java
+33
-30
ConditionalOnBeanTests.java
.../boot/autoconfigure/condition/ConditionalOnBeanTests.java
+27
-28
ConditionalOnClassTests.java
...boot/autoconfigure/condition/ConditionalOnClassTests.java
+18
-19
ConditionalOnCloudPlatformTests.java
...oconfigure/condition/ConditionalOnCloudPlatformTests.java
+3
-16
ConditionalOnExpressionTests.java
...autoconfigure/condition/ConditionalOnExpressionTests.java
+3
-17
ConditionalOnJavaTests.java
.../boot/autoconfigure/condition/ConditionalOnJavaTests.java
+7
-19
ConditionalOnJndiTests.java
.../boot/autoconfigure/condition/ConditionalOnJndiTests.java
+10
-19
AbstractApplicationContextRunner.java
...test/context/runner/AbstractApplicationContextRunner.java
+4
-11
JsonContent.java
.../java/org/springframework/boot/test/json/JsonContent.java
+1
-1
TestPropertyValues.java
...rg/springframework/boot/test/util/TestPropertyValues.java
+7
-14
AbstractApplicationContextRunnerTests.java
...context/runner/AbstractApplicationContextRunnerTests.java
+2
-1
No files found.
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfigurationTests.java
View file @
a869d25d
...
@@ -59,7 +59,7 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
...
@@ -59,7 +59,7 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
@Rule
@Rule
public
final
ExpectedException
thrown
=
ExpectedException
.
none
();
public
final
ExpectedException
thrown
=
ExpectedException
.
none
();
private
final
MBeanServer
mBeanS
erver
=
ManagementFactory
.
getPlatformMBeanServer
();
private
final
MBeanServer
s
erver
=
ManagementFactory
.
getPlatformMBeanServer
();
private
final
ApplicationContextRunner
contextRunner
=
new
ApplicationContextRunner
()
private
final
ApplicationContextRunner
contextRunner
=
new
ApplicationContextRunner
()
.
withConfiguration
(
AutoConfigurations
.
of
(
JmxAutoConfiguration
.
class
,
.
withConfiguration
(
AutoConfigurations
.
of
(
JmxAutoConfiguration
.
class
,
...
@@ -70,7 +70,7 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
...
@@ -70,7 +70,7 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
throws
MalformedObjectNameException
,
InstanceNotFoundException
{
throws
MalformedObjectNameException
,
InstanceNotFoundException
{
this
.
contextRunner
.
run
((
context
)
->
{
this
.
contextRunner
.
run
((
context
)
->
{
this
.
thrown
.
expect
(
InstanceNotFoundException
.
class
);
this
.
thrown
.
expect
(
InstanceNotFoundException
.
class
);
this
.
mBeanS
erver
.
getObjectInstance
(
createDefaultObjectName
());
this
.
s
erver
.
getObjectInstance
(
createDefaultObjectName
());
});
});
}
}
...
@@ -78,7 +78,7 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
...
@@ -78,7 +78,7 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
public
void
registeredWithProperty
()
throws
Exception
{
public
void
registeredWithProperty
()
throws
Exception
{
this
.
contextRunner
.
withPropertyValues
(
ENABLE_ADMIN_PROP
).
run
((
context
)
->
{
this
.
contextRunner
.
withPropertyValues
(
ENABLE_ADMIN_PROP
).
run
((
context
)
->
{
ObjectName
objectName
=
createDefaultObjectName
();
ObjectName
objectName
=
createDefaultObjectName
();
ObjectInstance
objectInstance
=
this
.
mBeanS
erver
.
getObjectInstance
(
objectName
);
ObjectInstance
objectInstance
=
this
.
s
erver
.
getObjectInstance
(
objectName
);
assertThat
(
objectInstance
).
as
(
"Lifecycle bean should have been registered"
)
assertThat
(
objectInstance
).
as
(
"Lifecycle bean should have been registered"
)
.
isNotNull
();
.
isNotNull
();
});
});
...
@@ -87,17 +87,19 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
...
@@ -87,17 +87,19 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
@Test
@Test
public
void
registerWithCustomJmxName
()
throws
InstanceNotFoundException
{
public
void
registerWithCustomJmxName
()
throws
InstanceNotFoundException
{
String
customJmxName
=
"org.acme:name=FooBar"
;
String
customJmxName
=
"org.acme:name=FooBar"
;
this
.
contextRunner
.
withSystemProperties
(
this
.
contextRunner
.
withSystemProperties
(
"spring.application.admin.jmx-name="
+
customJmxName
)
"spring.application.admin.jmx-name="
+
customJmxName
)
.
withPropertyValues
(
ENABLE_ADMIN_PROP
).
run
((
context
)
->
{
.
withPropertyValues
(
ENABLE_ADMIN_PROP
).
run
((
context
)
->
{
try
{
try
{
this
.
mBeanS
erver
.
getObjectInstance
(
createObjectName
(
customJmxName
));
this
.
s
erver
.
getObjectInstance
(
createObjectName
(
customJmxName
));
}
}
catch
(
InstanceNotFoundException
ex
)
{
catch
(
InstanceNotFoundException
ex
)
{
fail
(
"Admin MBean should have been exposed with custom name"
);
fail
(
"Admin MBean should have been exposed with custom name"
);
}
}
this
.
thrown
.
expect
(
InstanceNotFoundException
.
class
);
// Should not be exposed
this
.
thrown
.
expect
(
InstanceNotFoundException
.
class
);
// Should not be
this
.
mBeanServer
.
getObjectInstance
(
createDefaultObjectName
());
// exposed
this
.
server
.
getObjectInstance
(
createDefaultObjectName
());
});
});
}
}
...
@@ -110,7 +112,7 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
...
@@ -110,7 +112,7 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
SpringApplicationAdminJmxAutoConfiguration
.
class
)
SpringApplicationAdminJmxAutoConfiguration
.
class
)
.
run
(
"--"
+
ENABLE_ADMIN_PROP
,
"--server.port=0"
))
{
.
run
(
"--"
+
ENABLE_ADMIN_PROP
,
"--server.port=0"
))
{
assertThat
(
context
).
isInstanceOf
(
ServletWebServerApplicationContext
.
class
);
assertThat
(
context
).
isInstanceOf
(
ServletWebServerApplicationContext
.
class
);
assertThat
(
this
.
mBeanS
erver
.
getAttribute
(
createDefaultObjectName
(),
assertThat
(
this
.
s
erver
.
getAttribute
(
createDefaultObjectName
(),
"EmbeddedWebApplication"
)).
isEqualTo
(
Boolean
.
TRUE
);
"EmbeddedWebApplication"
)).
isEqualTo
(
Boolean
.
TRUE
);
int
expected
=
((
ServletWebServerApplicationContext
)
context
).
getWebServer
()
int
expected
=
((
ServletWebServerApplicationContext
)
context
).
getWebServer
()
.
getPort
();
.
getPort
();
...
@@ -128,7 +130,6 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
...
@@ -128,7 +130,6 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
.
child
(
JmxAutoConfiguration
.
class
,
.
child
(
JmxAutoConfiguration
.
class
,
SpringApplicationAdminJmxAutoConfiguration
.
class
)
SpringApplicationAdminJmxAutoConfiguration
.
class
)
.
web
(
WebApplicationType
.
NONE
);
.
web
(
WebApplicationType
.
NONE
);
try
(
ConfigurableApplicationContext
parent
=
parentBuilder
try
(
ConfigurableApplicationContext
parent
=
parentBuilder
.
run
(
"--"
+
ENABLE_ADMIN_PROP
);
.
run
(
"--"
+
ENABLE_ADMIN_PROP
);
ConfigurableApplicationContext
child
=
childBuilder
ConfigurableApplicationContext
child
=
childBuilder
...
@@ -155,7 +156,7 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
...
@@ -155,7 +156,7 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
}
}
private
String
getProperty
(
ObjectName
objectName
,
String
key
)
throws
Exception
{
private
String
getProperty
(
ObjectName
objectName
,
String
key
)
throws
Exception
{
return
(
String
)
this
.
mBeanS
erver
.
invoke
(
objectName
,
"getProperty"
,
return
(
String
)
this
.
s
erver
.
invoke
(
objectName
,
"getProperty"
,
new
Object
[]
{
key
},
new
String
[]
{
String
.
class
.
getName
()
});
new
Object
[]
{
key
},
new
String
[]
{
String
.
class
.
getName
()
});
}
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java
View file @
a869d25d
This diff is collapsed.
Click to expand it.
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/aop/AopAutoConfigurationTests.java
View file @
a869d25d
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java
View file @
a869d25d
This diff is collapsed.
Click to expand it.
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationWithoutJpaTests.java
View file @
a869d25d
...
@@ -54,42 +54,45 @@ public class BatchAutoConfigurationWithoutJpaTests {
...
@@ -54,42 +54,45 @@ public class BatchAutoConfigurationWithoutJpaTests {
@Test
@Test
public
void
jdbcWithDefaultSettings
()
throws
Exception
{
public
void
jdbcWithDefaultSettings
()
throws
Exception
{
this
.
contextRunner
.
withUserConfiguration
(
DefaultConfiguration
.
class
,
this
.
contextRunner
EmbeddedDataSourceConfiguration
.
class
).
withPropertyValues
(
.
withUserConfiguration
(
DefaultConfiguration
.
class
,
"spring.datasource.generate-unique-name=true"
).
run
((
context
)
->
{
EmbeddedDataSourceConfiguration
.
class
)
.
withPropertyValues
(
"spring.datasource.generate-unique-name=true"
)
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
JobLauncher
.
class
);
assertThat
(
context
).
hasSingleBean
(
JobLauncher
.
class
);
assertThat
(
context
).
hasSingleBean
(
JobExplorer
.
class
);
assertThat
(
context
).
hasSingleBean
(
JobExplorer
.
class
);
assertThat
(
context
).
hasSingleBean
(
JobRepository
.
class
);
assertThat
(
context
).
hasSingleBean
(
JobRepository
.
class
);
assertThat
(
context
).
hasSingleBean
(
PlatformTransactionManager
.
class
);
assertThat
(
context
).
hasSingleBean
(
PlatformTransactionManager
.
class
);
assertThat
(
context
.
getBean
(
PlatformTransactionManager
.
class
).
toString
())
.
contains
(
"DataSourceTransactionManager"
);
assertThat
(
assertThat
(
context
.
getBean
(
BatchProperties
.
class
).
getInitializer
().
isEnabled
())
context
.
getBean
(
PlatformTransactionManager
.
class
).
toString
())
.
isTrue
();
.
contains
(
"DataSourceTransactionManager"
);
assertThat
(
context
.
getBean
(
BatchProperties
.
class
).
getInitializer
()
.
isEnabled
()).
isTrue
();
assertThat
(
new
JdbcTemplate
(
context
.
getBean
(
DataSource
.
class
))
assertThat
(
new
JdbcTemplate
(
context
.
getBean
(
DataSource
.
class
))
.
queryForList
(
"select * from BATCH_JOB_EXECUTION"
)).
isEmpty
();
.
queryForList
(
"select * from BATCH_JOB_EXECUTION"
)).
isEmpty
();
assertThat
(
assertThat
(
context
.
getBean
(
JobExplorer
.
class
)
context
.
getBean
(
JobExplorer
.
class
).
findRunningJobExecutions
(
"test"
))
.
findRunningJobExecutions
(
"test"
)).
isEmpty
();
.
isEmpty
();
assertThat
(
context
.
getBean
(
JobRepository
.
class
)
assertThat
(
context
.
getBean
(
JobRepository
.
class
).
getLastJobExecution
(
"test"
,
.
getLastJobExecution
(
"test"
,
new
JobParameters
())).
isNull
();
new
JobParameters
())).
isNull
();
});
});
}
}
@Test
@Test
public
void
jdbcWithCustomPrefix
()
throws
Exception
{
public
void
jdbcWithCustomPrefix
()
throws
Exception
{
this
.
contextRunner
.
withUserConfiguration
(
DefaultConfiguration
.
class
,
this
.
contextRunner
EmbeddedDataSourceConfiguration
.
class
).
withPropertyValues
(
.
withUserConfiguration
(
DefaultConfiguration
.
class
,
"spring.datasource.generate-unique-name=true"
,
EmbeddedDataSourceConfiguration
.
class
)
.
withPropertyValues
(
"spring.datasource.generate-unique-name=true"
,
"spring.batch.schema:classpath:batch/custom-schema-hsql.sql"
,
"spring.batch.schema:classpath:batch/custom-schema-hsql.sql"
,
"spring.batch.tablePrefix:PREFIX_"
).
run
((
context
)
->
{
"spring.batch.tablePrefix:PREFIX_"
)
.
run
((
context
)
->
{
assertThat
(
new
JdbcTemplate
(
context
.
getBean
(
DataSource
.
class
))
assertThat
(
new
JdbcTemplate
(
context
.
getBean
(
DataSource
.
class
))
.
queryForList
(
"select * from PREFIX_JOB_EXECUTION"
)).
isEmpty
();
.
queryForList
(
"select * from PREFIX_JOB_EXECUTION"
))
assertThat
(
context
.
getBean
(
JobExplorer
.
class
).
findRunningJobExecutions
(
"test"
))
.
isEmpty
();
.
isEmpty
();
assertThat
(
context
.
getBean
(
JobRepository
.
class
).
getLastJobExecution
(
"test"
,
assertThat
(
context
.
getBean
(
JobExplorer
.
class
)
new
JobParameters
())).
isNull
();
.
findRunningJobExecutions
(
"test"
)).
isEmpty
();
assertThat
(
context
.
getBean
(
JobRepository
.
class
)
.
getLastJobExecution
(
"test"
,
new
JobParameters
())).
isNull
();
});
});
}
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/JobLauncherCommandLineRunnerTests.java
View file @
a869d25d
...
@@ -80,8 +80,7 @@ public class JobLauncherCommandLineRunnerTests {
...
@@ -80,8 +80,7 @@ public class JobLauncherCommandLineRunnerTests {
this
.
step
=
this
.
steps
.
get
(
"step"
).
tasklet
(
tasklet
).
build
();
this
.
step
=
this
.
steps
.
get
(
"step"
).
tasklet
(
tasklet
).
build
();
this
.
job
=
this
.
jobs
.
get
(
"job"
).
start
(
this
.
step
).
build
();
this
.
job
=
this
.
jobs
.
get
(
"job"
).
start
(
this
.
step
).
build
();
this
.
jobExplorer
=
this
.
context
.
getBean
(
JobExplorer
.
class
);
this
.
jobExplorer
=
this
.
context
.
getBean
(
JobExplorer
.
class
);
this
.
runner
=
new
JobLauncherCommandLineRunner
(
jobLauncher
,
this
.
runner
=
new
JobLauncherCommandLineRunner
(
jobLauncher
,
this
.
jobExplorer
);
this
.
jobExplorer
);
this
.
context
.
getBean
(
BatchConfiguration
.
class
).
clear
();
this
.
context
.
getBean
(
BatchConfiguration
.
class
).
clear
();
}
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfigurationTests.java
View file @
a869d25d
...
@@ -50,8 +50,9 @@ public class CassandraAutoConfigurationTests {
...
@@ -50,8 +50,9 @@ public class CassandraAutoConfigurationTests {
@Test
@Test
public
void
createClusterWithOverrides
()
{
public
void
createClusterWithOverrides
()
{
this
.
contextRunner
.
withPropertyValues
(
this
.
contextRunner
"spring.data.cassandra.cluster-name=testcluster"
).
run
((
context
)
->
{
.
withPropertyValues
(
"spring.data.cassandra.cluster-name=testcluster"
)
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
Cluster
.
class
);
assertThat
(
context
).
hasSingleBean
(
Cluster
.
class
);
assertThat
(
context
.
getBean
(
Cluster
.
class
).
getClusterName
())
assertThat
(
context
.
getBean
(
Cluster
.
class
).
getClusterName
())
.
isEqualTo
(
"testcluster"
);
.
isEqualTo
(
"testcluster"
);
...
@@ -60,8 +61,8 @@ public class CassandraAutoConfigurationTests {
...
@@ -60,8 +61,8 @@ public class CassandraAutoConfigurationTests {
@Test
@Test
public
void
createCustomizeCluster
()
{
public
void
createCustomizeCluster
()
{
this
.
contextRunner
.
withUserConfiguration
(
this
.
contextRunner
.
withUserConfiguration
(
MockCustomizerConfig
.
class
)
MockCustomizerConfig
.
class
)
.
run
((
context
)
->
{
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
Cluster
.
class
);
assertThat
(
context
).
hasSingleBean
(
Cluster
.
class
);
assertThat
(
context
).
hasSingleBean
(
ClusterBuilderCustomizer
.
class
);
assertThat
(
context
).
hasSingleBean
(
ClusterBuilderCustomizer
.
class
);
});
});
...
@@ -70,7 +71,8 @@ public class CassandraAutoConfigurationTests {
...
@@ -70,7 +71,8 @@ public class CassandraAutoConfigurationTests {
@Test
@Test
public
void
customizerOverridesAutoConfig
()
{
public
void
customizerOverridesAutoConfig
()
{
this
.
contextRunner
.
withUserConfiguration
(
SimpleCustomizerConfig
.
class
)
this
.
contextRunner
.
withUserConfiguration
(
SimpleCustomizerConfig
.
class
)
.
withPropertyValues
(
"spring.data.cassandra.cluster-name=testcluster"
).
run
((
context
)
->
{
.
withPropertyValues
(
"spring.data.cassandra.cluster-name=testcluster"
)
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
Cluster
.
class
);
assertThat
(
context
).
hasSingleBean
(
Cluster
.
class
);
assertThat
(
context
.
getBean
(
Cluster
.
class
).
getClusterName
())
assertThat
(
context
.
getBean
(
Cluster
.
class
).
getClusterName
())
.
isEqualTo
(
"overridden-name"
);
.
isEqualTo
(
"overridden-name"
);
...
@@ -96,22 +98,23 @@ public class CassandraAutoConfigurationTests {
...
@@ -96,22 +98,23 @@ public class CassandraAutoConfigurationTests {
@Test
@Test
public
void
customizePoolOptions
()
{
public
void
customizePoolOptions
()
{
this
.
contextRunner
.
withPropertyValues
(
this
.
contextRunner
"spring.data.cassandra.pool.idle-timeout=42"
,
.
withPropertyValues
(
"spring.data.cassandra.pool.idle-timeout=42"
,
"spring.data.cassandra.pool.pool-timeout=52"
,
"spring.data.cassandra.pool.pool-timeout=52"
,
"spring.data.cassandra.pool.heartbeat-interval=62"
,
"spring.data.cassandra.pool.heartbeat-interval=62"
,
"spring.data.cassandra.pool.max-queue-size=72"
).
run
((
context
)
->
{
"spring.data.cassandra.pool.max-queue-size=72"
)
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
Cluster
.
class
);
assertThat
(
context
).
hasSingleBean
(
Cluster
.
class
);
PoolingOptions
poolingOptions
=
context
.
getBean
(
Cluster
.
class
)
PoolingOptions
poolingOptions
=
context
.
getBean
(
Cluster
.
class
)
.
getConfiguration
().
getPoolingOptions
();
.
getConfiguration
().
getPoolingOptions
();
assertThat
(
poolingOptions
.
getIdleTimeoutSeconds
()).
isEqualTo
(
42
);
assertThat
(
poolingOptions
.
getIdleTimeoutSeconds
()).
isEqualTo
(
42
);
assertThat
(
poolingOptions
.
getPoolTimeoutMillis
()).
isEqualTo
(
52
);
assertThat
(
poolingOptions
.
getPoolTimeoutMillis
()).
isEqualTo
(
52
);
assertThat
(
poolingOptions
.
getHeartbeatIntervalSeconds
()).
isEqualTo
(
62
);
assertThat
(
poolingOptions
.
getHeartbeatIntervalSeconds
())
.
isEqualTo
(
62
);
assertThat
(
poolingOptions
.
getMaxQueueSize
()).
isEqualTo
(
72
);
assertThat
(
poolingOptions
.
getMaxQueueSize
()).
isEqualTo
(
72
);
});
});
}
}
@Configuration
@Configuration
static
class
MockCustomizerConfig
{
static
class
MockCustomizerConfig
{
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnBeanTests.java
View file @
a869d25d
...
@@ -30,7 +30,6 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
...
@@ -30,7 +30,6 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import
org.springframework.beans.factory.support.RootBeanDefinition
;
import
org.springframework.beans.factory.support.RootBeanDefinition
;
import
org.springframework.boot.test.context.assertj.AssertableApplicationContext
;
import
org.springframework.boot.test.context.assertj.AssertableApplicationContext
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ContextConsumer
;
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.context.annotation.Import
;
import
org.springframework.context.annotation.Import
;
...
@@ -55,40 +54,42 @@ public class ConditionalOnBeanTests {
...
@@ -55,40 +54,42 @@ public class ConditionalOnBeanTests {
@Test
@Test
public
void
testNameOnBeanCondition
()
{
public
void
testNameOnBeanCondition
()
{
this
.
contextRunner
.
withUserConfiguration
(
FooConfiguration
.
class
,
this
.
contextRunner
.
withUserConfiguration
(
FooConfiguration
.
class
,
OnBeanNameConfiguration
.
class
).
run
(
hasBarBean
()
);
OnBeanNameConfiguration
.
class
).
run
(
this
::
hasBarBean
);
}
}
@Test
@Test
public
void
testNameAndTypeOnBeanCondition
()
{
public
void
testNameAndTypeOnBeanCondition
()
{
this
.
contextRunner
.
withUserConfiguration
(
FooConfiguration
.
class
,
this
.
contextRunner
OnBeanNameAndTypeConfiguration
.
class
).
run
((
context
)
->
.
withUserConfiguration
(
FooConfiguration
.
class
,
assertThat
(
context
).
doesNotHaveBean
(
"bar"
));
OnBeanNameAndTypeConfiguration
.
class
)
.
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
"bar"
));
}
}
@Test
@Test
public
void
testNameOnBeanConditionReverseOrder
()
{
public
void
testNameOnBeanConditionReverseOrder
()
{
// Ideally this should be true
// Ideally this should be true
this
.
contextRunner
.
withUserConfiguration
(
OnBeanNameConfiguration
.
class
,
this
.
contextRunner
FooConfiguration
.
class
).
run
((
context
)
->
.
withUserConfiguration
(
OnBeanNameConfiguration
.
class
,
assertThat
(
context
).
doesNotHaveBean
(
"bar"
));
FooConfiguration
.
class
)
.
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
"bar"
));
}
}
@Test
@Test
public
void
testClassOnBeanCondition
()
{
public
void
testClassOnBeanCondition
()
{
this
.
contextRunner
.
withUserConfiguration
(
FooConfiguration
.
class
,
this
.
contextRunner
.
withUserConfiguration
(
FooConfiguration
.
class
,
OnBeanClassConfiguration
.
class
).
run
(
hasBarBean
()
);
OnBeanClassConfiguration
.
class
).
run
(
this
::
hasBarBean
);
}
}
@Test
@Test
public
void
testClassOnBeanClassNameCondition
()
{
public
void
testClassOnBeanClassNameCondition
()
{
this
.
contextRunner
.
withUserConfiguration
(
FooConfiguration
.
class
,
this
.
contextRunner
.
withUserConfiguration
(
FooConfiguration
.
class
,
OnBeanClassNameConfiguration
.
class
).
run
(
hasBarBean
()
);
OnBeanClassNameConfiguration
.
class
).
run
(
this
::
hasBarBean
);
}
}
@Test
@Test
public
void
testOnBeanConditionWithXml
()
{
public
void
testOnBeanConditionWithXml
()
{
this
.
contextRunner
.
withUserConfiguration
(
XmlConfiguration
.
class
,
this
.
contextRunner
.
withUserConfiguration
(
XmlConfiguration
.
class
,
OnBeanNameConfiguration
.
class
).
run
(
hasBarBean
()
);
OnBeanNameConfiguration
.
class
).
run
(
this
::
hasBarBean
);
}
}
@Test
@Test
...
@@ -101,20 +102,21 @@ public class ConditionalOnBeanTests {
...
@@ -101,20 +102,21 @@ public class ConditionalOnBeanTests {
@Test
@Test
public
void
testAnnotationOnBeanCondition
()
{
public
void
testAnnotationOnBeanCondition
()
{
this
.
contextRunner
.
withUserConfiguration
(
FooConfiguration
.
class
,
this
.
contextRunner
.
withUserConfiguration
(
FooConfiguration
.
class
,
OnAnnotationConfiguration
.
class
).
run
(
hasBarBean
()
);
OnAnnotationConfiguration
.
class
).
run
(
this
::
hasBarBean
);
}
}
@Test
@Test
public
void
testOnMissingBeanType
()
throws
Exception
{
public
void
testOnMissingBeanType
()
throws
Exception
{
this
.
contextRunner
.
withUserConfiguration
(
FooConfiguration
.
class
,
this
.
contextRunner
OnBeanMissingClassConfiguration
.
class
).
run
((
context
)
->
.
withUserConfiguration
(
FooConfiguration
.
class
,
assertThat
(
context
).
doesNotHaveBean
(
"bar"
));
OnBeanMissingClassConfiguration
.
class
)
.
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
"bar"
));
}
}
@Test
@Test
public
void
withPropertyPlaceholderClassName
()
throws
Exception
{
public
void
withPropertyPlaceholderClassName
()
throws
Exception
{
this
.
contextRunner
.
withUserConfiguration
(
this
.
contextRunner
PropertySourcesPlaceholderConfigurer
.
class
,
.
withUserConfiguration
(
PropertySourcesPlaceholderConfigurer
.
class
,
WithPropertyPlaceholderClassName
.
class
,
WithPropertyPlaceholderClassName
.
class
,
OnBeanClassConfiguration
.
class
)
OnBeanClassConfiguration
.
class
)
.
withPropertyValues
(
"mybeanclass=java.lang.String"
)
.
withPropertyValues
(
"mybeanclass=java.lang.String"
)
...
@@ -130,14 +132,11 @@ public class ConditionalOnBeanTests {
...
@@ -130,14 +132,11 @@ public class ConditionalOnBeanTests {
});
});
}
}
private
ContextConsumer
<
AssertableApplicationContext
>
hasBarBean
()
{
private
void
hasBarBean
(
AssertableApplicationContext
context
)
{
return
(
context
)
->
{
assertThat
(
context
).
hasBean
(
"bar"
);
assertThat
(
context
).
hasBean
(
"bar"
);
assertThat
(
context
.
getBean
(
"bar"
)).
isEqualTo
(
"bar"
);
assertThat
(
context
.
getBean
(
"bar"
)).
isEqualTo
(
"bar"
);
};
}
}
@Configuration
@Configuration
@ConditionalOnBean
(
name
=
"foo"
)
@ConditionalOnBean
(
name
=
"foo"
)
protected
static
class
OnBeanNameConfiguration
{
protected
static
class
OnBeanNameConfiguration
{
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnClassTests.java
View file @
a869d25d
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -20,7 +20,6 @@ import org.junit.Test;
...
@@ -20,7 +20,6 @@ import org.junit.Test;
import
org.springframework.boot.test.context.assertj.AssertableApplicationContext
;
import
org.springframework.boot.test.context.assertj.AssertableApplicationContext
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ContextConsumer
;
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.context.annotation.Import
;
import
org.springframework.context.annotation.Import
;
...
@@ -40,38 +39,38 @@ public class ConditionalOnClassTests {
...
@@ -40,38 +39,38 @@ public class ConditionalOnClassTests {
@Test
@Test
public
void
testVanillaOnClassCondition
()
{
public
void
testVanillaOnClassCondition
()
{
this
.
contextRunner
.
withUserConfiguration
(
BasicConfiguration
.
class
,
this
.
contextRunner
FooConfiguration
.
class
).
run
(
hasBarBean
());
.
withUserConfiguration
(
BasicConfiguration
.
class
,
FooConfiguration
.
class
)
.
run
(
this
::
hasBarBean
);
}
}
@Test
@Test
public
void
testMissingOnClassCondition
()
{
public
void
testMissingOnClassCondition
()
{
this
.
contextRunner
.
withUserConfiguration
(
MissingConfiguration
.
class
,
this
.
contextRunner
FooConfiguration
.
class
).
run
((
context
)
->
{
.
withUserConfiguration
(
MissingConfiguration
.
class
,
FooConfiguration
.
class
)
.
run
((
context
)
->
{
assertThat
(
context
).
doesNotHaveBean
(
"bar"
);
assertThat
(
context
).
doesNotHaveBean
(
"bar"
);
assertThat
(
context
).
hasBean
(
"foo"
);
assertThat
(
context
).
hasBean
(
"foo"
);
assertThat
(
context
.
getBean
(
"foo"
)).
isEqualTo
(
"foo"
);
assertThat
(
context
.
getBean
(
"foo"
)).
isEqualTo
(
"foo"
);
});
});
}
}
@Test
@Test
public
void
testOnClassConditionWithXml
()
{
public
void
testOnClassConditionWithXml
()
{
this
.
contextRunner
.
withUserConfiguration
(
BasicConfiguration
.
class
,
this
.
contextRunner
XmlConfiguration
.
class
).
run
(
hasBarBean
());
.
withUserConfiguration
(
BasicConfiguration
.
class
,
XmlConfiguration
.
class
)
.
run
(
this
::
hasBarBean
);
}
}
@Test
@Test
public
void
testOnClassConditionWithCombinedXml
()
{
public
void
testOnClassConditionWithCombinedXml
()
{
this
.
contextRunner
.
withUserConfiguration
(
CombinedXmlConfiguration
.
class
)
this
.
contextRunner
.
withUserConfiguration
(
CombinedXmlConfiguration
.
class
)
.
run
(
hasBarBean
()
);
.
run
(
this
::
hasBarBean
);
}
}
private
ContextConsumer
<
AssertableApplicationContext
>
hasBarBean
()
{
private
void
hasBarBean
(
AssertableApplicationContext
context
)
{
return
(
context
)
->
{
assertThat
(
context
).
hasBean
(
"bar"
);
assertThat
(
context
).
hasBean
(
"bar"
);
assertThat
(
context
.
getBean
(
"bar"
)).
isEqualTo
(
"bar"
);
assertThat
(
context
.
getBean
(
"bar"
)).
isEqualTo
(
"bar"
);
};
}
}
@Configuration
@Configuration
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnCloudPlatformTests.java
View file @
a869d25d
...
@@ -19,9 +19,7 @@ package org.springframework.boot.autoconfigure.condition;
...
@@ -19,9 +19,7 @@ package org.springframework.boot.autoconfigure.condition;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.boot.cloud.CloudPlatform
;
import
org.springframework.boot.cloud.CloudPlatform
;
import
org.springframework.boot.test.context.assertj.AssertableApplicationContext
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ContextConsumer
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
...
@@ -37,32 +35,21 @@ public class ConditionalOnCloudPlatformTests {
...
@@ -37,32 +35,21 @@ public class ConditionalOnCloudPlatformTests {
@Test
@Test
public
void
outcomeWhenCloudfoundryPlatformNotPresentShouldNotMatch
()
{
public
void
outcomeWhenCloudfoundryPlatformNotPresentShouldNotMatch
()
{
this
.
contextRunner
.
withUserConfiguration
(
CloudFoundryPlatformConfig
.
class
)
this
.
contextRunner
.
withUserConfiguration
(
CloudFoundryPlatformConfig
.
class
)
.
run
(
match
(
false
));
.
run
(
(
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
"foo"
));
}
}
@Test
@Test
public
void
outcomeWhenCloudfoundryPlatformPresentShouldMatch
()
{
public
void
outcomeWhenCloudfoundryPlatformPresentShouldMatch
()
{
this
.
contextRunner
.
withUserConfiguration
(
CloudFoundryPlatformConfig
.
class
)
this
.
contextRunner
.
withUserConfiguration
(
CloudFoundryPlatformConfig
.
class
)
.
withPropertyValues
(
"VCAP_APPLICATION:---"
)
.
withPropertyValues
(
"VCAP_APPLICATION:---"
)
.
run
(
match
(
true
));
.
run
(
(
context
)
->
assertThat
(
context
).
hasBean
(
"foo"
));
}
}
@Test
@Test
public
void
outcomeWhenCloudfoundryPlatformPresentAndMethodTargetShouldMatch
()
{
public
void
outcomeWhenCloudfoundryPlatformPresentAndMethodTargetShouldMatch
()
{
this
.
contextRunner
.
withUserConfiguration
(
CloudFoundryPlatformOnMethodConfig
.
class
)
this
.
contextRunner
.
withUserConfiguration
(
CloudFoundryPlatformOnMethodConfig
.
class
)
.
withPropertyValues
(
"VCAP_APPLICATION:---"
)
.
withPropertyValues
(
"VCAP_APPLICATION:---"
)
.
run
(
match
(
true
));
.
run
((
context
)
->
assertThat
(
context
).
hasBean
(
"foo"
));
}
private
ContextConsumer
<
AssertableApplicationContext
>
match
(
boolean
expected
)
{
return
(
context
)
->
{
if
(
expected
)
{
assertThat
(
context
).
hasBean
(
"foo"
);
}
else
{
assertThat
(
context
).
doesNotHaveBean
(
"foo"
);
}
};
}
}
@Configuration
@Configuration
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnExpressionTests.java
View file @
a869d25d
...
@@ -18,9 +18,7 @@ package org.springframework.boot.autoconfigure.condition;
...
@@ -18,9 +18,7 @@ package org.springframework.boot.autoconfigure.condition;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.boot.test.context.assertj.AssertableApplicationContext
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ContextConsumer
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
...
@@ -39,31 +37,19 @@ public class ConditionalOnExpressionTests {
...
@@ -39,31 +37,19 @@ public class ConditionalOnExpressionTests {
@Test
@Test
public
void
expressionIsTrue
()
{
public
void
expressionIsTrue
()
{
this
.
contextRunner
.
withUserConfiguration
(
BasicConfiguration
.
class
)
this
.
contextRunner
.
withUserConfiguration
(
BasicConfiguration
.
class
)
.
run
(
match
(
true
));
.
run
(
(
context
)
->
assertThat
(
context
.
getBean
(
"foo"
)).
isEqualTo
(
"foo"
));
}
}
@Test
@Test
public
void
expressionIsFalse
()
{
public
void
expressionIsFalse
()
{
this
.
contextRunner
.
withUserConfiguration
(
MissingConfiguration
.
class
)
this
.
contextRunner
.
withUserConfiguration
(
MissingConfiguration
.
class
)
.
run
(
match
(
false
));
.
run
(
(
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
"foo"
));
}
}
@Test
@Test
public
void
expressionIsNull
()
{
public
void
expressionIsNull
()
{
this
.
contextRunner
.
withUserConfiguration
(
NullConfiguration
.
class
)
this
.
contextRunner
.
withUserConfiguration
(
NullConfiguration
.
class
)
.
run
(
match
(
false
));
.
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
"foo"
));
}
private
ContextConsumer
<
AssertableApplicationContext
>
match
(
boolean
expected
)
{
return
(
context
)
->
{
if
(
expected
)
{
assertThat
(
context
).
hasBean
(
"foo"
);
assertThat
(
context
.
getBean
(
"foo"
)).
isEqualTo
(
"foo"
);
}
else
{
assertThat
(
context
).
doesNotHaveBean
(
"foo"
);
}
};
}
}
@Configuration
@Configuration
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnJavaTests.java
View file @
a869d25d
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -29,9 +29,7 @@ import org.junit.Test;
...
@@ -29,9 +29,7 @@ import org.junit.Test;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnJava.JavaVersion
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnJava.JavaVersion
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnJava.Range
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnJava.Range
;
import
org.springframework.boot.test.context.assertj.AssertableApplicationContext
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ContextConsumer
;
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
org.springframework.util.ReflectionUtils
;
...
@@ -52,17 +50,20 @@ public class ConditionalOnJavaTests {
...
@@ -52,17 +50,20 @@ public class ConditionalOnJavaTests {
@Test
@Test
public
void
doesNotMatchIfBetterVersionIsRequired
()
{
public
void
doesNotMatchIfBetterVersionIsRequired
()
{
this
.
contextRunner
.
withUserConfiguration
(
Java9Required
.
class
).
run
(
match
(
false
));
this
.
contextRunner
.
withUserConfiguration
(
Java9Required
.
class
)
.
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
String
.
class
));
}
}
@Test
@Test
public
void
doesNotMatchIfLowerIsRequired
()
{
public
void
doesNotMatchIfLowerIsRequired
()
{
this
.
contextRunner
.
withUserConfiguration
(
Java7Required
.
class
).
run
(
match
(
false
));
this
.
contextRunner
.
withUserConfiguration
(
Java7Required
.
class
)
.
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
String
.
class
));
}
}
@Test
@Test
public
void
matchesIfVersionIsInRange
()
{
public
void
matchesIfVersionIsInRange
()
{
this
.
contextRunner
.
withUserConfiguration
(
Java8Required
.
class
).
run
(
match
(
true
));
this
.
contextRunner
.
withUserConfiguration
(
Java8Required
.
class
)
.
run
((
context
)
->
assertThat
(
context
).
hasSingleBean
(
String
.
class
));
}
}
@Test
@Test
...
@@ -105,10 +106,8 @@ public class ConditionalOnJavaTests {
...
@@ -105,10 +106,8 @@ public class ConditionalOnJavaTests {
private
String
getJavaVersion
(
Class
<?>...
hiddenClasses
)
throws
Exception
{
private
String
getJavaVersion
(
Class
<?>...
hiddenClasses
)
throws
Exception
{
URL
[]
urls
=
((
URLClassLoader
)
getClass
().
getClassLoader
()).
getURLs
();
URL
[]
urls
=
((
URLClassLoader
)
getClass
().
getClassLoader
()).
getURLs
();
URLClassLoader
classLoader
=
new
ClassHidingClassLoader
(
urls
,
hiddenClasses
);
URLClassLoader
classLoader
=
new
ClassHidingClassLoader
(
urls
,
hiddenClasses
);
Class
<?>
javaVersionClass
=
classLoader
Class
<?>
javaVersionClass
=
classLoader
.
loadClass
(
ConditionalOnJava
.
JavaVersion
.
class
.
getName
());
.
loadClass
(
ConditionalOnJava
.
JavaVersion
.
class
.
getName
());
Method
getJavaVersionMethod
=
ReflectionUtils
.
findMethod
(
javaVersionClass
,
Method
getJavaVersionMethod
=
ReflectionUtils
.
findMethod
(
javaVersionClass
,
"getJavaVersion"
);
"getJavaVersion"
);
Object
javaVersion
=
ReflectionUtils
.
invokeMethod
(
getJavaVersionMethod
,
null
);
Object
javaVersion
=
ReflectionUtils
.
invokeMethod
(
getJavaVersionMethod
,
null
);
...
@@ -123,17 +122,6 @@ public class ConditionalOnJavaTests {
...
@@ -123,17 +122,6 @@ public class ConditionalOnJavaTests {
assertThat
(
outcome
.
isMatch
()).
as
(
outcome
.
getMessage
()).
isEqualTo
(
expected
);
assertThat
(
outcome
.
isMatch
()).
as
(
outcome
.
getMessage
()).
isEqualTo
(
expected
);
}
}
private
ContextConsumer
<
AssertableApplicationContext
>
match
(
boolean
expected
)
{
return
(
context
)
->
{
if
(
expected
)
{
assertThat
(
context
).
hasSingleBean
(
String
.
class
);
}
else
{
assertThat
(
context
).
doesNotHaveBean
(
String
.
class
);
}
};
}
private
final
class
ClassHidingClassLoader
extends
URLClassLoader
{
private
final
class
ClassHidingClassLoader
extends
URLClassLoader
{
private
final
List
<
Class
<?>>
hiddenClasses
;
private
final
List
<
Class
<?>>
hiddenClasses
;
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnJndiTests.java
View file @
a869d25d
...
@@ -27,9 +27,7 @@ import org.junit.Test;
...
@@ -27,9 +27,7 @@ import org.junit.Test;
import
org.springframework.boot.autoconfigure.jndi.JndiPropertiesHidingClassLoader
;
import
org.springframework.boot.autoconfigure.jndi.JndiPropertiesHidingClassLoader
;
import
org.springframework.boot.autoconfigure.jndi.TestableInitialContextFactory
;
import
org.springframework.boot.autoconfigure.jndi.TestableInitialContextFactory
;
import
org.springframework.boot.test.context.assertj.AssertableApplicationContext
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ContextConsumer
;
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.core.type.AnnotatedTypeMetadata
;
import
org.springframework.core.type.AnnotatedTypeMetadata
;
...
@@ -77,22 +75,26 @@ public class ConditionalOnJndiTests {
...
@@ -77,22 +75,26 @@ public class ConditionalOnJndiTests {
@Test
@Test
public
void
jndiNotAvailable
()
{
public
void
jndiNotAvailable
()
{
this
.
contextRunner
.
withUserConfiguration
(
JndiAvailableConfiguration
.
class
,
this
.
contextRunner
JndiConditionConfiguration
.
class
).
run
(
match
(
false
));
.
withUserConfiguration
(
JndiAvailableConfiguration
.
class
,
JndiConditionConfiguration
.
class
)
.
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
String
.
class
));
}
}
@Test
@Test
public
void
jndiAvailable
()
{
public
void
jndiAvailable
()
{
setupJndi
();
setupJndi
();
this
.
contextRunner
.
withUserConfiguration
(
JndiAvailableConfiguration
.
class
,
this
.
contextRunner
JndiConditionConfiguration
.
class
).
run
(
match
(
true
));
.
withUserConfiguration
(
JndiAvailableConfiguration
.
class
,
JndiConditionConfiguration
.
class
)
.
run
((
context
)
->
assertThat
(
context
).
hasSingleBean
(
String
.
class
));
}
}
@Test
@Test
public
void
jndiLocationNotBound
()
{
public
void
jndiLocationNotBound
()
{
setupJndi
();
setupJndi
();
this
.
contextRunner
.
withUserConfiguration
(
JndiConditionConfiguration
.
class
)
this
.
contextRunner
.
withUserConfiguration
(
JndiConditionConfiguration
.
class
)
.
run
(
match
(
false
));
.
run
(
(
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
String
.
class
));
}
}
@Test
@Test
...
@@ -100,7 +102,7 @@ public class ConditionalOnJndiTests {
...
@@ -100,7 +102,7 @@ public class ConditionalOnJndiTests {
setupJndi
();
setupJndi
();
TestableInitialContextFactory
.
bind
(
"java:/FooManager"
,
new
Object
());
TestableInitialContextFactory
.
bind
(
"java:/FooManager"
,
new
Object
());
this
.
contextRunner
.
withUserConfiguration
(
JndiConditionConfiguration
.
class
)
this
.
contextRunner
.
withUserConfiguration
(
JndiConditionConfiguration
.
class
)
.
run
(
match
(
true
));
.
run
(
(
context
)
->
assertThat
(
context
).
hasSingleBean
(
String
.
class
));
}
}
@Test
@Test
...
@@ -124,17 +126,6 @@ public class ConditionalOnJndiTests {
...
@@ -124,17 +126,6 @@ public class ConditionalOnJndiTests {
TestableInitialContextFactory
.
class
.
getName
());
TestableInitialContextFactory
.
class
.
getName
());
}
}
private
ContextConsumer
<
AssertableApplicationContext
>
match
(
boolean
expected
)
{
return
(
context
)
->
{
if
(
expected
)
{
assertThat
(
context
).
hasSingleBean
(
String
.
class
);
}
else
{
assertThat
(
context
).
doesNotHaveBean
(
String
.
class
);
}
};
}
private
AnnotatedTypeMetadata
mockMetaData
(
String
...
value
)
{
private
AnnotatedTypeMetadata
mockMetaData
(
String
...
value
)
{
AnnotatedTypeMetadata
metadata
=
mock
(
AnnotatedTypeMetadata
.
class
);
AnnotatedTypeMetadata
metadata
=
mock
(
AnnotatedTypeMetadata
.
class
);
Map
<
String
,
Object
>
attributes
=
new
HashMap
<>();
Map
<
String
,
Object
>
attributes
=
new
HashMap
<>();
...
...
spring-boot-test/src/main/java/org/springframework/boot/test/context/runner/AbstractApplicationContextRunner.java
View file @
a869d25d
...
@@ -292,20 +292,13 @@ abstract class AbstractApplicationContextRunner<SELF extends AbstractApplication
...
@@ -292,20 +292,13 @@ abstract class AbstractApplicationContextRunner<SELF extends AbstractApplication
consumer
.
accept
(
context
);
consumer
.
accept
(
context
);
}
}
catch
(
Throwable
ex
)
{
catch
(
Throwable
ex
)
{
AnyThrow
.
throwUnchecked
(
ex
);
rethrow
(
ex
);
}
}
}
}
private
static
class
AnyThrow
{
static
void
throwUnchecked
(
Throwable
e
)
{
AnyThrow
.
throwAny
(
e
);
}
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
private
static
<
E
extends
Throwable
>
void
throwAny
(
Throwable
e
)
throws
E
{
private
<
E
extends
Throwable
>
void
rethrow
(
Throwable
e
)
throws
E
{
throw
(
E
)
e
;
throw
(
E
)
e
;
}
}
}
}
}
spring-boot-test/src/main/java/org/springframework/boot/test/json/JsonContent.java
View file @
a869d25d
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
...
spring-boot-test/src/main/java/org/springframework/boot/test/util/TestPropertyValues.java
View file @
a869d25d
...
@@ -130,11 +130,16 @@ public final class TestPropertyValues {
...
@@ -130,11 +130,16 @@ public final class TestPropertyValues {
return
call
.
call
();
return
call
.
call
();
}
}
catch
(
Exception
ex
)
{
catch
(
Exception
ex
)
{
AnyThrow
.
throwUnchecked
(
ex
);
rethrow
(
ex
);
return
null
;
// never reached
throw
new
IllegalStateException
(
"Original cause not rethrown"
,
ex
);
}
}
}
}
@SuppressWarnings
(
"unchecked"
)
private
<
E
extends
Throwable
>
void
rethrow
(
Throwable
e
)
throws
E
{
throw
(
E
)
e
;
}
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
private
void
addToSources
(
MutablePropertySources
sources
,
Type
type
,
String
name
)
{
private
void
addToSources
(
MutablePropertySources
sources
,
Type
type
,
String
name
)
{
if
(
sources
.
contains
(
name
))
{
if
(
sources
.
contains
(
name
))
{
...
@@ -310,16 +315,4 @@ public final class TestPropertyValues {
...
@@ -310,16 +315,4 @@ public final class TestPropertyValues {
}
}
private
static
class
AnyThrow
{
static
void
throwUnchecked
(
Throwable
e
)
{
AnyThrow
.
throwAny
(
e
);
}
@SuppressWarnings
(
"unchecked"
)
private
static
<
E
extends
Throwable
>
void
throwAny
(
Throwable
e
)
throws
E
{
throw
(
E
)
e
;
}
}
}
}
spring-boot-test/src/test/java/org/springframework/boot/test/context/runner/AbstractApplicationContextRunnerTests.java
View file @
a869d25d
...
@@ -153,7 +153,8 @@ public abstract class AbstractApplicationContextRunnerTests<T extends AbstractAp
...
@@ -153,7 +153,8 @@ public abstract class AbstractApplicationContextRunnerTests<T extends AbstractAp
new
HidePackagesClassLoader
(
Gson
.
class
.
getPackage
().
getName
()))
new
HidePackagesClassLoader
(
Gson
.
class
.
getPackage
().
getName
()))
.
run
((
context
)
->
{
.
run
((
context
)
->
{
try
{
try
{
ClassUtils
.
forName
(
Gson
.
class
.
getName
(),
context
.
getClassLoader
());
ClassUtils
.
forName
(
Gson
.
class
.
getName
(),
context
.
getClassLoader
());
fail
(
"Should have thrown a ClassNotFoundException"
);
fail
(
"Should have thrown a ClassNotFoundException"
);
}
}
catch
(
ClassNotFoundException
e
)
{
catch
(
ClassNotFoundException
e
)
{
...
...
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