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
601b5e4d
Commit
601b5e4d
authored
Dec 28, 2017
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace SystemProperties by TestPropertyValues
Closes gh-9852
parent
f0d94a46
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
98 deletions
+45
-98
RepositoryConfigurationFactoryTests.java
...oot/cli/compiler/RepositoryConfigurationFactoryTests.java
+31
-22
SettingsXmlRepositorySystemSessionAutoConfigurationTests.java
...ingsXmlRepositorySystemSessionAutoConfigurationTests.java
+14
-12
SystemProperties.java
...g/springframework/boot/cli/testutil/SystemProperties.java
+0
-64
No files found.
spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/RepositoryConfigurationFactoryTests.java
View file @
601b5e4d
...
...
@@ -23,7 +23,7 @@ import java.util.Set;
import
org.junit.Test
;
import
org.springframework.boot.cli.compiler.grape.RepositoryConfiguration
;
import
org.springframework.boot.
cli.testutil.SystemProperti
es
;
import
org.springframework.boot.
test.util.TestPropertyValu
es
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
...
@@ -36,55 +36,64 @@ public class RepositoryConfigurationFactoryTests {
@Test
public
void
defaultRepositories
()
{
SystemProperties
.
doWithSystemProperties
(()
->
{
List
<
RepositoryConfiguration
>
repositoryConfiguration
=
RepositoryConfigurationFactory
.
createDefaultRepositoryConfiguration
();
assertRepositoryConfiguration
(
repositoryConfiguration
,
"central"
,
"local"
,
"spring-snapshot"
,
"spring-milestone"
);
},
"user.home:src/test/resources/maven-settings/basic"
);
TestPropertyValues
.
of
(
"user.home:src/test/resources/maven-settings/basic"
)
.
applyToSystemProperties
(()
->
{
List
<
RepositoryConfiguration
>
repositoryConfiguration
=
RepositoryConfigurationFactory
.
createDefaultRepositoryConfiguration
();
assertRepositoryConfiguration
(
repositoryConfiguration
,
"central"
,
"local"
,
"spring-snapshot"
,
"spring-milestone"
);
return
null
;
});
}
@Test
public
void
snapshotRepositoriesDisabled
()
{
SystemProperties
.
doWithSystemProperties
(()
->
{
TestPropertyValues
.
of
(
"user.home:src/test/resources/maven-settings/basic"
,
"disableSpringSnapshotRepos:true"
).
applyToSystemProperties
(()
->
{
List
<
RepositoryConfiguration
>
repositoryConfiguration
=
RepositoryConfigurationFactory
.
createDefaultRepositoryConfiguration
();
assertRepositoryConfiguration
(
repositoryConfiguration
,
"central"
,
"local"
);
},
"user.home:src/test/resources/maven-settings/basic"
,
"disableSpringSnapshotRepos:true"
);
return
null
;
}
);
}
@Test
public
void
activeByDefaultProfileRepositories
()
{
SystemProperties
.
doWithSystemProperties
(()
->
{
List
<
RepositoryConfiguration
>
repositoryConfiguration
=
RepositoryConfigurationFactory
.
createDefaultRepositoryConfiguration
();
assertRepositoryConfiguration
(
repositoryConfiguration
,
"central"
,
"local"
,
"spring-snapshot"
,
"spring-milestone"
,
"active-by-default"
);
},
"user.home:src/test/resources/maven-settings/active-profile-repositories"
);
TestPropertyValues
.
of
(
"user.home:src/test/resources/maven-settings/active-profile-repositories"
)
.
applyToSystemProperties
(()
->
{
List
<
RepositoryConfiguration
>
repositoryConfiguration
=
RepositoryConfigurationFactory
.
createDefaultRepositoryConfiguration
();
assertRepositoryConfiguration
(
repositoryConfiguration
,
"central"
,
"local"
,
"spring-snapshot"
,
"spring-milestone"
,
"active-by-default"
);
return
null
;
});
}
@Test
public
void
activeByPropertyProfileRepositories
()
{
SystemProperties
.
doWithSystemProperties
(()
->
{
TestPropertyValues
.
of
(
"user.home:src/test/resources/maven-settings/active-profile-repositories"
,
"foo:bar"
).
applyToSystemProperties
(()
->
{
List
<
RepositoryConfiguration
>
repositoryConfiguration
=
RepositoryConfigurationFactory
.
createDefaultRepositoryConfiguration
();
assertRepositoryConfiguration
(
repositoryConfiguration
,
"central"
,
"local"
,
"spring-snapshot"
,
"spring-milestone"
,
"active-by-property"
);
},
"user.home:src/test/resources/maven-settings/active-profile-repositories"
,
"foo:bar"
);
return
null
;
}
);
}
@Test
public
void
interpolationProfileRepositories
()
{
SystemProperties
.
doWithSystemProperties
(()
->
{
TestPropertyValues
.
of
(
"user.home:src/test/resources/maven-settings/active-profile-repositories"
,
"interpolate:true"
).
applyToSystemProperties
(()
->
{
List
<
RepositoryConfiguration
>
repositoryConfiguration
=
RepositoryConfigurationFactory
.
createDefaultRepositoryConfiguration
();
assertRepositoryConfiguration
(
repositoryConfiguration
,
"central"
,
"local"
,
"spring-snapshot"
,
"spring-milestone"
,
"interpolate-releases"
,
"interpolate-snapshots"
);
},
"user.home:src/test/resources/maven-settings/active-profile-repositories"
,
"interpolate:true"
);
return
null
;
}
);
}
private
void
assertRepositoryConfiguration
(
...
...
spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/SettingsXmlRepositorySystemSessionAutoConfigurationTests.java
View file @
601b5e4d
...
...
@@ -32,7 +32,7 @@ import org.junit.Test;
import
org.mockito.Mock
;
import
org.mockito.MockitoAnnotations
;
import
org.springframework.boot.
cli.testutil.SystemProperti
es
;
import
org.springframework.boot.
test.util.TestPropertyValu
es
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
...
...
@@ -74,12 +74,13 @@ public class SettingsXmlRepositorySystemSessionAutoConfigurationTests {
return
new
SimpleLocalRepositoryManagerFactory
().
newInstance
(
session
,
localRepository
);
});
SystemProperties
.
doWithSystemProperties
(
()
->
new
SettingsXmlRepositorySystemSessionAutoConfiguration
().
apply
(
session
,
SettingsXmlRepositorySystemSessionAutoConfigurationTests
.
this
.
repositorySystem
),
"user.home:src/test/resources/maven-settings/property-interpolation"
,
"foo:bar"
);
TestPropertyValues
.
of
(
"user.home:src/test/resources/maven-settings/property-interpolation"
,
"foo:bar"
).
applyToSystemProperties
(()
->
{
new
SettingsXmlRepositorySystemSessionAutoConfiguration
().
apply
(
session
,
SettingsXmlRepositorySystemSessionAutoConfigurationTests
.
this
.
repositorySystem
);
return
null
;
});
assertThat
(
session
.
getLocalRepository
().
getBasedir
().
getAbsolutePath
())
.
endsWith
(
File
.
separatorChar
+
"bar"
+
File
.
separatorChar
+
"repository"
);
}
...
...
@@ -87,11 +88,12 @@ public class SettingsXmlRepositorySystemSessionAutoConfigurationTests {
private
void
assertSessionCustomization
(
String
userHome
)
{
final
DefaultRepositorySystemSession
session
=
MavenRepositorySystemUtils
.
newSession
();
SystemProperties
.
doWithSystemProperties
(
()
->
new
SettingsXmlRepositorySystemSessionAutoConfiguration
().
apply
(
session
,
SettingsXmlRepositorySystemSessionAutoConfigurationTests
.
this
.
repositorySystem
),
"user.home:"
+
userHome
);
TestPropertyValues
.
of
(
"user.home:"
+
userHome
).
applyToSystemProperties
(()
->
{
new
SettingsXmlRepositorySystemSessionAutoConfiguration
().
apply
(
session
,
SettingsXmlRepositorySystemSessionAutoConfigurationTests
.
this
.
repositorySystem
);
return
null
;
});
RemoteRepository
repository
=
new
RemoteRepository
.
Builder
(
"my-server"
,
"default"
,
"http://maven.example.com"
).
build
();
assertMirrorSelectorConfiguration
(
session
,
repository
);
...
...
spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/testutil/SystemProperties.java
deleted
100644 → 0
View file @
f0d94a46
/*
* Copyright 2012-2017 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
cli
.
testutil
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map.Entry
;
/**
* Utilities for working with System properties in unit tests
*
* @author Andy Wilkinson
*/
public
final
class
SystemProperties
{
private
SystemProperties
()
{
}
/**
* Performs the given {@code action} with the given system properties set. System
* properties are restored to their previous values once the action has run.
* @param action The action to perform
* @param systemPropertyPairs The system properties, each in the form
* {@code key:value}
*/
public
static
void
doWithSystemProperties
(
Runnable
action
,
String
...
systemPropertyPairs
)
{
Map
<
String
,
String
>
originalValues
=
new
HashMap
<>();
for
(
String
pair
:
systemPropertyPairs
)
{
String
[]
components
=
pair
.
split
(
":"
);
String
key
=
components
[
0
];
String
value
=
components
[
1
];
originalValues
.
put
(
key
,
System
.
setProperty
(
key
,
value
));
}
try
{
action
.
run
();
}
finally
{
for
(
Entry
<
String
,
String
>
entry
:
originalValues
.
entrySet
())
{
if
(
entry
.
getValue
()
==
null
)
{
System
.
clearProperty
(
entry
.
getKey
());
}
else
{
System
.
setProperty
(
entry
.
getKey
(),
entry
.
getValue
());
}
}
}
}
}
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