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
00cfe1d0
Commit
00cfe1d0
authored
Feb 06, 2016
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use AssertJ in spring-boot-tools
See gh-5083
parent
7f9358f4
Changes
36
Show whitespace changes
Inline
Side-by-side
Showing
36 changed files
with
1325 additions
and
985 deletions
+1325
-985
AbstractConfigurationMetadataTests.java
...igurationmetadata/AbstractConfigurationMetadataTests.java
+12
-13
ConfigurationMetadataRepositoryJsonBuilderTests.java
...data/ConfigurationMetadataRepositoryJsonBuilderTests.java
+23
-26
DescriptionExtractorTests.java
...boot/configurationmetadata/DescriptionExtractorTests.java
+7
-7
JsonReaderTests.java
...framework/boot/configurationmetadata/JsonReaderTests.java
+51
-52
ConfigurationMetadataAnnotationProcessorTests.java
...cessor/ConfigurationMetadataAnnotationProcessorTests.java
+216
-214
Metadata.java
...springframework/boot/configurationprocessor/Metadata.java
+401
-0
TestConfigurationMetadataAnnotationProcessor.java
...ocessor/TestConfigurationMetadataAnnotationProcessor.java
+2
-0
AbstractFieldValuesProcessorTests.java
...cessor/fieldvalues/AbstractFieldValuesProcessorTests.java
+32
-41
ConfigurationMetadataTests.java
...urationprocessor/metadata/ConfigurationMetadataTests.java
+11
-11
JsonMarshallerTests.java
.../configurationprocessor/metadata/JsonMarshallerTests.java
+18
-21
DefaultLaunchScriptTests.java
...framework/boot/loader/tools/DefaultLaunchScriptTests.java
+11
-13
FileUtilsTests.java
...org/springframework/boot/loader/tools/FileUtilsTests.java
+11
-14
JvmUtilsTests.java
.../org/springframework/boot/loader/tools/JvmUtilsTests.java
+3
-5
LayoutsTests.java
...a/org/springframework/boot/loader/tools/LayoutsTests.java
+35
-36
MainClassFinderTests.java
...ringframework/boot/loader/tools/MainClassFinderTests.java
+10
-11
RepackagerTests.java
...rg/springframework/boot/loader/tools/RepackagerTests.java
+61
-65
ExecutableArchiveLauncherTests.java
...framework/boot/loader/ExecutableArchiveLauncherTests.java
+3
-4
InputArgumentsJavaAgentDetectorTests.java
...ork/boot/loader/InputArgumentsJavaAgentDetectorTests.java
+13
-12
LaunchedURLClassLoaderTests.java
...ingframework/boot/loader/LaunchedURLClassLoaderTests.java
+11
-14
PropertiesLauncherTests.java
.../springframework/boot/loader/PropertiesLauncherTests.java
+29
-34
WarLauncherTests.java
...ava/org/springframework/boot/loader/WarLauncherTests.java
+8
-19
ExplodedArchiveTests.java
...ngframework/boot/loader/archive/ExplodedArchiveTests.java
+23
-23
JarFileArchiveTests.java
...ingframework/boot/loader/archive/JarFileArchiveTests.java
+12
-16
ByteArrayRandomAccessDataTests.java
...work/boot/loader/data/ByteArrayRandomAccessDataTests.java
+11
-10
RandomAccessDataFileTests.java
...framework/boot/loader/data/RandomAccessDataFileTests.java
+34
-40
AsciiBytesTests.java
.../org/springframework/boot/loader/jar/AsciiBytesTests.java
+37
-39
CentralDirectoryParserTests.java
...ramework/boot/loader/jar/CentralDirectoryParserTests.java
+17
-14
JarFileTests.java
...ava/org/springframework/boot/loader/jar/JarFileTests.java
+107
-116
SystemPropertyUtilsTests.java
...gframework/boot/loader/util/SystemPropertyUtilsTests.java
+10
-6
ArtifactsLibrariesTests.java
...g/springframework/boot/maven/ArtifactsLibrariesTests.java
+7
-8
DependencyFilterMojoTests.java
...springframework/boot/maven/DependencyFilterMojoTests.java
+5
-6
ExcludeFilterTests.java
...va/org/springframework/boot/maven/ExcludeFilterTests.java
+14
-15
IncludeFilterTests.java
...va/org/springframework/boot/maven/IncludeFilterTests.java
+11
-12
PropertiesMergingResourceTransformerTests.java
...boot/maven/PropertiesMergingResourceTransformerTests.java
+6
-9
RunArgumentsTests.java
...ava/org/springframework/boot/maven/RunArgumentsTests.java
+17
-18
Verify.java
.../src/test/java/org/springframework/boot/maven/Verify.java
+46
-41
No files found.
spring-boot-tools/spring-boot-configuration-metadata/src/test/java/org/springframework/boot/configurationmetadata/AbstractConfigurationMetadataTests.java
View file @
00cfe1d0
...
...
@@ -25,8 +25,7 @@ import org.junit.rules.ExpectedException;
import
org.springframework.core.io.ClassPathResource
;
import
org.springframework.core.io.Resource
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Base for configuration meta-data tests.
...
...
@@ -40,25 +39,25 @@ public abstract class AbstractConfigurationMetadataTests {
protected
void
assertSource
(
ConfigurationMetadataSource
actual
,
String
groupId
,
String
type
,
String
sourceType
)
{
assert
NotNull
(
actual
);
assert
Equals
(
groupId
,
actual
.
getGroupId
()
);
assert
Equals
(
type
,
actual
.
getType
()
);
assert
Equals
(
sourceType
,
actual
.
getSourceType
()
);
assert
That
(
actual
).
isNotNull
(
);
assert
That
(
actual
.
getGroupId
()).
isEqualTo
(
groupId
);
assert
That
(
actual
.
getType
()).
isEqualTo
(
type
);
assert
That
(
actual
.
getSourceType
()).
isEqualTo
(
sourceType
);
}
protected
void
assertProperty
(
ConfigurationMetadataProperty
actual
,
String
id
,
String
name
,
Class
<?>
type
,
Object
defaultValue
)
{
assert
NotNull
(
actual
);
assert
Equals
(
id
,
actual
.
getId
()
);
assert
Equals
(
name
,
actual
.
getName
()
);
assert
That
(
actual
).
isNotNull
(
);
assert
That
(
actual
.
getId
()).
isEqualTo
(
id
);
assert
That
(
actual
.
getName
()).
isEqualTo
(
name
);
String
typeName
=
type
!=
null
?
type
.
getName
()
:
null
;
assert
Equals
(
typeName
,
actual
.
getType
()
);
assert
Equals
(
defaultValue
,
actual
.
getDefaultValue
()
);
assert
That
(
actual
.
getType
()).
isEqualTo
(
typeName
);
assert
That
(
actual
.
getDefaultValue
()).
isEqualTo
(
defaultValue
);
}
protected
void
assertItem
(
ConfigurationMetadataItem
actual
,
String
sourceType
)
{
assert
NotNull
(
actual
);
assert
Equals
(
sourceType
,
actual
.
getSourceType
()
);
assert
That
(
actual
).
isNotNull
(
);
assert
That
(
actual
.
getSourceType
()).
isEqualTo
(
sourceType
);
}
protected
InputStream
getInputStreamFor
(
String
name
)
throws
IOException
{
...
...
spring-boot-tools/spring-boot-configuration-metadata/src/test/java/org/springframework/boot/configurationmetadata/ConfigurationMetadataRepositoryJsonBuilderTests.java
View file @
00cfe1d0
...
...
@@ -22,9 +22,7 @@ import java.util.Map;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link ConfigurationMetadataRepository}.
...
...
@@ -47,10 +45,10 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests
ConfigurationMetadataRepository
repo
=
ConfigurationMetadataRepositoryJsonBuilder
.
create
(
foo
).
build
();
validateFoo
(
repo
);
assert
Equals
(
1
,
repo
.
getAllGroups
().
size
()
);
assert
That
(
repo
.
getAllGroups
()).
hasSize
(
1
);
contains
(
repo
.
getAllProperties
(),
"spring.foo.name"
,
"spring.foo.description"
,
"spring.foo.counter"
);
assert
Equals
(
3
,
repo
.
getAllProperties
().
size
()
);
assert
That
(
repo
.
getAllProperties
()).
hasSize
(
3
);
}
finally
{
foo
.
close
();
...
...
@@ -66,11 +64,11 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests
.
create
(
foo
,
bar
).
build
();
validateFoo
(
repo
);
validateBar
(
repo
);
assert
Equals
(
2
,
repo
.
getAllGroups
().
size
()
);
assert
That
(
repo
.
getAllGroups
()).
hasSize
(
2
);
contains
(
repo
.
getAllProperties
(),
"spring.foo.name"
,
"spring.foo.description"
,
"spring.foo.counter"
,
"spring.bar.name"
,
"spring.bar.description"
,
"spring.bar.counter"
);
assert
Equals
(
6
,
repo
.
getAllProperties
().
size
()
);
assert
That
(
repo
.
getAllProperties
()).
hasSize
(
6
);
}
finally
{
foo
.
close
();
...
...
@@ -86,11 +84,11 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests
ConfigurationMetadataRepository
repo
=
ConfigurationMetadataRepositoryJsonBuilder
.
create
(
foo
,
root
).
build
();
validateFoo
(
repo
);
assert
Equals
(
2
,
repo
.
getAllGroups
().
size
()
);
assert
That
(
repo
.
getAllGroups
()).
hasSize
(
2
);
contains
(
repo
.
getAllProperties
(),
"spring.foo.name"
,
"spring.foo.description"
,
"spring.foo.counter"
,
"spring.root.name"
,
"spring.root2.name"
);
assert
Equals
(
5
,
repo
.
getAllProperties
().
size
()
);
assert
That
(
repo
.
getAllProperties
()).
hasSize
(
5
);
}
finally
{
foo
.
close
();
...
...
@@ -105,17 +103,17 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests
try
{
ConfigurationMetadataRepository
repo
=
ConfigurationMetadataRepositoryJsonBuilder
.
create
(
foo
,
foo2
).
build
();
assert
Equals
(
1
,
repo
.
getAllGroups
().
size
()
);
assert
That
(
repo
.
getAllGroups
()).
hasSize
(
1
);
ConfigurationMetadataGroup
group
=
repo
.
getAllGroups
().
get
(
"spring.foo"
);
contains
(
group
.
getSources
(),
"org.acme.Foo"
,
"org.acme.Foo2"
,
"org.springframework.boot.FooProperties"
);
assert
Equals
(
3
,
group
.
getSources
().
size
()
);
assert
That
(
group
.
getSources
()).
hasSize
(
3
);
contains
(
group
.
getProperties
(),
"spring.foo.name"
,
"spring.foo.description"
,
"spring.foo.counter"
,
"spring.foo.enabled"
,
"spring.foo.type"
);
assert
Equals
(
5
,
group
.
getProperties
().
size
()
);
assert
That
(
group
.
getProperties
()).
hasSize
(
5
);
contains
(
repo
.
getAllProperties
(),
"spring.foo.name"
,
"spring.foo.description"
,
"spring.foo.counter"
,
"spring.foo.enabled"
,
"spring.foo.type"
);
assert
Equals
(
5
,
repo
.
getAllProperties
().
size
()
);
assert
That
(
repo
.
getAllProperties
()).
hasSize
(
5
);
}
finally
{
foo
.
close
();
...
...
@@ -138,11 +136,11 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests
validateFoo
(
secondRepo
);
validateBar
(
secondRepo
);
// first repo not impacted by second build
assert
NotEquals
(
firstRepo
,
second
Repo
);
assert
Equals
(
1
,
firstRepo
.
getAllGroups
().
size
()
);
assert
Equals
(
3
,
firstRepo
.
getAllProperties
().
size
()
);
assert
Equals
(
2
,
secondRepo
.
getAllGroups
().
size
()
);
assert
Equals
(
6
,
secondRepo
.
getAllProperties
().
size
()
);
assert
That
(
secondRepo
).
isNotEqualTo
(
first
Repo
);
assert
That
(
firstRepo
.
getAllGroups
()).
hasSize
(
1
);
assert
That
(
firstRepo
.
getAllProperties
()).
hasSize
(
3
);
assert
That
(
secondRepo
.
getAllGroups
()).
hasSize
(
2
);
assert
That
(
secondRepo
.
getAllProperties
()).
hasSize
(
6
);
}
finally
{
foo
.
close
();
...
...
@@ -156,11 +154,11 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests
"org.springframework.boot.FooProperties"
);
ConfigurationMetadataSource
source
=
group
.
getSources
().
get
(
"org.acme.Foo"
);
contains
(
source
.
getProperties
(),
"spring.foo.name"
,
"spring.foo.description"
);
assert
Equals
(
2
,
source
.
getProperties
().
size
()
);
assert
That
(
source
.
getProperties
()).
hasSize
(
2
);
ConfigurationMetadataSource
source2
=
group
.
getSources
()
.
get
(
"org.springframework.boot.FooProperties"
);
contains
(
source2
.
getProperties
(),
"spring.foo.name"
,
"spring.foo.counter"
);
assert
Equals
(
2
,
source2
.
getProperties
().
size
()
);
assert
That
(
source2
.
getProperties
()).
hasSize
(
2
);
validatePropertyHints
(
repo
.
getAllProperties
().
get
(
"spring.foo.name"
),
0
,
0
);
validatePropertyHints
(
repo
.
getAllProperties
().
get
(
"spring.foo.description"
),
0
,
0
);
...
...
@@ -173,11 +171,11 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests
"org.springframework.boot.BarProperties"
);
ConfigurationMetadataSource
source
=
group
.
getSources
().
get
(
"org.acme.Bar"
);
contains
(
source
.
getProperties
(),
"spring.bar.name"
,
"spring.bar.description"
);
assert
Equals
(
2
,
source
.
getProperties
().
size
()
);
assert
That
(
source
.
getProperties
()).
hasSize
(
2
);
ConfigurationMetadataSource
source2
=
group
.
getSources
()
.
get
(
"org.springframework.boot.BarProperties"
);
contains
(
source2
.
getProperties
(),
"spring.bar.name"
,
"spring.bar.counter"
);
assert
Equals
(
2
,
source2
.
getProperties
().
size
()
);
assert
That
(
source2
.
getProperties
()).
hasSize
(
2
);
validatePropertyHints
(
repo
.
getAllProperties
().
get
(
"spring.bar.name"
),
0
,
0
);
validatePropertyHints
(
repo
.
getAllProperties
().
get
(
"spring.bar.description"
),
2
,
2
);
...
...
@@ -186,14 +184,13 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests
private
void
validatePropertyHints
(
ConfigurationMetadataProperty
property
,
int
valueHints
,
int
valueProviders
)
{
assert
Equals
(
valueHints
,
property
.
getValueHints
().
size
()
);
assert
Equals
(
valueProviders
,
property
.
getValueHints
().
size
()
);
assert
That
(
property
.
getValueHints
().
size
()).
isEqualTo
(
valueHints
);
assert
That
(
property
.
getValueHints
().
size
()).
isEqualTo
(
valueProviders
);
}
private
void
contains
(
Map
<
String
,
?>
source
,
String
...
keys
)
{
for
(
String
key
:
keys
)
{
assertTrue
(
"Item '"
+
key
+
"' not found. Got "
+
source
.
keySet
(),
source
.
containsKey
(
key
));
assertThat
(
source
).
containsKey
(
key
);
}
}
...
...
spring-boot-tools/spring-boot-configuration-metadata/src/test/java/org/springframework/boot/configurationmetadata/DescriptionExtractorTests.java
View file @
00cfe1d0
...
...
@@ -18,7 +18,7 @@ package org.springframework.boot.configurationmetadata;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link DescriptionExtractor}.
...
...
@@ -35,39 +35,39 @@ public class DescriptionExtractorTests {
public
void
extractShortDescription
()
{
String
description
=
this
.
extractor
.
getShortDescription
(
"My short "
+
"description. More stuff."
);
assert
Equals
(
"My short description."
,
description
);
assert
That
(
description
).
isEqualTo
(
"My short description."
);
}
@Test
public
void
extractShortDescriptionNewLineBeforeDot
()
{
String
description
=
this
.
extractor
.
getShortDescription
(
"My short"
+
NEW_LINE
+
"description."
+
NEW_LINE
+
"More stuff."
);
assert
Equals
(
"My short description."
,
description
);
assert
That
(
description
).
isEqualTo
(
"My short description."
);
}
@Test
public
void
extractShortDescriptionNewLineBeforeDotWithSpaces
()
{
String
description
=
this
.
extractor
.
getShortDescription
(
"My short "
+
NEW_LINE
+
" description. "
+
NEW_LINE
+
"More stuff."
);
assert
Equals
(
"My short description."
,
description
);
assert
That
(
description
).
isEqualTo
(
"My short description."
);
}
@Test
public
void
extractShortDescriptionNoDot
()
{
String
description
=
this
.
extractor
.
getShortDescription
(
"My short description"
);
assert
Equals
(
"My short description"
,
description
);
assert
That
(
description
).
isEqualTo
(
"My short description"
);
}
@Test
public
void
extractShortDescriptionNoDotMultipleLines
()
{
String
description
=
this
.
extractor
.
getShortDescription
(
"My short description "
+
NEW_LINE
+
" More stuff"
);
assert
Equals
(
"My short description"
,
description
);
assert
That
(
description
).
isEqualTo
(
"My short description"
);
}
@Test
public
void
extractShortDescriptionNull
()
{
assert
Equals
(
null
,
this
.
extractor
.
getShortDescription
(
null
)
);
assert
That
(
this
.
extractor
.
getShortDescription
(
null
)).
isEqualTo
(
null
);
}
}
spring-boot-tools/spring-boot-configuration-metadata/src/test/java/org/springframework/boot/configurationmetadata/JsonReaderTests.java
View file @
00cfe1d0
...
...
@@ -23,10 +23,7 @@ import java.util.List;
import
org.json.JSONException
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link JsonReader}
...
...
@@ -42,8 +39,8 @@ public class JsonReaderTests extends AbstractConfigurationMetadataTests {
@Test
public
void
emptyMetadata
()
throws
IOException
{
RawConfigurationMetadata
rawMetadata
=
readFor
(
"empty"
);
assert
Equals
(
0
,
rawMetadata
.
getSources
().
size
()
);
assert
Equals
(
0
,
rawMetadata
.
getItems
().
size
()
);
assert
That
(
rawMetadata
.
getSources
()).
isEmpty
(
);
assert
That
(
rawMetadata
.
getItems
()).
isEmpty
(
);
}
@Test
...
...
@@ -56,17 +53,17 @@ public class JsonReaderTests extends AbstractConfigurationMetadataTests {
public
void
simpleMetadata
()
throws
IOException
{
RawConfigurationMetadata
rawMetadata
=
readFor
(
"foo"
);
List
<
ConfigurationMetadataSource
>
sources
=
rawMetadata
.
getSources
();
assert
Equals
(
2
,
sources
.
size
()
);
assert
That
(
sources
).
hasSize
(
2
);
List
<
ConfigurationMetadataItem
>
items
=
rawMetadata
.
getItems
();
assert
Equals
(
4
,
items
.
size
()
);
assert
That
(
items
).
hasSize
(
4
);
List
<
ConfigurationMetadataHint
>
hints
=
rawMetadata
.
getHints
();
assert
Equals
(
1
,
hints
.
size
()
);
assert
That
(
hints
).
hasSize
(
1
);
ConfigurationMetadataSource
source
=
sources
.
get
(
0
);
assertSource
(
source
,
"spring.foo"
,
"org.acme.Foo"
,
"org.acme.config.FooApp"
);
assert
Equals
(
"foo()"
,
source
.
getSourceMethod
()
);
assert
Equals
(
"This is Foo."
,
source
.
getDescription
()
);
assert
Equals
(
"This is Foo."
,
source
.
getShortDescription
()
);
assert
That
(
source
.
getSourceMethod
()).
isEqualTo
(
"foo()"
);
assert
That
(
source
.
getDescription
()).
isEqualTo
(
"This is Foo."
);
assert
That
(
source
.
getShortDescription
()).
isEqualTo
(
"This is Foo."
);
ConfigurationMetadataItem
item
=
items
.
get
(
0
);
assertProperty
(
item
,
"spring.foo.name"
,
"name"
,
String
.
class
,
null
);
...
...
@@ -74,61 +71,62 @@ public class JsonReaderTests extends AbstractConfigurationMetadataTests {
ConfigurationMetadataItem
item2
=
items
.
get
(
1
);
assertProperty
(
item2
,
"spring.foo.description"
,
"description"
,
String
.
class
,
"FooBar"
);
assert
Equals
(
"Foo description."
,
item2
.
getDescription
()
);
assert
Equals
(
"Foo description."
,
item2
.
getShortDescription
()
);
assert
Null
(
item2
.
getSourceMethod
()
);
assert
That
(
item2
.
getDescription
()).
isEqualTo
(
"Foo description."
);
assert
That
(
item2
.
getShortDescription
()).
isEqualTo
(
"Foo description."
);
assert
That
(
item2
.
getSourceMethod
()).
isNull
(
);
assertItem
(
item2
,
"org.acme.Foo"
);
ConfigurationMetadataHint
hint
=
hints
.
get
(
0
);
assert
Equals
(
"spring.foo.counter"
,
hint
.
getId
()
);
assert
Equals
(
1
,
hint
.
getValueHints
().
size
()
);
assert
That
(
hint
.
getId
()).
isEqualTo
(
"spring.foo.counter"
);
assert
That
(
hint
.
getValueHints
()).
hasSize
(
1
);
ValueHint
valueHint
=
hint
.
getValueHints
().
get
(
0
);
assert
Equals
(
42
,
valueHint
.
getValue
()
);
assert
Equals
(
"Because that's the answer to any question, choose it. \nReally."
,
valueHint
.
getDescription
()
);
assert
Equals
(
"Because that's the answer to any question, choose it."
,
valueHint
.
getShortDescription
()
);
assert
Equals
(
1
,
hint
.
getValueProviders
().
size
()
);
assert
That
(
valueHint
.
getValue
()).
isEqualTo
(
42
);
assert
That
(
valueHint
.
getDescription
()).
isEqualTo
(
"Because that's the answer to any question, choose it. \nReally."
);
assert
That
(
valueHint
.
getShortDescription
())
.
isEqualTo
(
"Because that's the answer to any question, choose it."
);
assert
That
(
hint
.
getValueProviders
()).
hasSize
(
1
);
ValueProvider
valueProvider
=
hint
.
getValueProviders
().
get
(
0
);
assert
Equals
(
"handle-as"
,
valueProvider
.
getName
()
);
assert
Equals
(
1
,
valueProvider
.
getParameters
().
size
()
);
assert
Equals
(
Integer
.
class
.
getName
(),
valueProvider
.
getParameters
().
get
(
"target"
));
assert
That
(
valueProvider
.
getName
()).
isEqualTo
(
"handle-as"
);
assert
That
(
valueProvider
.
getParameters
()).
hasSize
(
1
);
assert
That
(
valueProvider
.
getParameters
().
get
(
"target"
))
.
isEqualTo
(
Integer
.
class
.
getName
(
));
}
@Test
public
void
metadataHints
()
throws
IOException
{
RawConfigurationMetadata
rawMetadata
=
readFor
(
"bar"
);
List
<
ConfigurationMetadataHint
>
hints
=
rawMetadata
.
getHints
();
assert
Equals
(
1
,
hints
.
size
()
);
assert
That
(
hints
).
hasSize
(
1
);
ConfigurationMetadataHint
hint
=
hints
.
get
(
0
);
assert
Equals
(
"spring.bar.description"
,
hint
.
getId
()
);
assert
Equals
(
2
,
hint
.
getValueHints
().
size
()
);
assert
That
(
hint
.
getId
()).
isEqualTo
(
"spring.bar.description"
);
assert
That
(
hint
.
getValueHints
()).
hasSize
(
2
);
ValueHint
valueHint
=
hint
.
getValueHints
().
get
(
0
);
assert
Equals
(
"one"
,
valueHint
.
getValue
()
);
assert
Equals
(
"One."
,
valueHint
.
getDescription
()
);
assert
That
(
valueHint
.
getValue
()).
isEqualTo
(
"one"
);
assert
That
(
valueHint
.
getDescription
()).
isEqualTo
(
"One."
);
ValueHint
valueHint2
=
hint
.
getValueHints
().
get
(
1
);
assert
Equals
(
"two"
,
valueHint2
.
getValue
()
);
assert
Equals
(
null
,
valueHint2
.
getDescription
()
);
assert
That
(
valueHint2
.
getValue
()).
isEqualTo
(
"two"
);
assert
That
(
valueHint2
.
getDescription
()).
isEqualTo
(
null
);
assert
Equals
(
2
,
hint
.
getValueProviders
().
size
()
);
assert
That
(
hint
.
getValueProviders
()).
hasSize
(
2
);
ValueProvider
valueProvider
=
hint
.
getValueProviders
().
get
(
0
);
assertEquals
(
"handle-as"
,
valueProvider
.
getName
());
assertEquals
(
1
,
valueProvider
.
getParameters
().
size
());
assertEquals
(
String
.
class
.
getName
(),
valueProvider
.
getParameters
().
get
(
"target"
));
assertThat
(
valueProvider
.
getName
()).
isEqualTo
(
"handle-as"
);
assertThat
(
valueProvider
.
getParameters
()).
hasSize
(
1
);
assertThat
(
valueProvider
.
getParameters
().
get
(
"target"
))
.
isEqualTo
(
String
.
class
.
getName
());
ValueProvider
valueProvider2
=
hint
.
getValueProviders
().
get
(
1
);
assert
Equals
(
"any"
,
valueProvider2
.
getName
()
);
assert
Equals
(
0
,
valueProvider2
.
getParameters
().
size
()
);
assert
That
(
valueProvider2
.
getName
()).
isEqualTo
(
"any"
);
assert
That
(
valueProvider2
.
getParameters
()).
isEmpty
(
);
}
@Test
public
void
rootMetadata
()
throws
IOException
{
RawConfigurationMetadata
rawMetadata
=
readFor
(
"root"
);
List
<
ConfigurationMetadataSource
>
sources
=
rawMetadata
.
getSources
();
assert
Equals
(
0
,
sources
.
size
()
);
assert
That
(
sources
).
isEmpty
(
);
List
<
ConfigurationMetadataItem
>
items
=
rawMetadata
.
getItems
();
assert
Equals
(
2
,
items
.
size
()
);
assert
That
(
items
).
hasSize
(
2
);
ConfigurationMetadataItem
item
=
items
.
get
(
0
);
assertProperty
(
item
,
"spring.root.name"
,
"spring.root.name"
,
String
.
class
,
null
);
}
...
...
@@ -137,27 +135,28 @@ public class JsonReaderTests extends AbstractConfigurationMetadataTests {
public
void
deprecatedMetadata
()
throws
IOException
{
RawConfigurationMetadata
rawMetadata
=
readFor
(
"deprecated"
);
List
<
ConfigurationMetadataItem
>
items
=
rawMetadata
.
getItems
();
assert
Equals
(
3
,
items
.
size
()
);
assert
That
(
items
).
hasSize
(
3
);
ConfigurationMetadataItem
item
=
items
.
get
(
0
);
assertProperty
(
item
,
"server.port"
,
"server.port"
,
Integer
.
class
,
null
);
assertTrue
(
item
.
isDeprecated
());
assertEquals
(
"Server namespace has moved to spring.server"
,
item
.
getDeprecation
().
getReason
());
assertEquals
(
"server.spring.port"
,
item
.
getDeprecation
().
getReplacement
());
assertThat
(
item
.
isDeprecated
()).
isTrue
();
assertThat
(
item
.
getDeprecation
().
getReason
())
.
isEqualTo
(
"Server namespace has moved to spring.server"
);
assertThat
(
item
.
getDeprecation
().
getReplacement
())
.
isEqualTo
(
"server.spring.port"
);
ConfigurationMetadataItem
item2
=
items
.
get
(
1
);
assertProperty
(
item2
,
"server.cluster-name"
,
"server.cluster-name"
,
String
.
class
,
null
);
assertT
rue
(
item2
.
isDeprecated
()
);
assert
Equals
(
null
,
item2
.
getDeprecation
().
getReason
()
);
assert
Equals
(
null
,
item2
.
getDeprecation
().
getReplacement
()
);
assertT
hat
(
item2
.
isDeprecated
()).
isTrue
(
);
assert
That
(
item2
.
getDeprecation
().
getReason
()).
isEqualTo
(
null
);
assert
That
(
item2
.
getDeprecation
().
getReplacement
()).
isEqualTo
(
null
);
ConfigurationMetadataItem
item3
=
items
.
get
(
2
);
assertProperty
(
item3
,
"spring.server.name"
,
"spring.server.name"
,
String
.
class
,
null
);
assert
False
(
item3
.
isDeprecated
()
);
assert
Equals
(
null
,
item3
.
getDeprecation
()
);
assert
That
(
item3
.
isDeprecated
()).
isFalse
(
);
assert
That
(
item3
.
getDeprecation
()).
isEqualTo
(
null
);
}
RawConfigurationMetadata
readFor
(
String
path
)
throws
IOException
{
...
...
spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java
View file @
00cfe1d0
...
...
@@ -63,16 +63,7 @@ import org.springframework.boot.configurationsample.specific.InnerClassRootConfi
import
org.springframework.boot.configurationsample.specific.SimplePojo
;
import
org.springframework.util.FileCopyUtils
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
empty
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
not
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
springframework
.
boot
.
configurationprocessor
.
ConfigurationMetadataMatchers
.
containsGroup
;
import
static
org
.
springframework
.
boot
.
configurationprocessor
.
ConfigurationMetadataMatchers
.
containsHint
;
import
static
org
.
springframework
.
boot
.
configurationprocessor
.
ConfigurationMetadataMatchers
.
containsProperty
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link ConfigurationMetadataAnnotationProcessor}.
...
...
@@ -100,80 +91,88 @@ public class ConfigurationMetadataAnnotationProcessorTests {
@Test
public
void
notAnnotated
()
throws
Exception
{
ConfigurationMetadata
metadata
=
compile
(
NotAnnotated
.
class
);
assertThat
(
"No config metadata file should have been generated when "
+
"no metadata is discovered"
,
metadata
.
getItems
(),
empty
());
assertThat
(
metadata
.
getItems
()).
isEmpty
();
}
@Test
public
void
simpleProperties
()
throws
Exception
{
ConfigurationMetadata
metadata
=
compile
(
SimpleProperties
.
class
);
assertThat
(
metadata
,
containsGroup
(
"simple"
).
fromSource
(
SimpleProperties
.
class
));
assertThat
(
metadata
,
contains
Property
(
"simple.the-name"
,
String
.
class
)
assertThat
(
metadata
)
.
has
(
Metadata
.
withGroup
(
"simple"
).
fromSource
(
SimpleProperties
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"simple.the-name"
,
String
.
class
)
.
fromSource
(
SimpleProperties
.
class
)
.
withDescription
(
"The name of this simple properties."
)
.
withDefaultValue
(
is
(
"boot"
)).
withDeprecation
(
null
,
null
));
assertThat
(
metadata
,
containsProperty
(
"simple.flag"
,
Boolean
.
class
)
.
fromSource
(
SimpleProperties
.
class
)
.
withDescription
(
"A simple flag."
).
withDeprecation
(
null
,
null
));
assertThat
(
metadata
,
containsProperty
(
"simple.comparator"
));
assertThat
(
metadata
,
not
(
containsProperty
(
"simple.counter"
)));
assertThat
(
metadata
,
not
(
containsProperty
(
"simple.size"
)));
.
withDefaultValue
(
"boot"
).
withDeprecation
(
null
,
null
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"simple.flag"
,
Boolean
.
class
)
.
fromSource
(
SimpleProperties
.
class
).
withDescription
(
"A simple flag."
)
.
withDeprecation
(
null
,
null
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"simple.comparator"
));
assertThat
(
metadata
).
doesNotHave
(
Metadata
.
withProperty
(
"simple.counter"
));
assertThat
(
metadata
).
doesNotHave
(
Metadata
.
withProperty
(
"simple.size"
));
}
@Test
public
void
simplePrefixValueProperties
()
throws
Exception
{
ConfigurationMetadata
metadata
=
compile
(
SimplePrefixValueProperties
.
class
);
assertThat
(
metadata
,
containsGroup
(
"simple"
)
.
fromSource
(
SimplePrefixValueProperties
.
class
));
assertThat
(
metadata
,
contains
Property
(
"simple.name"
,
String
.
class
)
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"simple"
)
.
fromSource
(
SimplePrefixValueProperties
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"simple.name"
,
String
.
class
)
.
fromSource
(
SimplePrefixValueProperties
.
class
));
}
@Test
public
void
simpleTypeProperties
()
throws
Exception
{
ConfigurationMetadata
metadata
=
compile
(
SimpleTypeProperties
.
class
);
assertThat
(
metadata
,
containsGroup
(
"simple.type"
).
fromSource
(
SimpleTypeProperties
.
class
));
assertThat
(
metadata
,
containsProperty
(
"simple.type.my-string"
,
String
.
class
));
assertThat
(
metadata
,
containsProperty
(
"simple.type.my-byte"
,
Byte
.
class
));
assertThat
(
metadata
,
containsProperty
(
"simple.type.my-primitive-byte"
,
Byte
.
class
));
assertThat
(
metadata
,
containsProperty
(
"simple.type.my-char"
,
Character
.
class
));
assertThat
(
metadata
,
containsProperty
(
"simple.type.my-primitive-char"
,
Character
.
class
));
assertThat
(
metadata
,
containsProperty
(
"simple.type.my-boolean"
,
Boolean
.
class
));
assertThat
(
metadata
,
containsProperty
(
"simple.type.my-primitive-boolean"
,
Boolean
.
class
));
assertThat
(
metadata
,
containsProperty
(
"simple.type.my-short"
,
Short
.
class
));
assertThat
(
metadata
,
containsProperty
(
"simple.type.my-primitive-short"
,
Short
.
class
));
assertThat
(
metadata
,
containsProperty
(
"simple.type.my-integer"
,
Integer
.
class
));
assertThat
(
metadata
,
containsProperty
(
"simple.type.my-primitive-integer"
,
Integer
.
class
));
assertThat
(
metadata
,
containsProperty
(
"simple.type.my-long"
,
Long
.
class
));
assertThat
(
metadata
,
containsProperty
(
"simple.type.my-primitive-long"
,
Long
.
class
));
assertThat
(
metadata
,
containsProperty
(
"simple.type.my-double"
,
Double
.
class
));
assertThat
(
metadata
,
containsProperty
(
"simple.type.my-primitive-double"
,
Double
.
class
));
assertThat
(
metadata
,
containsProperty
(
"simple.type.my-float"
,
Float
.
class
));
assertThat
(
metadata
,
containsProperty
(
"simple.type.my-primitive-float"
,
Float
.
class
));
assertThat
(
metadata
.
getItems
().
size
(),
equalTo
(
18
));
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"simple.type"
).
fromSource
(
SimpleTypeProperties
.
class
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"simple.type.my-string"
,
String
.
class
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"simple.type.my-byte"
,
Byte
.
class
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"simple.type.my-primitive-byte"
,
Byte
.
class
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"simple.type.my-char"
,
Character
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"simple.type.my-primitive-char"
,
Character
.
class
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"simple.type.my-boolean"
,
Boolean
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"simple.type.my-primitive-boolean"
,
Boolean
.
class
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"simple.type.my-short"
,
Short
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"simple.type.my-primitive-short"
,
Short
.
class
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"simple.type.my-integer"
,
Integer
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"simple.type.my-primitive-integer"
,
Integer
.
class
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"simple.type.my-long"
,
Long
.
class
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"simple.type.my-primitive-long"
,
Long
.
class
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"simple.type.my-double"
,
Double
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"simple.type.my-primitive-double"
,
Double
.
class
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"simple.type.my-float"
,
Float
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"simple.type.my-primitive-float"
,
Float
.
class
));
assertThat
(
metadata
.
getItems
().
size
()).
isEqualTo
(
18
);
}
@Test
public
void
hierarchicalProperties
()
throws
Exception
{
ConfigurationMetadata
metadata
=
compile
(
HierarchicalProperties
.
class
);
assertThat
(
metadata
,
containsGroup
(
"hierarchical"
).
fromSource
(
HierarchicalProperties
.
class
));
assertThat
(
metadata
,
containsProperty
(
"hierarchical.first"
,
String
.
class
)
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"hierarchical"
)
.
fromSource
(
HierarchicalProperties
.
class
));
assertThat
(
metadata
,
containsProperty
(
"hierarchical.second
"
,
String
.
class
)
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"hierarchical.first
"
,
String
.
class
)
.
fromSource
(
HierarchicalProperties
.
class
));
assertThat
(
metadata
,
containsProperty
(
"hierarchical.third"
,
String
.
class
)
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"hierarchical.second"
,
String
.
class
)
.
fromSource
(
HierarchicalProperties
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"hierarchical.third"
,
String
.
class
)
.
fromSource
(
HierarchicalProperties
.
class
));
}
...
...
@@ -182,10 +181,11 @@ public class ConfigurationMetadataAnnotationProcessorTests {
public
void
deprecatedProperties
()
throws
Exception
{
Class
<?>
type
=
org
.
springframework
.
boot
.
configurationsample
.
simple
.
DeprecatedProperties
.
class
;
ConfigurationMetadata
metadata
=
compile
(
type
);
assertThat
(
metadata
,
contains
Group
(
"deprecated"
).
fromSource
(
type
));
assertThat
(
metadata
,
contains
Property
(
"deprecated.name"
,
String
.
class
)
assertThat
(
metadata
).
has
(
Metadata
.
with
Group
(
"deprecated"
).
fromSource
(
type
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"deprecated.name"
,
String
.
class
)
.
fromSource
(
type
).
withDeprecation
(
null
,
null
));
assertThat
(
metadata
,
containsProperty
(
"deprecated.description"
,
String
.
class
)
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"deprecated.description"
,
String
.
class
)
.
fromSource
(
type
).
withDeprecation
(
null
,
null
));
}
...
...
@@ -193,11 +193,12 @@ public class ConfigurationMetadataAnnotationProcessorTests {
public
void
singleDeprecatedProperty
()
throws
Exception
{
Class
<?>
type
=
DeprecatedSingleProperty
.
class
;
ConfigurationMetadata
metadata
=
compile
(
type
);
assertThat
(
metadata
,
containsGroup
(
"singledeprecated"
).
fromSource
(
type
));
assertThat
(
metadata
,
containsProperty
(
"singledeprecated.new-name"
,
String
.
class
)
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"singledeprecated"
).
fromSource
(
type
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"singledeprecated.new-name"
,
String
.
class
)
.
fromSource
(
type
));
assertThat
(
metadata
,
contains
Property
(
"singledeprecated.name"
,
String
.
class
).
fromSource
(
type
)
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"singledeprecated.name"
,
String
.
class
).
fromSource
(
type
)
.
withDeprecation
(
"renamed"
,
"singledeprecated.new-name"
));
}
...
...
@@ -205,10 +206,12 @@ public class ConfigurationMetadataAnnotationProcessorTests {
public
void
deprecatedOnUnrelatedSetter
()
throws
Exception
{
Class
<?>
type
=
DeprecatedUnrelatedMethodPojo
.
class
;
ConfigurationMetadata
metadata
=
compile
(
type
);
assertThat
(
metadata
,
containsGroup
(
"not.deprecated"
).
fromSource
(
type
));
assertThat
(
metadata
,
containsProperty
(
"not.deprecated.counter"
,
Integer
.
class
)
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"not.deprecated"
).
fromSource
(
type
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"not.deprecated.counter"
,
Integer
.
class
)
.
withNoDeprecation
().
fromSource
(
type
));
assertThat
(
metadata
,
containsProperty
(
"not.deprecated.flag"
,
Boolean
.
class
)
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"not.deprecated.flag"
,
Boolean
.
class
)
.
withNoDeprecation
().
fromSource
(
type
));
}
...
...
@@ -216,118 +219,119 @@ public class ConfigurationMetadataAnnotationProcessorTests {
public
void
boxingOnSetter
()
throws
IOException
{
Class
<?>
type
=
BoxingPojo
.
class
;
ConfigurationMetadata
metadata
=
compile
(
type
);
assertThat
(
metadata
,
contains
Group
(
"boxing"
).
fromSource
(
type
));
assertThat
(
metadata
,
contains
Property
(
"boxing.flag"
,
Boolean
.
class
).
fromSource
(
type
));
assertThat
(
metadata
,
contains
Property
(
"boxing.counter"
,
Integer
.
class
).
fromSource
(
type
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Group
(
"boxing"
).
fromSource
(
type
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"boxing.flag"
,
Boolean
.
class
).
fromSource
(
type
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"boxing.counter"
,
Integer
.
class
).
fromSource
(
type
));
}
@Test
public
void
parseCollectionConfig
()
throws
Exception
{
ConfigurationMetadata
metadata
=
compile
(
SimpleCollectionProperties
.
class
);
// getter and setter
assertThat
(
metadata
,
contains
Property
(
"collection.integers-to-names"
,
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"collection.integers-to-names"
,
"java.util.Map<java.lang.Integer,java.lang.String>"
));
assertThat
(
metadata
,
contains
Property
(
"collection.longs"
,
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"collection.longs"
,
"java.util.Collection<java.lang.Long>"
));
assertThat
(
metadata
,
containsProperty
(
"collection.floats"
,
"java.util.List<java.lang.Float>"
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"collection.floats"
,
"java.util.List<java.lang.Float>"
));
// getter only
assertThat
(
metadata
,
contains
Property
(
"collection.names-to-integers"
,
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"collection.names-to-integers"
,
"java.util.Map<java.lang.String,java.lang.Integer>"
));
assertThat
(
metadata
,
contains
Property
(
"collection.bytes"
,
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"collection.bytes"
,
"java.util.Collection<java.lang.Byte>"
));
assertThat
(
metadata
,
contains
Property
(
"collection.doubles"
,
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"collection.doubles"
,
"java.util.List<java.lang.Double>"
));
}
@Test
public
void
simpleMethodConfig
()
throws
Exception
{
ConfigurationMetadata
metadata
=
compile
(
SimpleMethodConfig
.
class
);
assertThat
(
metadata
,
containsGroup
(
"foo"
).
fromSource
(
SimpleMethodConfig
.
class
));
assertThat
(
metadata
,
containsProperty
(
"foo.name"
,
String
.
class
)
assertThat
(
metadata
)
.
has
(
Metadata
.
withGroup
(
"foo"
).
fromSource
(
SimpleMethodConfig
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"foo.name"
,
String
.
class
)
.
fromSource
(
SimpleMethodConfig
.
Foo
.
class
));
assertThat
(
metadata
,
contains
Property
(
"foo.flag"
,
Boolean
.
class
)
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"foo.flag"
,
Boolean
.
class
)
.
fromSource
(
SimpleMethodConfig
.
Foo
.
class
));
}
@Test
public
void
invalidMethodConfig
()
throws
Exception
{
ConfigurationMetadata
metadata
=
compile
(
InvalidMethodConfig
.
class
);
assertThat
(
metadata
,
contains
Property
(
"something.name"
,
String
.
class
)
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"something.name"
,
String
.
class
)
.
fromSource
(
InvalidMethodConfig
.
class
));
assertThat
(
metadata
,
not
(
containsProperty
(
"invalid.name"
)
));
assertThat
(
metadata
).
isNotEqualTo
(
Metadata
.
withProperty
(
"invalid.name"
));
}
@Test
public
void
methodAndClassConfig
()
throws
Exception
{
ConfigurationMetadata
metadata
=
compile
(
MethodAndClassConfig
.
class
);
assertThat
(
metadata
,
contains
Property
(
"conflict.name"
,
String
.
class
)
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"conflict.name"
,
String
.
class
)
.
fromSource
(
MethodAndClassConfig
.
Foo
.
class
));
assertThat
(
metadata
,
contains
Property
(
"conflict.flag"
,
Boolean
.
class
)
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"conflict.flag"
,
Boolean
.
class
)
.
fromSource
(
MethodAndClassConfig
.
Foo
.
class
));
assertThat
(
metadata
,
contains
Property
(
"conflict.value"
,
String
.
class
)
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"conflict.value"
,
String
.
class
)
.
fromSource
(
MethodAndClassConfig
.
class
));
}
@Test
public
void
emptyTypeMethodConfig
()
throws
Exception
{
ConfigurationMetadata
metadata
=
compile
(
EmptyTypeMethodConfig
.
class
);
assertThat
(
metadata
,
not
(
containsProperty
(
"something.foo"
)
));
assertThat
(
metadata
).
isNotEqualTo
(
Metadata
.
withProperty
(
"something.foo"
));
}
@Test
public
void
innerClassRootConfig
()
throws
Exception
{
ConfigurationMetadata
metadata
=
compile
(
InnerClassRootConfig
.
class
);
assertThat
(
metadata
,
contains
Property
(
"config.name"
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"config.name"
));
}
@Test
public
void
innerClassProperties
()
throws
Exception
{
ConfigurationMetadata
metadata
=
compile
(
InnerClassProperties
.
class
);
assertThat
(
metadata
,
containsGroup
(
"config"
).
fromSource
(
InnerClassProperties
.
class
));
assertThat
(
metadata
,
containsGroup
(
"config.first"
).
ofType
(
InnerClassProperties
.
Foo
.
class
)
.
fromSource
(
InnerClassProperties
.
class
));
assertThat
(
metadata
,
containsProperty
(
"config.first.name"
));
assertThat
(
metadata
,
containsProperty
(
"config.first.bar.name"
));
assertThat
(
metadata
,
containsGroup
(
"config.the-second"
,
InnerClassProperties
.
Foo
.
class
)
assertThat
(
metadata
)
.
has
(
Metadata
.
withGroup
(
"config"
).
fromSource
(
InnerClassProperties
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"config.first"
).
ofType
(
InnerClassProperties
.
Foo
.
class
)
.
fromSource
(
InnerClassProperties
.
class
));
assertThat
(
metadata
,
containsProperty
(
"config.the-second.name"
));
assertThat
(
metadata
,
containsProperty
(
"config.the-second.bar.name"
));
assertThat
(
metadata
,
containsGroup
(
"config.third"
).
ofType
(
SimplePojo
.
class
)
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"config.first.name"
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"config.first.bar.name"
));
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"config.the-second"
,
InnerClassProperties
.
Foo
.
class
)
.
fromSource
(
InnerClassProperties
.
class
));
assertThat
(
metadata
,
containsProperty
(
"config.third.value"
));
assertThat
(
metadata
,
containsProperty
(
"config.fourth"
));
assertThat
(
metadata
,
not
(
containsGroup
(
"config.fourth"
)));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"config.the-second.name"
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"config.the-second.bar.name"
));
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"config.third"
)
.
ofType
(
SimplePojo
.
class
).
fromSource
(
InnerClassProperties
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"config.third.value"
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"config.fourth"
));
assertThat
(
metadata
).
isNotEqualTo
(
Metadata
.
withGroup
(
"config.fourth"
));
}
@Test
public
void
innerClassAnnotatedGetterConfig
()
throws
Exception
{
ConfigurationMetadata
metadata
=
compile
(
InnerClassAnnotatedGetterConfig
.
class
);
assertThat
(
metadata
,
contains
Property
(
"specific.value"
));
assertThat
(
metadata
,
contains
Property
(
"foo.name"
));
assertThat
(
metadata
,
not
(
containsProperty
(
"specific.foo"
)
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"specific.value"
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"foo.name"
));
assertThat
(
metadata
).
isNotEqualTo
(
Metadata
.
withProperty
(
"specific.foo"
));
}
@Test
public
void
builderPojo
()
throws
IOException
{
ConfigurationMetadata
metadata
=
compile
(
BuilderPojo
.
class
);
assertThat
(
metadata
,
contains
Property
(
"builder.name"
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"builder.name"
));
}
@Test
public
void
excludedTypesPojo
()
throws
IOException
{
ConfigurationMetadata
metadata
=
compile
(
ExcludedTypesPojo
.
class
);
assertThat
(
metadata
,
contains
Property
(
"excluded.name"
));
assertThat
(
metadata
,
not
(
containsProperty
(
"excluded.class-loader"
)
));
assertThat
(
metadata
,
not
(
containsProperty
(
"excluded.data-source"
)
));
assertThat
(
metadata
,
not
(
containsProperty
(
"excluded.print-writer"
)
));
assertThat
(
metadata
,
not
(
containsProperty
(
"excluded.writer"
)
));
assertThat
(
metadata
,
not
(
containsProperty
(
"excluded.writer-array"
)
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"excluded.name"
));
assertThat
(
metadata
).
isNotEqualTo
(
Metadata
.
withProperty
(
"excluded.class-loader"
));
assertThat
(
metadata
).
isNotEqualTo
(
Metadata
.
withProperty
(
"excluded.data-source"
));
assertThat
(
metadata
).
isNotEqualTo
(
Metadata
.
withProperty
(
"excluded.print-writer"
));
assertThat
(
metadata
).
isNotEqualTo
(
Metadata
.
withProperty
(
"excluded.writer"
));
assertThat
(
metadata
).
isNotEqualTo
(
Metadata
.
withProperty
(
"excluded.writer-array"
));
}
@Test
...
...
@@ -352,19 +356,20 @@ public class ConfigurationMetadataAnnotationProcessorTests {
@Test
public
void
lombokInnerClassProperties
()
throws
Exception
{
ConfigurationMetadata
metadata
=
compile
(
LombokInnerClassProperties
.
class
);
assertThat
(
metadata
,
containsGroup
(
"config"
)
.
fromSource
(
LombokInnerClassProperties
.
class
));
assertThat
(
metadata
,
containsGroup
(
"config.first"
)
.
ofType
(
LombokInnerClassProperties
.
Foo
.
class
)
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"config"
)
.
fromSource
(
LombokInnerClassProperties
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"config.first"
)
.
ofType
(
LombokInnerClassProperties
.
Foo
.
class
)
.
fromSource
(
LombokInnerClassProperties
.
class
));
assertThat
(
metadata
,
contains
Property
(
"config.first.name"
));
assertThat
(
metadata
,
contains
Property
(
"config.first.bar.name"
));
assertThat
(
metadata
,
contains
Group
(
"config.second"
,
LombokInnerClassProperties
.
Foo
.
class
)
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"config.first.name"
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"config.first.bar.name"
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Group
(
"config.second"
,
LombokInnerClassProperties
.
Foo
.
class
)
.
fromSource
(
LombokInnerClassProperties
.
class
));
assertThat
(
metadata
,
containsProperty
(
"config.second.name"
));
assertThat
(
metadata
,
containsProperty
(
"config.second.bar.name"
));
assertThat
(
metadata
,
containsGroup
(
"config.third"
).
ofType
(
SimpleLombokPojo
.
class
)
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"config.second.name"
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"config.second.bar.name"
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withGroup
(
"config.third"
).
ofType
(
SimpleLombokPojo
.
class
)
.
fromSource
(
LombokInnerClassProperties
.
class
));
// For some reason the annotation processor resolves a type for SimpleLombokPojo
// that is resolved (compiled) and the source annotations are gone. Because we
...
...
@@ -372,8 +377,8 @@ public class ConfigurationMetadataAnnotationProcessorTests {
// that a sample project works fine so this seem to be related to the unit test
// environment for some reason. assertThat(metadata,
// containsProperty("config.third.value"));
assertThat
(
metadata
,
contains
Property
(
"config.fourth"
));
assertThat
(
metadata
,
not
(
containsGroup
(
"config.fourth"
)
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"config.fourth"
));
assertThat
(
metadata
).
isNotEqualTo
(
Metadata
.
withGroup
(
"config.fourth"
));
}
@Test
...
...
@@ -382,8 +387,8 @@ public class ConfigurationMetadataAnnotationProcessorTests {
AdditionalMetadata
.
class
.
getName
(),
null
,
null
,
null
,
null
);
writeAdditionalMetadata
(
property
);
ConfigurationMetadata
metadata
=
compile
(
SimpleProperties
.
class
);
assertThat
(
metadata
,
contains
Property
(
"simple.comparator"
));
assertThat
(
metadata
,
contains
Property
(
"foo"
,
String
.
class
)
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"simple.comparator"
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"foo"
,
String
.
class
)
.
fromSource
(
AdditionalMetadata
.
class
));
}
...
...
@@ -393,10 +398,10 @@ public class ConfigurationMetadataAnnotationProcessorTests {
null
,
null
,
true
,
null
);
writeAdditionalMetadata
(
property
);
ConfigurationMetadata
metadata
=
compile
(
SimpleProperties
.
class
);
assertThat
(
metadata
,
contains
Property
(
"simple.flag"
,
Boolean
.
class
)
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"simple.flag"
,
Boolean
.
class
)
.
fromSource
(
SimpleProperties
.
class
).
withDescription
(
"A simple flag."
)
.
withDeprecation
(
null
,
null
).
withDefaultValue
(
is
(
true
)
));
assertThat
(
metadata
.
getItems
()
.
size
(),
is
(
4
)
);
.
withDeprecation
(
null
,
null
).
withDefaultValue
(
true
));
assertThat
(
metadata
.
getItems
()
).
hasSize
(
4
);
}
@Test
...
...
@@ -405,11 +410,11 @@ public class ConfigurationMetadataAnnotationProcessorTests {
null
,
null
,
"A nice comparator."
,
null
,
null
);
writeAdditionalMetadata
(
property
);
ConfigurationMetadata
metadata
=
compile
(
SimpleProperties
.
class
);
assertThat
(
metadata
,
contains
Property
(
"simple.comparator"
,
"java.util.Comparator<?>"
)
assertThat
(
metadata
)
.
has
(
Metadata
.
with
Property
(
"simple.comparator"
,
"java.util.Comparator<?>"
)
.
fromSource
(
SimpleProperties
.
class
)
.
withDescription
(
"A nice comparator."
));
assertThat
(
metadata
.
getItems
()
.
size
(),
is
(
4
)
);
assertThat
(
metadata
.
getItems
()
).
hasSize
(
4
);
}
@Test
...
...
@@ -419,11 +424,11 @@ public class ConfigurationMetadataAnnotationProcessorTests {
new
ItemDeprecation
(
"Don't use this."
,
"simple.complex-comparator"
));
writeAdditionalMetadata
(
property
);
ConfigurationMetadata
metadata
=
compile
(
SimpleProperties
.
class
);
assertThat
(
metadata
,
contains
Property
(
"simple.comparator"
,
"java.util.Comparator<?>"
)
assertThat
(
metadata
)
.
has
(
Metadata
.
with
Property
(
"simple.comparator"
,
"java.util.Comparator<?>"
)
.
fromSource
(
SimpleProperties
.
class
)
.
withDeprecation
(
"Don't use this."
,
"simple.complex-comparator"
));
assertThat
(
metadata
.
getItems
()
.
size
(),
is
(
4
)
);
assertThat
(
metadata
.
getItems
()
).
hasSize
(
4
);
}
@Test
...
...
@@ -433,11 +438,11 @@ public class ConfigurationMetadataAnnotationProcessorTests {
new
ItemDeprecation
(
"Don't use this."
,
"single.name"
));
writeAdditionalMetadata
(
property
);
ConfigurationMetadata
metadata
=
compile
(
DeprecatedSingleProperty
.
class
);
assertThat
(
metadata
,
contains
Property
(
"singledeprecated.name"
,
String
.
class
.
getName
())
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"singledeprecated.name"
,
String
.
class
.
getName
())
.
fromSource
(
DeprecatedSingleProperty
.
class
)
.
withDeprecation
(
"Don't use this."
,
"single.name"
));
assertThat
(
metadata
.
getItems
()
.
size
(),
is
(
3
)
);
assertThat
(
metadata
.
getItems
()
).
hasSize
(
3
);
}
@Test
...
...
@@ -456,12 +461,11 @@ public class ConfigurationMetadataAnnotationProcessorTests {
new
ItemHint
.
ValueHint
(
"boot"
,
"Bla bla"
),
new
ItemHint
.
ValueHint
(
"spring"
,
null
)));
ConfigurationMetadata
metadata
=
compile
(
SimpleProperties
.
class
);
assertThat
(
metadata
,
containsProperty
(
"simple.the-name"
,
String
.
class
)
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"simple.the-name"
,
String
.
class
)
.
fromSource
(
SimpleProperties
.
class
)
.
withDescription
(
"The name of this simple properties."
)
.
withDefaultValue
(
is
(
"boot"
)
).
withDeprecation
(
null
,
null
));
assertThat
(
metadata
,
contains
Hint
(
"simple.the-name"
)
.
withDefaultValue
(
"boot"
).
withDeprecation
(
null
,
null
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Hint
(
"simple.the-name"
)
.
withValue
(
0
,
"boot"
,
"Bla bla"
).
withValue
(
1
,
"spring"
,
null
));
}
...
...
@@ -470,13 +474,12 @@ public class ConfigurationMetadataAnnotationProcessorTests {
writeAdditionalHints
(
ItemHint
.
newHint
(
"simple.theName"
,
new
ItemHint
.
ValueHint
(
"boot"
,
"Bla bla"
)));
ConfigurationMetadata
metadata
=
compile
(
SimpleProperties
.
class
);
assertThat
(
metadata
,
containsProperty
(
"simple.the-name"
,
String
.
class
)
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"simple.the-name"
,
String
.
class
)
.
fromSource
(
SimpleProperties
.
class
)
.
withDescription
(
"The name of this simple properties."
)
.
withDefaultValue
(
is
(
"boot"
)
).
withDeprecation
(
null
,
null
));
assertThat
(
metadata
,
contains
Hint
(
"simple.the-name"
).
withValue
(
0
,
"boot"
,
"Bla bla"
));
.
withDefaultValue
(
"boot"
).
withDeprecation
(
null
,
null
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Hint
(
"simple.the-name"
).
withValue
(
0
,
"boot"
,
"Bla bla"
));
}
@Test
...
...
@@ -489,12 +492,11 @@ public class ConfigurationMetadataAnnotationProcessorTests {
"org.foo"
)),
new
ItemHint
.
ValueProvider
(
"second"
,
null
))));
ConfigurationMetadata
metadata
=
compile
(
SimpleProperties
.
class
);
assertThat
(
metadata
,
containsProperty
(
"simple.the-name"
,
String
.
class
)
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"simple.the-name"
,
String
.
class
)
.
fromSource
(
SimpleProperties
.
class
)
.
withDescription
(
"The name of this simple properties."
)
.
withDefaultValue
(
is
(
"boot"
)
).
withDeprecation
(
null
,
null
));
assertThat
(
metadata
,
contains
Hint
(
"simple.the-name"
)
.
withDefaultValue
(
"boot"
).
withDeprecation
(
null
,
null
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Hint
(
"simple.the-name"
)
.
withProvider
(
"first"
,
"target"
,
"org.foo"
).
withProvider
(
"second"
));
}
...
...
@@ -504,7 +506,7 @@ public class ConfigurationMetadataAnnotationProcessorTests {
"java.lang.String"
,
null
,
null
,
null
,
null
,
new
ItemDeprecation
(
"Lame name."
,
"simple.the-name"
)));
ConfigurationMetadata
metadata
=
compile
(
SimpleProperties
.
class
);
assertThat
(
metadata
,
contains
Property
(
"simple.wrong-name"
,
String
.
class
)
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"simple.wrong-name"
,
String
.
class
)
.
withDeprecation
(
"Lame name."
,
"simple.the-name"
));
}
...
...
@@ -527,8 +529,8 @@ public class ConfigurationMetadataAnnotationProcessorTests {
additionalMetadata
.
write
(
writer
);
writer
.
flush
();
ConfigurationMetadata
metadata
=
compile
(
SimpleProperties
.
class
);
assertThat
(
metadata
,
contains
Property
(
"simple.comparator"
));
assertThat
(
metadata
,
contains
Property
(
"foo"
,
String
.
class
)
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"simple.comparator"
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"foo"
,
String
.
class
)
.
fromSource
(
AdditionalMetadata
.
class
));
}
...
...
@@ -536,29 +538,29 @@ public class ConfigurationMetadataAnnotationProcessorTests {
public
void
incrementalBuild
()
throws
Exception
{
TestProject
project
=
new
TestProject
(
this
.
temporaryFolder
,
FooProperties
.
class
,
BarProperties
.
class
);
assert
False
(
project
.
getOutputFile
(
MetadataStore
.
METADATA_PATH
).
exists
()
);
assert
That
(
project
.
getOutputFile
(
MetadataStore
.
METADATA_PATH
).
exists
()).
isFalse
(
);
ConfigurationMetadata
metadata
=
project
.
fullBuild
();
assertT
rue
(
project
.
getOutputFile
(
MetadataStore
.
METADATA_PATH
).
exists
()
);
assertThat
(
metadata
,
contains
Property
(
"foo.counter"
).
fromSource
(
FooProperties
.
class
));
assertThat
(
metadata
,
contains
Property
(
"bar.counter"
).
fromSource
(
BarProperties
.
class
));
assertT
hat
(
project
.
getOutputFile
(
MetadataStore
.
METADATA_PATH
).
exists
()).
isTrue
(
);
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"foo.counter"
).
fromSource
(
FooProperties
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"bar.counter"
).
fromSource
(
BarProperties
.
class
));
metadata
=
project
.
incrementalBuild
(
BarProperties
.
class
);
assertThat
(
metadata
,
contains
Property
(
"foo.counter"
).
fromSource
(
FooProperties
.
class
));
assertThat
(
metadata
,
contains
Property
(
"bar.counter"
).
fromSource
(
BarProperties
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"foo.counter"
).
fromSource
(
FooProperties
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"bar.counter"
).
fromSource
(
BarProperties
.
class
));
project
.
addSourceCode
(
BarProperties
.
class
,
BarProperties
.
class
.
getResourceAsStream
(
"BarProperties.snippet"
));
metadata
=
project
.
incrementalBuild
(
BarProperties
.
class
);
assertThat
(
metadata
,
contains
Property
(
"bar.extra"
));
assertThat
(
metadata
,
contains
Property
(
"foo.counter"
));
assertThat
(
metadata
,
contains
Property
(
"bar.counter"
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"bar.extra"
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"foo.counter"
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"bar.counter"
));
project
.
revert
(
BarProperties
.
class
);
metadata
=
project
.
incrementalBuild
(
BarProperties
.
class
);
assertThat
(
metadata
,
not
(
containsProperty
(
"bar.extra"
)
));
assertThat
(
metadata
,
contains
Property
(
"foo.counter"
));
assertThat
(
metadata
,
contains
Property
(
"bar.counter"
));
assertThat
(
metadata
).
isNotEqualTo
(
Metadata
.
withProperty
(
"bar.extra"
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"foo.counter"
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"bar.counter"
));
}
@Test
...
...
@@ -566,13 +568,13 @@ public class ConfigurationMetadataAnnotationProcessorTests {
TestProject
project
=
new
TestProject
(
this
.
temporaryFolder
,
FooProperties
.
class
,
BarProperties
.
class
);
ConfigurationMetadata
metadata
=
project
.
fullBuild
();
assertThat
(
metadata
,
contains
Property
(
"foo.counter"
));
assertThat
(
metadata
,
contains
Property
(
"bar.counter"
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"foo.counter"
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"bar.counter"
));
project
.
replaceText
(
BarProperties
.
class
,
"@ConfigurationProperties"
,
"//@ConfigurationProperties"
);
metadata
=
project
.
incrementalBuild
(
BarProperties
.
class
);
assertThat
(
metadata
,
contains
Property
(
"foo.counter"
));
assertThat
(
metadata
,
not
(
containsProperty
(
"bar.counter"
)
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"foo.counter"
));
assertThat
(
metadata
).
isNotEqualTo
(
Metadata
.
withProperty
(
"bar.counter"
));
}
@Test
...
...
@@ -580,35 +582,35 @@ public class ConfigurationMetadataAnnotationProcessorTests {
TestProject
project
=
new
TestProject
(
this
.
temporaryFolder
,
FooProperties
.
class
,
BarProperties
.
class
);
ConfigurationMetadata
metadata
=
project
.
fullBuild
();
assertThat
(
metadata
,
contains
Property
(
"foo.counter"
).
fromSource
(
FooProperties
.
class
));
assertThat
(
metadata
,
contains
Property
(
"bar.counter"
).
fromSource
(
BarProperties
.
class
));
assertThat
(
metadata
,
not
(
containsProperty
(
"bar.counter"
).
fromSource
(
RenamedBarProperties
.
class
)
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"foo.counter"
).
fromSource
(
FooProperties
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"bar.counter"
).
fromSource
(
BarProperties
.
class
));
assertThat
(
metadata
).
doesNotHave
(
Metadata
.
withProperty
(
"bar.counter"
)
.
fromSource
(
RenamedBarProperties
.
class
));
project
.
delete
(
BarProperties
.
class
);
project
.
add
(
RenamedBarProperties
.
class
);
metadata
=
project
.
incrementalBuild
(
RenamedBarProperties
.
class
);
assertThat
(
metadata
,
contains
Property
(
"foo.counter"
).
fromSource
(
FooProperties
.
class
));
assertThat
(
metadata
,
not
(
containsProperty
(
"bar.counter"
).
fromSource
(
BarProperties
.
class
)
));
assertThat
(
metadata
,
containsProperty
(
"bar.counter"
)
.
fromSource
(
RenamedBarProperties
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
"foo.counter"
).
fromSource
(
FooProperties
.
class
));
assertThat
(
metadata
).
doesNotHave
(
Metadata
.
withProperty
(
"bar.counter"
).
fromSource
(
BarProperties
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"bar.counter"
)
.
fromSource
(
RenamedBarProperties
.
class
));
}
private
void
assertSimpleLombokProperties
(
ConfigurationMetadata
metadata
,
Class
<?>
source
,
String
prefix
)
{
assertThat
(
metadata
,
contains
Group
(
prefix
).
fromSource
(
source
));
assertThat
(
metadata
,
not
(
containsProperty
(
prefix
+
".id"
)
));
assertThat
(
metadata
,
contains
Property
(
prefix
+
".name"
,
String
.
class
)
assertThat
(
metadata
).
has
(
Metadata
.
with
Group
(
prefix
).
fromSource
(
source
));
assertThat
(
metadata
).
doesNotHave
(
Metadata
.
withProperty
(
prefix
+
".id"
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
prefix
+
".name"
,
String
.
class
)
.
fromSource
(
source
).
withDescription
(
"Name description."
));
assertThat
(
metadata
,
contains
Property
(
prefix
+
".description"
));
assertThat
(
metadata
,
contains
Property
(
prefix
+
".counter"
));
assertThat
(
metadata
,
containsProperty
(
prefix
+
".number"
).
fromSource
(
source
)
.
withDefaultValue
(
is
(
0
)
).
withDeprecation
(
null
,
null
));
assertThat
(
metadata
,
contains
Property
(
prefix
+
".items"
));
assertThat
(
metadata
,
not
(
containsProperty
(
prefix
+
".ignored"
)
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
prefix
+
".description"
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
prefix
+
".counter"
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
prefix
+
".number"
)
.
fromSource
(
source
).
withDefaultValue
(
0
).
withDeprecation
(
null
,
null
));
assertThat
(
metadata
).
has
(
Metadata
.
with
Property
(
prefix
+
".items"
));
assertThat
(
metadata
).
doesNotHave
(
Metadata
.
withProperty
(
prefix
+
".ignored"
));
}
private
ConfigurationMetadata
compile
(
Class
<?>...
types
)
throws
IOException
{
...
...
spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/
ConfigurationMetadataMatchers
.java
→
spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/
Metadata
.java
View file @
00cfe1d0
...
...
@@ -21,9 +21,7 @@ import java.util.Collections;
import
java.util.List
;
import
java.util.Map
;
import
org.hamcrest.BaseMatcher
;
import
org.hamcrest.Description
;
import
org.hamcrest.Matcher
;
import
org.assertj.core.api.Condition
;
import
org.hamcrest.collection.IsMapContaining
;
import
org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata
;
...
...
@@ -31,47 +29,48 @@ import org.springframework.boot.configurationprocessor.metadata.ItemDeprecation;
import
org.springframework.boot.configurationprocessor.metadata.ItemHint
;
import
org.springframework.boot.configurationprocessor.metadata.ItemMetadata
;
import
org.springframework.boot.configurationprocessor.metadata.ItemMetadata.ItemType
;
import
org.springframework.util.ObjectUtils
;
/**
*
Hamcrest {@link Matcher
} to help test {@link ConfigurationMetadata}.
*
AssertJ {@link Condition
} to help test {@link ConfigurationMetadata}.
*
* @author Phillip Webb
* @author Stephane Nicoll
*/
public
final
class
ConfigurationMetadataMatchers
{
public
final
class
Metadata
{
private
ConfigurationMetadataMatchers
()
{
private
Metadata
()
{
}
public
static
ContainsItemMatcher
contains
Group
(
String
name
)
{
return
new
ContainsItemMatcher
(
ItemType
.
GROUP
,
name
);
public
static
MetadataItemCondition
with
Group
(
String
name
)
{
return
new
MetadataItemCondition
(
ItemType
.
GROUP
,
name
);
}
public
static
ContainsItemMatcher
contains
Group
(
String
name
,
Class
<?>
type
)
{
return
new
ContainsItemMatcher
(
ItemType
.
GROUP
,
name
).
ofType
(
type
);
public
static
MetadataItemCondition
with
Group
(
String
name
,
Class
<?>
type
)
{
return
new
MetadataItemCondition
(
ItemType
.
GROUP
,
name
).
ofType
(
type
);
}
public
static
ContainsItemMatcher
contains
Group
(
String
name
,
String
type
)
{
return
new
ContainsItemMatcher
(
ItemType
.
GROUP
,
name
).
ofType
(
type
);
public
static
MetadataItemCondition
with
Group
(
String
name
,
String
type
)
{
return
new
MetadataItemCondition
(
ItemType
.
GROUP
,
name
).
ofType
(
type
);
}
public
static
ContainsItemMatcher
contains
Property
(
String
name
)
{
return
new
ContainsItemMatcher
(
ItemType
.
PROPERTY
,
name
);
public
static
MetadataItemCondition
with
Property
(
String
name
)
{
return
new
MetadataItemCondition
(
ItemType
.
PROPERTY
,
name
);
}
public
static
ContainsItemMatcher
contains
Property
(
String
name
,
Class
<?>
type
)
{
return
new
ContainsItemMatcher
(
ItemType
.
PROPERTY
,
name
).
ofType
(
type
);
public
static
MetadataItemCondition
with
Property
(
String
name
,
Class
<?>
type
)
{
return
new
MetadataItemCondition
(
ItemType
.
PROPERTY
,
name
).
ofType
(
type
);
}
public
static
ContainsItemMatcher
contains
Property
(
String
name
,
String
type
)
{
return
new
ContainsItemMatcher
(
ItemType
.
PROPERTY
,
name
).
ofType
(
type
);
public
static
MetadataItemCondition
with
Property
(
String
name
,
String
type
)
{
return
new
MetadataItemCondition
(
ItemType
.
PROPERTY
,
name
).
ofType
(
type
);
}
public
static
ContainsHintMatcher
contains
Hint
(
String
name
)
{
return
new
ContainsHintMatcher
(
name
);
public
static
MetadataHintCondition
with
Hint
(
String
name
)
{
return
new
MetadataHintCondition
(
name
);
}
public
static
class
ContainsItemMatcher
extends
BaseMatcher
<
ConfigurationMetadata
>
{
public
static
class
MetadataItemCondition
extends
Condition
<
ConfigurationMetadata
>
{
private
final
ItemType
itemType
;
...
...
@@ -83,16 +82,16 @@ public final class ConfigurationMetadataMatchers {
private
final
String
description
;
private
final
Matcher
<?>
defaultValue
;
private
final
Object
defaultValue
;
private
final
ItemDeprecation
deprecation
;
public
ContainsItemMatcher
(
ItemType
itemType
,
String
name
)
{
public
MetadataItemCondition
(
ItemType
itemType
,
String
name
)
{
this
(
itemType
,
name
,
null
,
null
,
null
,
null
,
null
);
}
public
ContainsItemMatcher
(
ItemType
itemType
,
String
name
,
String
type
,
Class
<?>
sourceType
,
String
description
,
Matcher
<?>
defaultValue
,
public
MetadataItemCondition
(
ItemType
itemType
,
String
name
,
String
type
,
Class
<?>
sourceType
,
String
description
,
Object
defaultValue
,
ItemDeprecation
deprecation
)
{
this
.
itemType
=
itemType
;
this
.
name
=
name
;
...
...
@@ -101,12 +100,33 @@ public final class ConfigurationMetadataMatchers {
this
.
description
=
description
;
this
.
defaultValue
=
defaultValue
;
this
.
deprecation
=
deprecation
;
describedAs
(
createDescription
());
}
private
String
createDescription
()
{
StringBuilder
description
=
new
StringBuilder
();
description
.
append
(
"an item named '"
+
this
.
name
+
"'"
);
if
(
this
.
type
!=
null
)
{
description
.
append
(
" with dataType:"
).
append
(
this
.
type
);
}
if
(
this
.
sourceType
!=
null
)
{
description
.
append
(
" with sourceType:"
).
append
(
this
.
sourceType
);
}
if
(
this
.
defaultValue
!=
null
)
{
description
.
append
(
" with defaultValue:"
).
append
(
this
.
defaultValue
);
}
if
(
this
.
description
!=
null
)
{
description
.
append
(
" with description:"
).
append
(
this
.
description
);
}
if
(
this
.
deprecation
!=
null
)
{
description
.
append
(
" with deprecation:"
).
append
(
this
.
deprecation
);
}
return
description
.
toString
();
}
@Override
public
boolean
matches
(
Object
item
)
{
ConfigurationMetadata
metadata
=
(
ConfigurationMetadata
)
item
;
ItemMetadata
itemMetadata
=
getFirstItemWithName
(
metadata
,
this
.
name
);
public
boolean
matches
(
ConfigurationMetadata
value
)
{
ItemMetadata
itemMetadata
=
getFirstItemWithName
(
value
,
this
.
name
);
if
(
itemMetadata
==
null
)
{
return
false
;
}
...
...
@@ -117,8 +137,8 @@ public final class ConfigurationMetadataMatchers {
&&
!
this
.
sourceType
.
getName
().
equals
(
itemMetadata
.
getSourceType
()))
{
return
false
;
}
if
(
this
.
defaultValue
!=
null
&&
!
this
.
defaultValue
.
matches
(
itemMetadata
.
getDefaultValue
()))
{
if
(
this
.
defaultValue
!=
null
&&
!
ObjectUtils
.
nullSafeEquals
(
this
.
defaultValue
,
itemMetadata
.
getDefaultValue
()))
{
return
false
;
}
if
(
this
.
description
!=
null
...
...
@@ -135,76 +155,41 @@ public final class ConfigurationMetadataMatchers {
return
true
;
}
@Override
public
void
describeMismatch
(
Object
item
,
Description
description
)
{
ConfigurationMetadata
metadata
=
(
ConfigurationMetadata
)
item
;
ItemMetadata
property
=
getFirstItemWithName
(
metadata
,
this
.
name
);
if
(
property
==
null
)
{
description
.
appendText
(
"missing "
+
this
.
itemType
.
toString
().
toLowerCase
()
+
" "
+
this
.
name
);
}
else
{
description
.
appendText
(
"was "
+
this
.
itemType
.
toString
().
toLowerCase
()
+
" "
)
.
appendValue
(
property
);
}
}
@Override
public
void
describeTo
(
Description
description
)
{
description
.
appendText
(
"metadata containing "
+
this
.
name
);
if
(
this
.
type
!=
null
)
{
description
.
appendText
(
" dataType "
).
appendValue
(
this
.
type
);
}
if
(
this
.
sourceType
!=
null
)
{
description
.
appendText
(
" sourceType "
).
appendValue
(
this
.
sourceType
);
}
if
(
this
.
defaultValue
!=
null
)
{
description
.
appendText
(
" defaultValue "
).
appendValue
(
this
.
defaultValue
);
}
if
(
this
.
description
!=
null
)
{
description
.
appendText
(
" description "
).
appendValue
(
this
.
description
);
}
if
(
this
.
deprecation
!=
null
)
{
description
.
appendText
(
" deprecation "
).
appendValue
(
this
.
deprecation
);
}
}
public
ContainsItemMatcher
ofType
(
Class
<?>
dataType
)
{
return
new
ContainsItemMatcher
(
this
.
itemType
,
this
.
name
,
dataType
.
getName
(),
public
MetadataItemCondition
ofType
(
Class
<?>
dataType
)
{
return
new
MetadataItemCondition
(
this
.
itemType
,
this
.
name
,
dataType
.
getName
(),
this
.
sourceType
,
this
.
description
,
this
.
defaultValue
,
this
.
deprecation
);
}
public
ContainsItemMatcher
ofType
(
String
dataType
)
{
return
new
ContainsItemMatcher
(
this
.
itemType
,
this
.
name
,
dataType
,
public
MetadataItemCondition
ofType
(
String
dataType
)
{
return
new
MetadataItemCondition
(
this
.
itemType
,
this
.
name
,
dataType
,
this
.
sourceType
,
this
.
description
,
this
.
defaultValue
,
this
.
deprecation
);
}
public
ContainsItemMatcher
fromSource
(
Class
<?>
sourceType
)
{
return
new
ContainsItemMatcher
(
this
.
itemType
,
this
.
name
,
this
.
type
,
public
MetadataItemCondition
fromSource
(
Class
<?>
sourceType
)
{
return
new
MetadataItemCondition
(
this
.
itemType
,
this
.
name
,
this
.
type
,
sourceType
,
this
.
description
,
this
.
defaultValue
,
this
.
deprecation
);
}
public
ContainsItemMatcher
withDescription
(
String
description
)
{
return
new
ContainsItemMatcher
(
this
.
itemType
,
this
.
name
,
this
.
type
,
public
MetadataItemCondition
withDescription
(
String
description
)
{
return
new
MetadataItemCondition
(
this
.
itemType
,
this
.
name
,
this
.
type
,
this
.
sourceType
,
description
,
this
.
defaultValue
,
this
.
deprecation
);
}
public
ContainsItemMatcher
withDefaultValue
(
Matcher
<?>
defaultValue
)
{
return
new
ContainsItemMatcher
(
this
.
itemType
,
this
.
name
,
this
.
type
,
public
MetadataItemCondition
withDefaultValue
(
Object
defaultValue
)
{
return
new
MetadataItemCondition
(
this
.
itemType
,
this
.
name
,
this
.
type
,
this
.
sourceType
,
this
.
description
,
defaultValue
,
this
.
deprecation
);
}
public
ContainsItemMatcher
withDeprecation
(
String
reason
,
String
replacement
)
{
return
new
ContainsItemMatcher
(
this
.
itemType
,
this
.
name
,
this
.
type
,
public
MetadataItemCondition
withDeprecation
(
String
reason
,
String
replacement
)
{
return
new
MetadataItemCondition
(
this
.
itemType
,
this
.
name
,
this
.
type
,
this
.
sourceType
,
this
.
description
,
this
.
defaultValue
,
new
ItemDeprecation
(
reason
,
replacement
));
}
public
ContainsItemMatcher
withNoDeprecation
()
{
return
new
ContainsItemMatcher
(
this
.
itemType
,
this
.
name
,
this
.
type
,
public
MetadataItemCondition
withNoDeprecation
()
{
return
new
MetadataItemCondition
(
this
.
itemType
,
this
.
name
,
this
.
type
,
this
.
sourceType
,
this
.
description
,
this
.
defaultValue
,
null
);
}
...
...
@@ -220,107 +205,105 @@ public final class ConfigurationMetadataMatchers {
}
public
static
class
ContainsHintMatcher
extends
BaseMatcher
<
ConfigurationMetadata
>
{
public
static
class
MetadataHintCondition
extends
Condition
<
ConfigurationMetadata
>
{
private
final
String
name
;
private
final
List
<
ValueHintMatcher
>
value
s
;
private
final
List
<
ItemHintValueCondition
>
valueCondition
s
;
private
final
List
<
ValueProviderMatcher
>
provider
s
;
private
final
List
<
ItemHintProviderCondition
>
providerCondition
s
;
public
ContainsHintMatcher
(
String
name
)
{
this
(
name
,
new
ArrayList
<
ValueHintMatcher
>(),
new
ArrayList
<
ValueProviderMatcher
>());
public
MetadataHintCondition
(
String
name
)
{
this
.
name
=
name
;
this
.
valueConditions
=
Collections
.
emptyList
();
this
.
providerConditions
=
Collections
.
emptyList
();
}
public
ContainsHintMatcher
(
String
name
,
List
<
ValueHintMatcher
>
values
,
List
<
ValueProviderMatcher
>
providers
)
{
public
MetadataHintCondition
(
String
name
,
List
<
ItemHintValueCondition
>
valueConditions
,
List
<
ItemHintProviderCondition
>
providerConditions
)
{
this
.
name
=
name
;
this
.
values
=
values
;
this
.
providers
=
providers
;
this
.
valueConditions
=
valueConditions
;
this
.
providerConditions
=
providerConditions
;
describedAs
(
createDescription
());
}
private
String
createDescription
()
{
StringBuilder
description
=
new
StringBuilder
();
description
.
append
(
"a hints name '"
+
this
.
name
+
"'"
);
if
(!
this
.
valueConditions
.
isEmpty
())
{
description
.
append
(
" with values:"
).
append
(
this
.
valueConditions
);
}
if
(!
this
.
providerConditions
.
isEmpty
())
{
description
.
append
(
" with providers:"
).
append
(
this
.
providerConditions
);
}
return
description
.
toString
();
}
@Override
public
boolean
matches
(
Object
item
)
{
ConfigurationMetadata
metadata
=
(
ConfigurationMetadata
)
item
;
public
boolean
matches
(
ConfigurationMetadata
metadata
)
{
ItemHint
itemHint
=
getFirstHintWithName
(
metadata
,
this
.
name
);
if
(
itemHint
==
null
)
{
return
false
;
}
for
(
ValueHintMatcher
value
:
this
.
values
)
{
if
(!
value
.
matches
(
itemHint
))
{
return
false
;
}
return
matches
(
itemHint
,
this
.
valueConditions
)
&&
matches
(
itemHint
,
this
.
providerConditions
);
}
for
(
ValueProviderMatcher
provider
:
this
.
providers
)
{
if
(!
provider
.
matches
(
itemHint
))
{
private
boolean
matches
(
ItemHint
itemHint
,
List
<?
extends
Condition
<
ItemHint
>>
conditions
)
{
for
(
Condition
<
ItemHint
>
condition
:
conditions
)
{
if
(!
condition
.
matches
(
itemHint
))
{
return
false
;
}
}
return
true
;
}
@Override
public
void
describeMismatch
(
Object
item
,
Description
description
)
{
ConfigurationMetadata
metadata
=
(
ConfigurationMetadata
)
item
;
ItemHint
itemHint
=
getFirstHintWithName
(
metadata
,
this
.
name
);
if
(
itemHint
==
null
)
{
description
.
appendText
(
"missing hint "
+
this
.
name
);
}
else
{
description
.
appendText
(
"was hint "
).
appendValue
(
itemHint
);
}
}
@Override
public
void
describeTo
(
Description
description
)
{
description
.
appendText
(
"hints for "
+
this
.
name
);
if
(
this
.
values
!=
null
)
{
description
.
appendText
(
" values "
).
appendValue
(
this
.
values
);
private
ItemHint
getFirstHintWithName
(
ConfigurationMetadata
metadata
,
String
name
)
{
for
(
ItemHint
hint
:
metadata
.
getHints
())
{
if
(
name
.
equals
(
hint
.
getName
()))
{
return
hint
;
}
if
(
this
.
providers
!=
null
)
{
description
.
appendText
(
" providers "
).
appendValue
(
this
.
providers
);
}
return
null
;
}
public
ContainsHintMatcher
withValue
(
int
index
,
Object
value
,
public
MetadataHintCondition
withValue
(
int
index
,
Object
value
,
String
description
)
{
List
<
ValueHintMatcher
>
values
=
new
ArrayList
<
ValueHintMatcher
>(
this
.
values
);
values
.
add
(
new
ValueHintMatcher
(
index
,
value
,
description
));
return
new
ContainsHintMatcher
(
this
.
name
,
values
,
this
.
providers
);
return
new
MetadataHintCondition
(
this
.
name
,
add
(
this
.
valueConditions
,
new
ItemHintValueCondition
(
index
,
value
,
description
)),
this
.
providerConditions
);
}
public
ContainsHintMatcher
withProvider
(
int
index
,
String
provider
,
Map
<
String
,
Object
>
parameters
)
{
List
<
ValueProviderMatcher
>
providers
=
new
ArrayList
<
ValueProviderMatcher
>(
this
.
providers
);
providers
.
add
(
new
ValueProviderMatcher
(
index
,
provider
,
parameters
));
return
new
ContainsHintMatcher
(
this
.
name
,
this
.
values
,
providers
);
public
MetadataHintCondition
withProvider
(
String
provider
)
{
return
withProvider
(
this
.
providerConditions
.
size
(),
provider
,
null
);
}
public
ContainsHintMatcher
withProvider
(
String
provider
,
String
key
,
public
MetadataHintCondition
withProvider
(
String
provider
,
String
key
,
Object
value
)
{
return
withProvider
(
this
.
providers
.
size
(),
provider
,
return
withProvider
(
this
.
provider
Condition
s
.
size
(),
provider
,
Collections
.
singletonMap
(
key
,
value
));
}
public
ContainsHintMatcher
withProvider
(
String
provider
)
{
return
withProvider
(
this
.
providers
.
size
(),
provider
,
null
);
public
MetadataHintCondition
withProvider
(
int
index
,
String
provider
,
Map
<
String
,
Object
>
parameters
)
{
return
new
MetadataHintCondition
(
this
.
name
,
this
.
valueConditions
,
add
(
this
.
providerConditions
,
new
ItemHintProviderCondition
(
index
,
provider
,
parameters
)));
}
private
ItemHint
getFirstHintWithName
(
ConfigurationMetadata
metadata
,
String
name
)
{
for
(
ItemHint
hint
:
metadata
.
getHints
())
{
if
(
name
.
equals
(
hint
.
getName
()))
{
return
hint
;
}
}
return
null
;
private
<
T
>
List
<
T
>
add
(
List
<
T
>
items
,
T
item
)
{
List
<
T
>
result
=
new
ArrayList
<
T
>(
items
);
result
.
add
(
item
);
return
result
;
}
}
p
ublic
static
class
ValueHintMatcher
extends
BaseMatcher
<
ItemHint
>
{
p
rivate
static
class
ItemHintValueCondition
extends
Condition
<
ItemHint
>
{
private
final
int
index
;
...
...
@@ -328,19 +311,31 @@ public final class ConfigurationMetadataMatchers {
private
final
String
description
;
public
ValueHintMatcher
(
int
index
,
Object
value
,
String
description
)
{
ItemHintValueCondition
(
int
index
,
Object
value
,
String
description
)
{
this
.
index
=
index
;
this
.
value
=
value
;
this
.
description
=
description
;
describedAs
(
createDescription
());
}
private
String
createDescription
()
{
StringBuilder
description
=
new
StringBuilder
();
description
.
append
(
"value hint at index '"
+
this
.
index
+
"'"
);
if
(
this
.
value
!=
null
)
{
description
.
append
(
" with value:"
).
append
(
this
.
value
);
}
if
(
this
.
description
!=
null
)
{
description
.
append
(
" with description:"
).
append
(
this
.
description
);
}
return
description
.
toString
();
}
@Override
public
boolean
matches
(
Object
item
)
{
ItemHint
hint
=
(
ItemHint
)
item
;
if
(
this
.
index
+
1
>
hint
.
getValues
().
size
())
{
public
boolean
matches
(
ItemHint
value
)
{
if
(
this
.
index
+
1
>
value
.
getValues
().
size
())
{
return
false
;
}
ItemHint
.
ValueHint
valueHint
=
hint
.
getValues
().
get
(
this
.
index
);
ItemHint
.
ValueHint
valueHint
=
value
.
getValues
().
get
(
this
.
index
);
if
(
this
.
value
!=
null
&&
!
this
.
value
.
equals
(
valueHint
.
getValue
()))
{
return
false
;
}
...
...
@@ -351,20 +346,9 @@ public final class ConfigurationMetadataMatchers {
return
true
;
}
@Override
public
void
describeTo
(
Description
description
)
{
description
.
appendText
(
"value hint at index '"
+
this
.
index
+
"'"
);
if
(
this
.
value
!=
null
)
{
description
.
appendText
(
" value "
).
appendValue
(
this
.
value
);
}
if
(
this
.
description
!=
null
)
{
description
.
appendText
(
" description "
).
appendValue
(
this
.
description
);
}
}
}
p
ublic
static
class
ValueProviderMatcher
extends
BaseMatcher
<
ItemHint
>
{
p
rivate
static
class
ItemHintProviderCondition
extends
Condition
<
ItemHint
>
{
private
final
int
index
;
...
...
@@ -372,16 +356,28 @@ public final class ConfigurationMetadataMatchers {
private
final
Map
<
String
,
Object
>
parameters
;
public
ValueProviderMatcher
(
int
index
,
String
name
,
ItemHintProviderCondition
(
int
index
,
String
name
,
Map
<
String
,
Object
>
parameters
)
{
this
.
index
=
index
;
this
.
name
=
name
;
this
.
parameters
=
parameters
;
describedAs
(
createDescription
());
}
public
String
createDescription
()
{
StringBuilder
description
=
new
StringBuilder
();
description
.
append
(
"value provider"
);
if
(
this
.
name
!=
null
)
{
description
.
append
(
" with name:"
).
append
(
this
.
name
);
}
if
(
this
.
parameters
!=
null
)
{
description
.
append
(
" with parameters:"
).
append
(
this
.
parameters
);
}
return
description
.
toString
();
}
@Override
public
boolean
matches
(
Object
item
)
{
ItemHint
hint
=
(
ItemHint
)
item
;
public
boolean
matches
(
ItemHint
hint
)
{
if
(
this
.
index
+
1
>
hint
.
getProviders
().
size
())
{
return
false
;
}
...
...
@@ -400,17 +396,6 @@ public final class ConfigurationMetadataMatchers {
return
true
;
}
@Override
public
void
describeTo
(
Description
description
)
{
description
.
appendText
(
"value provider "
);
if
(
this
.
name
!=
null
)
{
description
.
appendText
(
" name "
).
appendValue
(
this
.
name
);
}
if
(
this
.
parameters
!=
null
)
{
description
.
appendText
(
" parameters "
).
appendValue
(
this
.
parameters
);
}
}
}
}
spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/TestConfigurationMetadataAnnotationProcessor.java
View file @
00cfe1d0
...
...
@@ -28,6 +28,8 @@ import org.springframework.boot.configurationprocessor.metadata.ConfigurationMet
import
org.springframework.boot.configurationprocessor.metadata.JsonMarshaller
;
/**
* Test {@link ConfigurationMetadataAnnotationProcessor}.
*
* @author Stephane Nicoll
* @author Phillip Webb
* @author Andy Wilkinson
...
...
spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/fieldvalues/AbstractFieldValuesProcessorTests.java
View file @
00cfe1d0
...
...
@@ -29,7 +29,6 @@ import javax.lang.model.SourceVersion;
import
javax.lang.model.element.Element
;
import
javax.lang.model.element.TypeElement
;
import
org.hamcrest.Matcher
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.rules.TemporaryFolder
;
...
...
@@ -37,9 +36,7 @@ import org.junit.rules.TemporaryFolder;
import
org.springframework.boot.configurationprocessor.TestCompiler
;
import
org.springframework.boot.configurationsample.fieldvalues.FieldValues
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
nullValue
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Abstract base class for {@link FieldValuesParser} tests.
...
...
@@ -60,43 +57,37 @@ public abstract class AbstractFieldValuesProcessorTests {
TestCompiler
compiler
=
new
TestCompiler
(
this
.
temporaryFolder
);
compiler
.
getTask
(
FieldValues
.
class
).
call
(
processor
);
Map
<
String
,
Object
>
values
=
processor
.
getValues
();
assertThat
(
values
.
get
(
"string"
),
equalToObject
(
"1"
));
assertThat
(
values
.
get
(
"stringNone"
),
nullValue
());
assertThat
(
values
.
get
(
"stringConst"
),
equalToObject
(
"c"
));
assertThat
(
values
.
get
(
"bool"
),
equalToObject
(
true
));
assertThat
(
values
.
get
(
"boolNone"
),
equalToObject
(
false
));
assertThat
(
values
.
get
(
"boolConst"
),
equalToObject
(
true
));
assertThat
(
values
.
get
(
"boolObject"
),
equalToObject
(
true
));
assertThat
(
values
.
get
(
"boolObjectNone"
),
nullValue
());
assertThat
(
values
.
get
(
"boolObjectConst"
),
equalToObject
(
true
));
assertThat
(
values
.
get
(
"integer"
),
equalToObject
(
1
));
assertThat
(
values
.
get
(
"integerNone"
),
equalToObject
(
0
));
assertThat
(
values
.
get
(
"integerConst"
),
equalToObject
(
2
));
assertThat
(
values
.
get
(
"integerObject"
),
equalToObject
(
3
));
assertThat
(
values
.
get
(
"integerObjectNone"
),
nullValue
());
assertThat
(
values
.
get
(
"integerObjectConst"
),
equalToObject
(
4
));
assertThat
(
values
.
get
(
"charset"
),
equalToObject
(
"US-ASCII"
));
assertThat
(
values
.
get
(
"charsetConst"
),
equalToObject
(
"UTF-8"
));
assertThat
(
values
.
get
(
"mimeType"
),
equalToObject
(
"text/html"
));
assertThat
(
values
.
get
(
"mimeTypeConst"
),
equalToObject
(
"text/plain"
));
assertThat
(
values
.
get
(
"object"
),
equalToObject
(
123
));
assertThat
(
values
.
get
(
"objectNone"
),
nullValue
());
assertThat
(
values
.
get
(
"objectConst"
),
equalToObject
(
"c"
));
assertThat
(
values
.
get
(
"objectInstance"
),
nullValue
());
assertThat
(
values
.
get
(
"stringArray"
),
equalToObject
(
new
Object
[]
{
"FOO"
,
"BAR"
}));
assertThat
(
values
.
get
(
"stringArrayNone"
),
nullValue
());
assertThat
(
values
.
get
(
"stringEmptyArray"
),
equalToObject
(
new
Object
[
0
]));
assertThat
(
values
.
get
(
"stringArrayConst"
),
equalToObject
(
new
Object
[]
{
"OK"
,
"KO"
}));
assertThat
(
values
.
get
(
"stringArrayConstElements"
),
equalToObject
(
new
Object
[]
{
"c"
}));
assertThat
(
values
.
get
(
"integerArray"
),
equalToObject
(
new
Object
[]
{
42
,
24
}));
assertThat
(
values
.
get
(
"unknownArray"
),
nullValue
());
}
private
Matcher
<
Object
>
equalToObject
(
Object
object
)
{
return
equalTo
(
object
);
assertThat
(
values
.
get
(
"string"
)).
isEqualTo
(
"1"
);
assertThat
(
values
.
get
(
"stringNone"
)).
isNull
();
assertThat
(
values
.
get
(
"stringConst"
)).
isEqualTo
(
"c"
);
assertThat
(
values
.
get
(
"bool"
)).
isEqualTo
(
true
);
assertThat
(
values
.
get
(
"boolNone"
)).
isEqualTo
(
false
);
assertThat
(
values
.
get
(
"boolConst"
)).
isEqualTo
(
true
);
assertThat
(
values
.
get
(
"boolObject"
)).
isEqualTo
(
true
);
assertThat
(
values
.
get
(
"boolObjectNone"
)).
isNull
();
assertThat
(
values
.
get
(
"boolObjectConst"
)).
isEqualTo
(
true
);
assertThat
(
values
.
get
(
"integer"
)).
isEqualTo
(
1
);
assertThat
(
values
.
get
(
"integerNone"
)).
isEqualTo
(
0
);
assertThat
(
values
.
get
(
"integerConst"
)).
isEqualTo
(
2
);
assertThat
(
values
.
get
(
"integerObject"
)).
isEqualTo
(
3
);
assertThat
(
values
.
get
(
"integerObjectNone"
)).
isNull
();
assertThat
(
values
.
get
(
"integerObjectConst"
)).
isEqualTo
(
4
);
assertThat
(
values
.
get
(
"charset"
)).
isEqualTo
(
"US-ASCII"
);
assertThat
(
values
.
get
(
"charsetConst"
)).
isEqualTo
(
"UTF-8"
);
assertThat
(
values
.
get
(
"mimeType"
)).
isEqualTo
(
"text/html"
);
assertThat
(
values
.
get
(
"mimeTypeConst"
)).
isEqualTo
(
"text/plain"
);
assertThat
(
values
.
get
(
"object"
)).
isEqualTo
(
123
);
assertThat
(
values
.
get
(
"objectNone"
)).
isNull
();
assertThat
(
values
.
get
(
"objectConst"
)).
isEqualTo
(
"c"
);
assertThat
(
values
.
get
(
"objectInstance"
)).
isNull
();
assertThat
(
values
.
get
(
"stringArray"
)).
isEqualTo
(
new
Object
[]
{
"FOO"
,
"BAR"
});
assertThat
(
values
.
get
(
"stringArrayNone"
)).
isNull
();
assertThat
(
values
.
get
(
"stringEmptyArray"
)).
isEqualTo
(
new
Object
[
0
]);
assertThat
(
values
.
get
(
"stringArrayConst"
)).
isEqualTo
(
new
Object
[]
{
"OK"
,
"KO"
});
assertThat
(
values
.
get
(
"stringArrayConstElements"
))
.
isEqualTo
(
new
Object
[]
{
"c"
});
assertThat
(
values
.
get
(
"integerArray"
)).
isEqualTo
(
new
Object
[]
{
42
,
24
});
assertThat
(
values
.
get
(
"unknownArray"
)).
isNull
();
}
@SupportedAnnotationTypes
({
...
...
spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadataTests.java
View file @
00cfe1d0
...
...
@@ -18,8 +18,7 @@ package org.springframework.boot.configurationprocessor.metadata;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link ConfigurationMetadata}.
...
...
@@ -30,43 +29,44 @@ public class ConfigurationMetadataTests {
@Test
public
void
toDashedCaseCamelCase
()
{
assertThat
(
toDashedCase
(
"simpleCamelCase"
)
,
is
(
"simple-camel-case"
)
);
assertThat
(
toDashedCase
(
"simpleCamelCase"
)
).
isEqualTo
(
"simple-camel-case"
);
}
@Test
public
void
toDashedCaseWordsUnderscore
()
{
assertThat
(
toDashedCase
(
"Word_With_underscore"
),
is
(
"word_with_underscore"
));
assertThat
(
toDashedCase
(
"Word_With_underscore"
))
.
isEqualTo
(
"word_with_underscore"
);
}
@Test
public
void
toDashedCaseWordsSeveralUnderscores
()
{
assertThat
(
toDashedCase
(
"Word___With__underscore"
)
,
is
(
"word___with__underscore"
)
);
assertThat
(
toDashedCase
(
"Word___With__underscore"
)
)
.
isEqualTo
(
"word___with__underscore"
);
}
@Test
public
void
toDashedCaseLowerCaseUnderscore
()
{
assertThat
(
toDashedCase
(
"lower_underscore"
)
,
is
(
"lower_underscore"
)
);
assertThat
(
toDashedCase
(
"lower_underscore"
)
).
isEqualTo
(
"lower_underscore"
);
}
@Test
public
void
toDashedCaseUpperUnderscore
()
{
assertThat
(
toDashedCase
(
"UPPER_UNDERSCORE"
)
,
is
(
"upper_underscore"
)
);
assertThat
(
toDashedCase
(
"UPPER_UNDERSCORE"
)
).
isEqualTo
(
"upper_underscore"
);
}
@Test
public
void
toDashedCaseMultipleUnderscores
()
{
assertThat
(
toDashedCase
(
"super___crazy"
)
,
is
(
"super___crazy"
)
);
assertThat
(
toDashedCase
(
"super___crazy"
)
).
isEqualTo
(
"super___crazy"
);
}
@Test
public
void
toDashedCaseUppercase
()
{
assertThat
(
toDashedCase
(
"UPPERCASE"
)
,
is
(
"uppercase"
)
);
assertThat
(
toDashedCase
(
"UPPERCASE"
)
).
isEqualTo
(
"uppercase"
);
}
@Test
public
void
toDashedCaseLowercase
()
{
assertThat
(
toDashedCase
(
"lowercase"
)
,
is
(
"lowercase"
)
);
assertThat
(
toDashedCase
(
"lowercase"
)
).
isEqualTo
(
"lowercase"
);
}
private
String
toDashedCase
(
String
name
)
{
...
...
spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/metadata/JsonMarshallerTests.java
View file @
00cfe1d0
...
...
@@ -25,11 +25,9 @@ import java.util.Collections;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
springframework
.
boot
.
configurationprocessor
.
ConfigurationMetadataMatchers
.
containsGroup
;
import
static
org
.
springframework
.
boot
.
configurationprocessor
.
ConfigurationMetadataMatchers
.
containsHint
;
import
static
org
.
springframework
.
boot
.
configurationprocessor
.
ConfigurationMetadataMatchers
.
containsProperty
;
import
org.springframework.boot.configurationprocessor.Metadata
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link JsonMarshaller}.
...
...
@@ -70,22 +68,21 @@ public class JsonMarshallerTests {
marshaller
.
write
(
metadata
,
outputStream
);
ConfigurationMetadata
read
=
marshaller
.
read
(
new
ByteArrayInputStream
(
outputStream
.
toByteArray
()));
assertThat
(
read
,
containsProperty
(
"a.b"
,
StringBuffer
.
class
).
fromSource
(
InputStream
.
class
)
.
withDescription
(
"desc"
).
withDefaultValue
(
is
(
"x"
))
.
withDeprecation
(
"Deprecation comment"
,
"b.c.d"
));
assertThat
(
read
,
containsProperty
(
"b.c.d"
));
assertThat
(
read
,
containsProperty
(
"c"
).
withDefaultValue
(
is
(
123
)));
assertThat
(
read
,
containsProperty
(
"d"
).
withDefaultValue
(
is
(
true
)));
assertThat
(
read
,
containsProperty
(
"e"
).
withDefaultValue
(
is
(
new
String
[]
{
"y"
,
"n"
})));
assertThat
(
read
,
containsProperty
(
"f"
)
.
withDefaultValue
(
is
(
new
boolean
[]
{
true
,
false
})));
assertThat
(
read
,
containsGroup
(
"d"
));
assertThat
(
read
,
containsHint
(
"a.b"
));
assertThat
(
read
,
containsHint
(
"c"
).
withValue
(
0
,
123
,
"hey"
).
withValue
(
1
,
456
,
null
));
assertThat
(
read
,
containsHint
(
"d"
).
withProvider
(
"first"
,
"target"
,
"foo"
)
assertThat
(
read
).
has
(
Metadata
.
withProperty
(
"a.b"
,
StringBuffer
.
class
)
.
fromSource
(
InputStream
.
class
).
withDescription
(
"desc"
)
.
withDefaultValue
(
"x"
).
withDeprecation
(
"Deprecation comment"
,
"b.c.d"
));
assertThat
(
read
).
has
(
Metadata
.
withProperty
(
"b.c.d"
));
assertThat
(
read
).
has
(
Metadata
.
withProperty
(
"c"
).
withDefaultValue
(
123
));
assertThat
(
read
).
has
(
Metadata
.
withProperty
(
"d"
).
withDefaultValue
(
true
));
assertThat
(
read
).
has
(
Metadata
.
withProperty
(
"e"
).
withDefaultValue
(
new
String
[]
{
"y"
,
"n"
}));
assertThat
(
read
).
has
(
Metadata
.
withProperty
(
"f"
)
.
withDefaultValue
(
new
Object
[]
{
true
,
false
}));
assertThat
(
read
).
has
(
Metadata
.
withGroup
(
"d"
));
assertThat
(
read
).
has
(
Metadata
.
withHint
(
"a.b"
));
assertThat
(
read
).
has
(
Metadata
.
withHint
(
"c"
).
withValue
(
0
,
123
,
"hey"
).
withValue
(
1
,
456
,
null
));
assertThat
(
read
).
has
(
Metadata
.
withHint
(
"d"
).
withProvider
(
"first"
,
"target"
,
"foo"
)
.
withProvider
(
"second"
));
}
...
...
spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/DefaultLaunchScriptTests.java
View file @
00cfe1d0
...
...
@@ -26,9 +26,7 @@ import org.junit.rules.TemporaryFolder;
import
org.springframework.util.FileCopyUtils
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link DefaultLaunchScript}.
...
...
@@ -45,7 +43,7 @@ public class DefaultLaunchScriptTests {
public
void
loadsDefaultScript
()
throws
Exception
{
DefaultLaunchScript
script
=
new
DefaultLaunchScript
(
null
,
null
);
String
content
=
new
String
(
script
.
toByteArray
());
assertThat
(
content
,
containsString
(
"Spring Boot Startup Script"
)
);
assertThat
(
content
).
contains
(
"Spring Boot Startup Script"
);
}
@Test
...
...
@@ -82,14 +80,14 @@ public class DefaultLaunchScriptTests {
public
void
defaultForUseStartStopDaemonIsTrue
()
throws
Exception
{
DefaultLaunchScript
script
=
new
DefaultLaunchScript
(
null
,
null
);
String
content
=
new
String
(
script
.
toByteArray
());
assertThat
(
content
,
containsString
(
"USE_START_STOP_DAEMON=\"true\""
)
);
assertThat
(
content
).
contains
(
"USE_START_STOP_DAEMON=\"true\""
);
}
@Test
public
void
defaultForModeIsAuto
()
throws
Exception
{
DefaultLaunchScript
script
=
new
DefaultLaunchScript
(
null
,
null
);
String
content
=
new
String
(
script
.
toByteArray
());
assertThat
(
content
,
containsString
(
"MODE=\"auto\""
)
);
assertThat
(
content
).
contains
(
"MODE=\"auto\""
);
}
@Test
...
...
@@ -98,7 +96,7 @@ public class DefaultLaunchScriptTests {
FileCopyUtils
.
copy
(
"ABC"
.
getBytes
(),
file
);
DefaultLaunchScript
script
=
new
DefaultLaunchScript
(
file
,
null
);
String
content
=
new
String
(
script
.
toByteArray
());
assertThat
(
content
,
equalTo
(
"ABC"
)
);
assertThat
(
content
).
isEqualTo
(
"ABC"
);
}
@Test
...
...
@@ -108,7 +106,7 @@ public class DefaultLaunchScriptTests {
DefaultLaunchScript
script
=
new
DefaultLaunchScript
(
file
,
createProperties
(
"a:e"
,
"b:o"
));
String
content
=
new
String
(
script
.
toByteArray
());
assertThat
(
content
,
equalTo
(
"hello"
)
);
assertThat
(
content
).
isEqualTo
(
"hello"
);
}
@Test
...
...
@@ -118,7 +116,7 @@ public class DefaultLaunchScriptTests {
DefaultLaunchScript
script
=
new
DefaultLaunchScript
(
file
,
createProperties
(
"a:e"
,
"b:o"
));
String
content
=
new
String
(
script
.
toByteArray
());
assertThat
(
content
,
equalTo
(
"hel\nlo"
)
);
assertThat
(
content
).
isEqualTo
(
"hel\nlo"
);
}
@Test
...
...
@@ -127,7 +125,7 @@ public class DefaultLaunchScriptTests {
FileCopyUtils
.
copy
(
"h{{a:e}}ll{{b:o}}"
.
getBytes
(),
file
);
DefaultLaunchScript
script
=
new
DefaultLaunchScript
(
file
,
null
);
String
content
=
new
String
(
script
.
toByteArray
());
assertThat
(
content
,
equalTo
(
"hello"
)
);
assertThat
(
content
).
isEqualTo
(
"hello"
);
}
@Test
...
...
@@ -137,7 +135,7 @@ public class DefaultLaunchScriptTests {
DefaultLaunchScript
script
=
new
DefaultLaunchScript
(
file
,
createProperties
(
"a:a"
));
String
content
=
new
String
(
script
.
toByteArray
());
assertThat
(
content
,
equalTo
(
"hallo"
)
);
assertThat
(
content
).
isEqualTo
(
"hallo"
);
}
@Test
...
...
@@ -146,14 +144,14 @@ public class DefaultLaunchScriptTests {
FileCopyUtils
.
copy
(
"h{{a}}ll{{b}}"
.
getBytes
(),
file
);
DefaultLaunchScript
script
=
new
DefaultLaunchScript
(
file
,
null
);
String
content
=
new
String
(
script
.
toByteArray
());
assertThat
(
content
,
equalTo
(
"h{{a}}ll{{b}}"
)
);
assertThat
(
content
).
isEqualTo
(
"h{{a}}ll{{b}}"
);
}
private
void
assertThatPlaceholderCanBeReplaced
(
String
placeholder
)
throws
Exception
{
DefaultLaunchScript
script
=
new
DefaultLaunchScript
(
null
,
createProperties
(
placeholder
+
":__test__"
));
String
content
=
new
String
(
script
.
toByteArray
());
assertThat
(
content
,
containsString
(
"__test__"
)
);
assertThat
(
content
).
contains
(
"__test__"
);
}
private
Map
<?,
?>
createProperties
(
String
...
pairs
)
{
...
...
spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/FileUtilsTests.java
View file @
00cfe1d0
...
...
@@ -28,10 +28,7 @@ import org.junit.rules.TemporaryFolder;
import
org.springframework.util.FileSystemUtils
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link FileUtils}.
...
...
@@ -65,31 +62,31 @@ public class FileUtilsTests {
new
File
(
this
.
originDirectory
,
"logback.xml"
).
createNewFile
();
FileUtils
.
removeDuplicatesFromOutputDirectory
(
this
.
outputDirectory
,
this
.
originDirectory
);
assert
False
(
file
.
exists
()
);
assert
That
(
file
.
exists
()).
isFalse
(
);
}
@Test
public
void
nestedDuplicateFile
()
throws
IOException
{
assertT
rue
(
new
File
(
this
.
outputDirectory
,
"sub"
).
mkdirs
()
);
assertT
rue
(
new
File
(
this
.
originDirectory
,
"sub"
).
mkdirs
()
);
assertT
hat
(
new
File
(
this
.
outputDirectory
,
"sub"
).
mkdirs
()).
isTrue
(
);
assertT
hat
(
new
File
(
this
.
originDirectory
,
"sub"
).
mkdirs
()).
isTrue
(
);
File
file
=
new
File
(
this
.
outputDirectory
,
"sub/logback.xml"
);
file
.
createNewFile
();
new
File
(
this
.
originDirectory
,
"sub/logback.xml"
).
createNewFile
();
FileUtils
.
removeDuplicatesFromOutputDirectory
(
this
.
outputDirectory
,
this
.
originDirectory
);
assert
False
(
file
.
exists
()
);
assert
That
(
file
.
exists
()).
isFalse
(
);
}
@Test
public
void
nestedNonDuplicateFile
()
throws
IOException
{
assertT
rue
(
new
File
(
this
.
outputDirectory
,
"sub"
).
mkdirs
()
);
assertT
rue
(
new
File
(
this
.
originDirectory
,
"sub"
).
mkdirs
()
);
assertT
hat
(
new
File
(
this
.
outputDirectory
,
"sub"
).
mkdirs
()).
isTrue
(
);
assertT
hat
(
new
File
(
this
.
originDirectory
,
"sub"
).
mkdirs
()).
isTrue
(
);
File
file
=
new
File
(
this
.
outputDirectory
,
"sub/logback.xml"
);
file
.
createNewFile
();
new
File
(
this
.
originDirectory
,
"sub/different.xml"
).
createNewFile
();
FileUtils
.
removeDuplicatesFromOutputDirectory
(
this
.
outputDirectory
,
this
.
originDirectory
);
assertT
rue
(
file
.
exists
()
);
assertT
hat
(
file
.
exists
()).
isTrue
(
);
}
@Test
...
...
@@ -99,7 +96,7 @@ public class FileUtilsTests {
new
File
(
this
.
originDirectory
,
"different.xml"
).
createNewFile
();
FileUtils
.
removeDuplicatesFromOutputDirectory
(
this
.
outputDirectory
,
this
.
originDirectory
);
assertT
rue
(
file
.
exists
()
);
assertT
hat
(
file
.
exists
()).
isTrue
(
);
}
@Test
...
...
@@ -112,8 +109,8 @@ public class FileUtilsTests {
finally
{
outputStream
.
close
();
}
assertThat
(
FileUtils
.
sha1Hash
(
file
)
,
equalTo
(
"7037807198c22a7d2b0807371d763779a84fdfcf"
)
);
assertThat
(
FileUtils
.
sha1Hash
(
file
)
)
.
isEqualTo
(
"7037807198c22a7d2b0807371d763779a84fdfcf"
);
}
}
spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/JvmUtilsTests.java
View file @
00cfe1d0
...
...
@@ -21,9 +21,7 @@ import java.net.URL;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
Matchers
.
endsWith
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link JvmUtils}.
...
...
@@ -36,8 +34,8 @@ public class JvmUtilsTests {
public
void
getToolsJar
()
throws
Exception
{
URL
jarUrl
=
JvmUtils
.
getToolsJarUrl
();
// System.out.println(jarUrl);
assertThat
(
jarUrl
.
toString
()
,
endsWith
(
".jar"
)
);
assertThat
(
new
File
(
jarUrl
.
toURI
()).
exists
()
,
equalTo
(
true
)
);
assertThat
(
jarUrl
.
toString
()
).
endsWith
(
".jar"
);
assertThat
(
new
File
(
jarUrl
.
toURI
()).
exists
()
).
isTrue
(
);
}
}
spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/LayoutsTests.java
View file @
00cfe1d0
...
...
@@ -22,10 +22,7 @@ import org.junit.Rule;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
instanceOf
;
import
static
org
.
hamcrest
.
Matchers
.
nullValue
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link Layouts}.
...
...
@@ -40,18 +37,20 @@ public class LayoutsTests {
@Test
public
void
jarFile
()
throws
Exception
{
assertThat
(
Layouts
.
forFile
(
new
File
(
"test.jar"
)),
instanceOf
(
Layouts
.
Jar
.
class
));
assertThat
(
Layouts
.
forFile
(
new
File
(
"test.JAR"
)),
instanceOf
(
Layouts
.
Jar
.
class
));
assertThat
(
Layouts
.
forFile
(
new
File
(
"test.jAr"
)),
instanceOf
(
Layouts
.
Jar
.
class
));
assertThat
(
Layouts
.
forFile
(
new
File
(
"te.st.jar"
)),
instanceOf
(
Layouts
.
Jar
.
class
));
assertThat
(
Layouts
.
forFile
(
new
File
(
"test.jar"
))).
isInstanceOf
(
Layouts
.
Jar
.
class
);
assertThat
(
Layouts
.
forFile
(
new
File
(
"test.JAR"
))).
isInstanceOf
(
Layouts
.
Jar
.
class
);
assertThat
(
Layouts
.
forFile
(
new
File
(
"test.jAr"
))).
isInstanceOf
(
Layouts
.
Jar
.
class
);
assertThat
(
Layouts
.
forFile
(
new
File
(
"te.st.jar"
)))
.
isInstanceOf
(
Layouts
.
Jar
.
class
);
}
@Test
public
void
warFile
()
throws
Exception
{
assertThat
(
Layouts
.
forFile
(
new
File
(
"test.war"
)),
instanceOf
(
Layouts
.
War
.
class
));
assertThat
(
Layouts
.
forFile
(
new
File
(
"test.WAR"
)),
instanceOf
(
Layouts
.
War
.
class
));
assertThat
(
Layouts
.
forFile
(
new
File
(
"test.wAr"
)),
instanceOf
(
Layouts
.
War
.
class
));
assertThat
(
Layouts
.
forFile
(
new
File
(
"te.st.war"
)),
instanceOf
(
Layouts
.
War
.
class
));
assertThat
(
Layouts
.
forFile
(
new
File
(
"test.war"
))).
isInstanceOf
(
Layouts
.
War
.
class
);
assertThat
(
Layouts
.
forFile
(
new
File
(
"test.WAR"
))).
isInstanceOf
(
Layouts
.
War
.
class
);
assertThat
(
Layouts
.
forFile
(
new
File
(
"test.wAr"
))).
isInstanceOf
(
Layouts
.
War
.
class
);
assertThat
(
Layouts
.
forFile
(
new
File
(
"te.st.war"
)))
.
isInstanceOf
(
Layouts
.
War
.
class
);
}
@Test
...
...
@@ -64,40 +63,40 @@ public class LayoutsTests {
@Test
public
void
jarLayout
()
throws
Exception
{
Layout
layout
=
new
Layouts
.
Jar
();
assertThat
(
layout
.
getLibraryDestination
(
"lib.jar"
,
LibraryScope
.
COMPILE
)
,
equalTo
(
"lib/"
)
);
assertThat
(
layout
.
getLibraryDestination
(
"lib.jar"
,
LibraryScope
.
CUSTOM
)
,
equalTo
(
"lib/"
)
);
assertThat
(
layout
.
getLibraryDestination
(
"lib.jar"
,
LibraryScope
.
PROVIDED
)
,
equalTo
(
"lib/"
)
);
assertThat
(
layout
.
getLibraryDestination
(
"lib.jar"
,
LibraryScope
.
RUNTIME
)
,
equalTo
(
"lib/"
)
);
assertThat
(
layout
.
getLibraryDestination
(
"lib.jar"
,
LibraryScope
.
COMPILE
)
)
.
isEqualTo
(
"lib/"
);
assertThat
(
layout
.
getLibraryDestination
(
"lib.jar"
,
LibraryScope
.
CUSTOM
)
)
.
isEqualTo
(
"lib/"
);
assertThat
(
layout
.
getLibraryDestination
(
"lib.jar"
,
LibraryScope
.
PROVIDED
)
)
.
isEqualTo
(
"lib/"
);
assertThat
(
layout
.
getLibraryDestination
(
"lib.jar"
,
LibraryScope
.
RUNTIME
)
)
.
isEqualTo
(
"lib/"
);
}
@Test
public
void
warLayout
()
throws
Exception
{
Layout
layout
=
new
Layouts
.
War
();
assertThat
(
layout
.
getLibraryDestination
(
"lib.jar"
,
LibraryScope
.
COMPILE
)
,
equalTo
(
"WEB-INF/lib/"
)
);
assertThat
(
layout
.
getLibraryDestination
(
"lib.jar"
,
LibraryScope
.
CUSTOM
)
,
equalTo
(
"WEB-INF/lib/"
)
);
assertThat
(
layout
.
getLibraryDestination
(
"lib.jar"
,
LibraryScope
.
PROVIDED
)
,
equalTo
(
"WEB-INF/lib-provided/"
)
);
assertThat
(
layout
.
getLibraryDestination
(
"lib.jar"
,
LibraryScope
.
RUNTIME
)
,
equalTo
(
"WEB-INF/lib/"
)
);
assertThat
(
layout
.
getLibraryDestination
(
"lib.jar"
,
LibraryScope
.
COMPILE
)
)
.
isEqualTo
(
"WEB-INF/lib/"
);
assertThat
(
layout
.
getLibraryDestination
(
"lib.jar"
,
LibraryScope
.
CUSTOM
)
)
.
isEqualTo
(
"WEB-INF/lib/"
);
assertThat
(
layout
.
getLibraryDestination
(
"lib.jar"
,
LibraryScope
.
PROVIDED
)
)
.
isEqualTo
(
"WEB-INF/lib-provided/"
);
assertThat
(
layout
.
getLibraryDestination
(
"lib.jar"
,
LibraryScope
.
RUNTIME
)
)
.
isEqualTo
(
"WEB-INF/lib/"
);
}
@Test
public
void
moduleLayout
()
throws
Exception
{
Layout
layout
=
new
Layouts
.
Module
();
assertThat
(
layout
.
getLibraryDestination
(
"lib.jar"
,
LibraryScope
.
COMPILE
)
,
equalTo
(
"lib/"
)
);
assertThat
(
layout
.
getLibraryDestination
(
"lib.jar"
,
LibraryScope
.
PROVIDED
)
,
nullValue
()
);
assertThat
(
layout
.
getLibraryDestination
(
"lib.jar"
,
LibraryScope
.
RUNTIME
)
,
equalTo
(
"lib/"
)
);
assertThat
(
layout
.
getLibraryDestination
(
"lib.jar"
,
LibraryScope
.
CUSTOM
)
,
equalTo
(
"lib/"
)
);
assertThat
(
layout
.
getLibraryDestination
(
"lib.jar"
,
LibraryScope
.
COMPILE
)
)
.
isEqualTo
(
"lib/"
);
assertThat
(
layout
.
getLibraryDestination
(
"lib.jar"
,
LibraryScope
.
PROVIDED
)
)
.
isNull
(
);
assertThat
(
layout
.
getLibraryDestination
(
"lib.jar"
,
LibraryScope
.
RUNTIME
)
)
.
isEqualTo
(
"lib/"
);
assertThat
(
layout
.
getLibraryDestination
(
"lib.jar"
,
LibraryScope
.
CUSTOM
)
)
.
isEqualTo
(
"lib/"
);
}
}
spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/MainClassFinderTests.java
View file @
00cfe1d0
...
...
@@ -30,8 +30,7 @@ import org.springframework.boot.loader.tools.MainClassFinder.ClassNameCallback;
import
org.springframework.boot.loader.tools.sample.ClassWithMainMethod
;
import
org.springframework.boot.loader.tools.sample.ClassWithoutMainMethod
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link MainClassFinder}.
...
...
@@ -58,7 +57,7 @@ public class MainClassFinderTests {
this
.
testJarFile
.
addClass
(
"B.class"
,
ClassWithMainMethod
.
class
);
this
.
testJarFile
.
addClass
(
"A.class"
,
ClassWithoutMainMethod
.
class
);
String
actual
=
MainClassFinder
.
findMainClass
(
this
.
testJarFile
.
getJarFile
(),
""
);
assertThat
(
actual
,
equalTo
(
"B"
)
);
assertThat
(
actual
).
isEqualTo
(
"B"
);
}
@Test
...
...
@@ -67,7 +66,7 @@ public class MainClassFinderTests {
this
.
testJarFile
.
addClass
(
"a/b/c/E.class"
,
ClassWithoutMainMethod
.
class
);
this
.
testJarFile
.
addClass
(
"a/b/F.class"
,
ClassWithoutMainMethod
.
class
);
String
actual
=
MainClassFinder
.
findMainClass
(
this
.
testJarFile
.
getJarFile
(),
""
);
assertThat
(
actual
,
equalTo
(
"a.b.c.D"
)
);
assertThat
(
actual
).
isEqualTo
(
"a.b.c.D"
);
}
@Test
...
...
@@ -75,7 +74,7 @@ public class MainClassFinderTests {
this
.
testJarFile
.
addClass
(
"a/B.class"
,
ClassWithMainMethod
.
class
);
this
.
testJarFile
.
addClass
(
"a/b/c/E.class"
,
ClassWithMainMethod
.
class
);
String
actual
=
MainClassFinder
.
findMainClass
(
this
.
testJarFile
.
getJarFile
(),
""
);
assertThat
(
actual
,
equalTo
(
"a.B"
)
);
assertThat
(
actual
).
isEqualTo
(
"a.B"
);
}
@Test
...
...
@@ -94,7 +93,7 @@ public class MainClassFinderTests {
this
.
testJarFile
.
addClass
(
"a/b/c/E.class"
,
ClassWithMainMethod
.
class
);
String
actual
=
MainClassFinder
.
findMainClass
(
this
.
testJarFile
.
getJarFile
(),
"a/"
);
assertThat
(
actual
,
equalTo
(
"B"
)
);
assertThat
(
actual
).
isEqualTo
(
"B"
);
}
...
...
@@ -103,7 +102,7 @@ public class MainClassFinderTests {
this
.
testJarFile
.
addClass
(
"B.class"
,
ClassWithMainMethod
.
class
);
this
.
testJarFile
.
addClass
(
"A.class"
,
ClassWithoutMainMethod
.
class
);
String
actual
=
MainClassFinder
.
findMainClass
(
this
.
testJarFile
.
getJarSource
());
assertThat
(
actual
,
equalTo
(
"B"
)
);
assertThat
(
actual
).
isEqualTo
(
"B"
);
}
@Test
...
...
@@ -112,7 +111,7 @@ public class MainClassFinderTests {
this
.
testJarFile
.
addClass
(
"a/b/c/E.class"
,
ClassWithoutMainMethod
.
class
);
this
.
testJarFile
.
addClass
(
"a/b/F.class"
,
ClassWithoutMainMethod
.
class
);
String
actual
=
MainClassFinder
.
findMainClass
(
this
.
testJarFile
.
getJarSource
());
assertThat
(
actual
,
equalTo
(
"a.b.c.D"
)
);
assertThat
(
actual
).
isEqualTo
(
"a.b.c.D"
);
}
@Test
...
...
@@ -120,7 +119,7 @@ public class MainClassFinderTests {
this
.
testJarFile
.
addClass
(
"a/B.class"
,
ClassWithMainMethod
.
class
);
this
.
testJarFile
.
addClass
(
"a/b/c/E.class"
,
ClassWithMainMethod
.
class
);
String
actual
=
MainClassFinder
.
findMainClass
(
this
.
testJarFile
.
getJarSource
());
assertThat
(
actual
,
equalTo
(
"a.B"
)
);
assertThat
(
actual
).
isEqualTo
(
"a.B"
);
}
@Test
...
...
@@ -141,7 +140,7 @@ public class MainClassFinderTests {
this
.
testJarFile
.
addClass
(
"a/b/G.class"
,
ClassWithMainMethod
.
class
);
ClassNameCollector
callback
=
new
ClassNameCollector
();
MainClassFinder
.
doWithMainClasses
(
this
.
testJarFile
.
getJarSource
(),
callback
);
assertThat
(
callback
.
getClassNames
().
toString
()
,
equalTo
(
"[a.b.G, a.b.c.D]"
)
);
assertThat
(
callback
.
getClassNames
().
toString
()
).
isEqualTo
(
"[a.b.G, a.b.c.D]"
);
}
@Test
...
...
@@ -152,7 +151,7 @@ public class MainClassFinderTests {
this
.
testJarFile
.
addClass
(
"a/b/G.class"
,
ClassWithMainMethod
.
class
);
ClassNameCollector
callback
=
new
ClassNameCollector
();
MainClassFinder
.
doWithMainClasses
(
this
.
testJarFile
.
getJarFile
(),
""
,
callback
);
assertThat
(
callback
.
getClassNames
().
toString
()
,
equalTo
(
"[a.b.G, a.b.c.D]"
)
);
assertThat
(
callback
.
getClassNames
().
toString
()
).
isEqualTo
(
"[a.b.G, a.b.c.D]"
);
}
private
static
class
ClassNameCollector
implements
ClassNameCallback
<
Object
>
{
...
...
spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/RepackagerTests.java
View file @
00cfe1d0
...
...
@@ -38,10 +38,7 @@ import org.springframework.boot.loader.tools.sample.ClassWithMainMethod;
import
org.springframework.boot.loader.tools.sample.ClassWithoutMainMethod
;
import
org.springframework.util.FileCopyUtils
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
hasItem
;
import
static
org
.
hamcrest
.
Matchers
.
startsWith
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Matchers
.
anyString
;
import
static
org
.
mockito
.
Matchers
.
eq
;
...
...
@@ -112,11 +109,11 @@ public class RepackagerTests {
repackager
.
setMainClass
(
"a.b.C"
);
repackager
.
repackage
(
NO_LIBRARIES
);
Manifest
actualManifest
=
getManifest
(
file
);
assertThat
(
actualManifest
.
getMainAttributes
().
getValue
(
"Main-Class"
)
,
equalTo
(
"org.springframework.boot.loader.JarLauncher"
)
);
assertThat
(
actualManifest
.
getMainAttributes
().
getValue
(
"Start-Class"
)
,
equalTo
(
"a.b.C"
)
);
assertThat
(
hasLauncherClasses
(
file
)
,
equalTo
(
true
)
);
assertThat
(
actualManifest
.
getMainAttributes
().
getValue
(
"Main-Class"
)
)
.
isEqualTo
(
"org.springframework.boot.loader.JarLauncher"
);
assertThat
(
actualManifest
.
getMainAttributes
().
getValue
(
"Start-Class"
)
)
.
isEqualTo
(
"a.b.C"
);
assertThat
(
hasLauncherClasses
(
file
)
).
isTrue
(
);
}
@Test
...
...
@@ -130,11 +127,11 @@ public class RepackagerTests {
Repackager
repackager
=
new
Repackager
(
file
);
repackager
.
repackage
(
NO_LIBRARIES
);
Manifest
actualManifest
=
getManifest
(
file
);
assertThat
(
actualManifest
.
getMainAttributes
().
getValue
(
"Main-Class"
)
,
equalTo
(
"org.springframework.boot.loader.JarLauncher"
)
);
assertThat
(
actualManifest
.
getMainAttributes
().
getValue
(
"Start-Class"
)
,
equalTo
(
"a.b.C"
)
);
assertThat
(
hasLauncherClasses
(
file
)
,
equalTo
(
true
)
);
assertThat
(
actualManifest
.
getMainAttributes
().
getValue
(
"Main-Class"
)
)
.
isEqualTo
(
"org.springframework.boot.loader.JarLauncher"
);
assertThat
(
actualManifest
.
getMainAttributes
().
getValue
(
"Start-Class"
)
)
.
isEqualTo
(
"a.b.C"
);
assertThat
(
hasLauncherClasses
(
file
)
).
isTrue
(
);
}
@Test
...
...
@@ -144,11 +141,11 @@ public class RepackagerTests {
Repackager
repackager
=
new
Repackager
(
file
);
repackager
.
repackage
(
NO_LIBRARIES
);
Manifest
actualManifest
=
getManifest
(
file
);
assertThat
(
actualManifest
.
getMainAttributes
().
getValue
(
"Main-Class"
)
,
equalTo
(
"org.springframework.boot.loader.JarLauncher"
)
);
assertThat
(
actualManifest
.
getMainAttributes
().
getValue
(
"Start-Class"
)
,
equalTo
(
"a.b.C"
)
);
assertThat
(
hasLauncherClasses
(
file
)
,
equalTo
(
true
)
);
assertThat
(
actualManifest
.
getMainAttributes
().
getValue
(
"Main-Class"
)
)
.
isEqualTo
(
"org.springframework.boot.loader.JarLauncher"
);
assertThat
(
actualManifest
.
getMainAttributes
().
getValue
(
"Start-Class"
)
)
.
isEqualTo
(
"a.b.C"
);
assertThat
(
hasLauncherClasses
(
file
)
).
isTrue
(
);
}
@Test
...
...
@@ -159,11 +156,11 @@ public class RepackagerTests {
repackager
.
repackage
(
NO_LIBRARIES
);
repackager
.
repackage
(
NO_LIBRARIES
);
Manifest
actualManifest
=
getManifest
(
file
);
assertThat
(
actualManifest
.
getMainAttributes
().
getValue
(
"Main-Class"
)
,
equalTo
(
"org.springframework.boot.loader.JarLauncher"
)
);
assertThat
(
actualManifest
.
getMainAttributes
().
getValue
(
"Start-Class"
)
,
equalTo
(
"a.b.C"
)
);
assertThat
(
hasLauncherClasses
(
file
)
,
equalTo
(
true
)
);
assertThat
(
actualManifest
.
getMainAttributes
().
getValue
(
"Main-Class"
)
)
.
isEqualTo
(
"org.springframework.boot.loader.JarLauncher"
);
assertThat
(
actualManifest
.
getMainAttributes
().
getValue
(
"Start-Class"
)
)
.
isEqualTo
(
"a.b.C"
);
assertThat
(
hasLauncherClasses
(
file
)
).
isTrue
(
);
}
@Test
...
...
@@ -194,9 +191,9 @@ public class RepackagerTests {
repackager
.
setLayout
(
new
Layouts
.
None
());
repackager
.
repackage
(
file
,
NO_LIBRARIES
);
Manifest
actualManifest
=
getManifest
(
file
);
assertThat
(
actualManifest
.
getMainAttributes
().
getValue
(
"Main-Class"
)
,
equalTo
(
"a.b.C"
)
);
assertThat
(
hasLauncherClasses
(
file
)
,
equalTo
(
false
)
);
assertThat
(
actualManifest
.
getMainAttributes
().
getValue
(
"Main-Class"
)
)
.
isEqualTo
(
"a.b.C"
);
assertThat
(
hasLauncherClasses
(
file
)
).
isFalse
(
);
}
@Test
...
...
@@ -207,9 +204,9 @@ public class RepackagerTests {
repackager
.
setLayout
(
new
Layouts
.
None
());
repackager
.
repackage
(
file
,
NO_LIBRARIES
);
Manifest
actualManifest
=
getManifest
(
file
);
assertThat
(
actualManifest
.
getMainAttributes
().
getValue
(
"Main-Class"
)
,
equalTo
(
null
)
);
assertThat
(
hasLauncherClasses
(
file
)
,
equalTo
(
false
)
);
assertThat
(
actualManifest
.
getMainAttributes
().
getValue
(
"Main-Class"
)
)
.
isEqualTo
(
null
);
assertThat
(
hasLauncherClasses
(
file
)
).
isFalse
(
);
}
@Test
...
...
@@ -218,9 +215,8 @@ public class RepackagerTests {
File
file
=
this
.
testJarFile
.
getFile
();
Repackager
repackager
=
new
Repackager
(
file
);
repackager
.
repackage
(
NO_LIBRARIES
);
assertThat
(
new
File
(
file
.
getParent
(),
file
.
getName
()
+
".original"
).
exists
(),
equalTo
(
true
));
assertThat
(
hasLauncherClasses
(
file
),
equalTo
(
true
));
assertThat
(
new
File
(
file
.
getParent
(),
file
.
getName
()
+
".original"
)).
exists
();
assertThat
(
hasLauncherClasses
(
file
)).
isTrue
();
}
@Test
...
...
@@ -230,9 +226,9 @@ public class RepackagerTests {
Repackager
repackager
=
new
Repackager
(
file
);
repackager
.
setBackupSource
(
false
);
repackager
.
repackage
(
NO_LIBRARIES
);
assertThat
(
new
File
(
file
.
getParent
(),
file
.
getName
()
+
".original"
)
.
exists
(),
equalTo
(
false
)
);
assertThat
(
hasLauncherClasses
(
file
)
,
equalTo
(
true
)
);
assertThat
(
new
File
(
file
.
getParent
(),
file
.
getName
()
+
".original"
)
)
.
doesNotExist
(
);
assertThat
(
hasLauncherClasses
(
file
)
).
isTrue
(
);
}
@Test
...
...
@@ -242,10 +238,10 @@ public class RepackagerTests {
File
dest
=
this
.
temporaryFolder
.
newFile
(
"different.jar"
);
Repackager
repackager
=
new
Repackager
(
source
);
repackager
.
repackage
(
dest
,
NO_LIBRARIES
);
assertThat
(
new
File
(
source
.
getParent
(),
source
.
getName
()
+
".original"
)
.
exists
(),
equalTo
(
false
)
);
assertThat
(
hasLauncherClasses
(
source
)
,
equalTo
(
false
)
);
assertThat
(
hasLauncherClasses
(
dest
)
,
equalTo
(
true
)
);
assertThat
(
new
File
(
source
.
getParent
(),
source
.
getName
()
+
".original"
)
)
.
doesNotExist
(
);
assertThat
(
hasLauncherClasses
(
source
)
).
isFalse
(
);
assertThat
(
hasLauncherClasses
(
dest
)
).
isTrue
(
);
}
@Test
...
...
@@ -273,7 +269,7 @@ public class RepackagerTests {
File
dest
=
this
.
temporaryFolder
.
newFile
(
"dest.jar"
);
dest
.
createNewFile
();
repackager
.
repackage
(
dest
,
NO_LIBRARIES
);
assertThat
(
hasLauncherClasses
(
dest
)
,
equalTo
(
true
)
);
assertThat
(
hasLauncherClasses
(
dest
)
).
isTrue
(
);
}
@Test
...
...
@@ -309,14 +305,14 @@ public class RepackagerTests {
callback
.
library
(
new
Library
(
libNonJarFile
,
LibraryScope
.
COMPILE
));
}
});
assertThat
(
hasEntry
(
file
,
"lib/"
+
libJarFile
.
getName
())
,
equalTo
(
true
)
);
assertThat
(
hasEntry
(
file
,
"lib/"
+
libJarFileToUnpack
.
getName
())
,
equalTo
(
true
)
);
assertThat
(
hasEntry
(
file
,
"lib/"
+
libNonJarFile
.
getName
())
,
equalTo
(
false
)
);
assertThat
(
hasEntry
(
file
,
"lib/"
+
libJarFile
.
getName
())
).
isTrue
(
);
assertThat
(
hasEntry
(
file
,
"lib/"
+
libJarFileToUnpack
.
getName
())
).
isTrue
(
);
assertThat
(
hasEntry
(
file
,
"lib/"
+
libNonJarFile
.
getName
())
).
isFalse
(
);
JarEntry
entry
=
getEntry
(
file
,
"lib/"
+
libJarFile
.
getName
());
assertThat
(
entry
.
getTime
()
,
equalTo
(
JAN_1_1985
)
);
assertThat
(
entry
.
getTime
()
).
isEqualTo
(
JAN_1_1985
);
entry
=
getEntry
(
file
,
"lib/"
+
libJarFileToUnpack
.
getName
());
assertThat
(
entry
.
getComment
()
,
startsWith
(
"UNPACK:"
)
);
assertThat
(
entry
.
getComment
().
length
()
,
equalTo
(
47
)
);
assertThat
(
entry
.
getComment
()
).
startsWith
(
"UNPACK:"
);
assertThat
(
entry
.
getComment
().
length
()
).
isEqualTo
(
47
);
}
@Test
...
...
@@ -357,9 +353,9 @@ public class RepackagerTests {
callback
.
library
(
new
Library
(
libJarFile
,
scope
));
}
});
assertThat
(
hasEntry
(
file
,
"test/"
+
libJarFile
.
getName
())
,
equalTo
(
true
)
);
assertThat
(
getManifest
(
file
).
getMainAttributes
().
getValue
(
"Main-Class"
)
,
equalTo
(
"testLauncher"
)
);
assertThat
(
hasEntry
(
file
,
"test/"
+
libJarFile
.
getName
())
).
isTrue
(
);
assertThat
(
getManifest
(
file
).
getMainAttributes
().
getValue
(
"Main-Class"
)
)
.
isEqualTo
(
"testLauncher"
);
}
@Test
...
...
@@ -369,8 +365,8 @@ public class RepackagerTests {
Repackager
repackager
=
new
Repackager
(
file
);
repackager
.
repackage
(
NO_LIBRARIES
);
Manifest
actualManifest
=
getManifest
(
file
);
assertThat
(
actualManifest
.
getMainAttributes
()
.
containsKey
(
new
Attributes
.
Name
(
"Spring-Boot-Version"
))
,
equalTo
(
true
))
;
assertThat
(
actualManifest
.
getMainAttributes
()
)
.
containsKey
(
new
Attributes
.
Name
(
"Spring-Boot-Version"
));
}
@Test
...
...
@@ -399,10 +395,10 @@ public class RepackagerTests {
});
JarFile
jarFile
=
new
JarFile
(
file
);
try
{
assertThat
(
jarFile
.
getEntry
(
"lib/"
+
nestedFile
.
getName
()).
getMethod
()
,
equalTo
(
ZipEntry
.
STORED
)
);
assertThat
(
jarFile
.
getEntry
(
"test/nested.jar"
).
getMethod
()
,
equalTo
(
ZipEntry
.
STORED
)
);
assertThat
(
jarFile
.
getEntry
(
"lib/"
+
nestedFile
.
getName
()).
getMethod
()
)
.
isEqualTo
(
ZipEntry
.
STORED
);
assertThat
(
jarFile
.
getEntry
(
"test/nested.jar"
).
getMethod
()
)
.
isEqualTo
(
ZipEntry
.
STORED
);
}
finally
{
jarFile
.
close
();
...
...
@@ -418,12 +414,12 @@ public class RepackagerTests {
LaunchScript
script
=
new
MockLauncherScript
(
"ABC"
);
repackager
.
repackage
(
dest
,
NO_LIBRARIES
,
script
);
byte
[]
bytes
=
FileCopyUtils
.
copyToByteArray
(
dest
);
assertThat
(
new
String
(
bytes
)
,
startsWith
(
"ABC"
)
);
assertThat
(
hasLauncherClasses
(
source
)
,
equalTo
(
false
)
);
assertThat
(
hasLauncherClasses
(
dest
)
,
equalTo
(
true
)
);
assertThat
(
new
String
(
bytes
)
).
startsWith
(
"ABC"
);
assertThat
(
hasLauncherClasses
(
source
)
).
isFalse
(
);
assertThat
(
hasLauncherClasses
(
dest
)
).
isTrue
(
);
try
{
assertThat
(
Files
.
getPosixFilePermissions
(
dest
.
toPath
())
,
hasItem
(
PosixFilePermission
.
OWNER_EXECUTE
)
);
assertThat
(
Files
.
getPosixFilePermissions
(
dest
.
toPath
())
)
.
contains
(
PosixFilePermission
.
OWNER_EXECUTE
);
}
catch
(
UnsupportedOperationException
ex
)
{
// Probably running the test on Windows
...
...
@@ -450,8 +446,8 @@ public class RepackagerTests {
});
JarFile
jarFile
=
new
JarFile
(
file
);
try
{
assertThat
(
jarFile
.
getEntry
(
"lib/"
+
nestedFile
.
getName
()).
getComment
()
,
startsWith
(
"UNPACK:"
)
);
assertThat
(
jarFile
.
getEntry
(
"lib/"
+
nestedFile
.
getName
()).
getComment
()
)
.
startsWith
(
"UNPACK:"
);
}
finally
{
jarFile
.
close
();
...
...
@@ -482,8 +478,8 @@ public class RepackagerTests {
});
JarFile
jarFile
=
new
JarFile
(
file
);
try
{
assertThat
(
jarFile
.
getEntry
(
"lib/"
+
nestedFile
.
getName
()).
getSize
()
,
equalTo
(
sourceLength
)
);
assertThat
(
jarFile
.
getEntry
(
"lib/"
+
nestedFile
.
getName
()).
getSize
()
)
.
isEqualTo
(
sourceLength
);
}
finally
{
jarFile
.
close
();
...
...
spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/ExecutableArchiveLauncherTests.java
View file @
00cfe1d0
...
...
@@ -28,8 +28,7 @@ import org.mockito.MockitoAnnotations;
import
org.springframework.boot.loader.archive.Archive.Entry
;
import
static
org
.
junit
.
Assert
.
assertArrayEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
/**
...
...
@@ -87,8 +86,8 @@ public class ExecutableArchiveLauncherTests {
}
private
void
assertClassLoaderUrls
(
ClassLoader
classLoader
,
URL
[]
urls
)
{
assertT
rue
(
classLoader
instanceof
URLClassLoader
);
assert
ArrayEquals
(
urls
,
((
URLClassLoader
)
classLoader
).
getURLs
()
);
assertT
hat
(
classLoader
).
isInstanceOf
(
URLClassLoader
.
class
);
assert
That
(((
URLClassLoader
)
classLoader
).
getURLs
()).
isEqualTo
(
urls
);
}
private
void
doWithTccl
(
ClassLoader
classLoader
,
Callable
<?>
action
)
...
...
spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/InputArgumentsJavaAgentDetectorTests.java
View file @
00cfe1d0
...
...
@@ -23,8 +23,7 @@ import java.util.Arrays;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link InputArgumentsJavaAgentDetector}
...
...
@@ -38,24 +37,25 @@ public class InputArgumentsJavaAgentDetectorTests {
throws
MalformedURLException
,
IOException
{
InputArgumentsJavaAgentDetector
detector
=
new
InputArgumentsJavaAgentDetector
(
Arrays
.
asList
(
"-javaagent:my-agent.jar"
));
assertFalse
(
detector
.
isJavaAgentJar
(
new
File
(
"something-else.jar"
).
getCanonicalFile
().
toURI
().
toURL
()));
assertThat
(
detector
.
isJavaAgentJar
(
new
File
(
"something-else.jar"
).
getCanonicalFile
().
toURI
().
toURL
()))
.
isFalse
();
}
@Test
public
void
singleJavaAgent
()
throws
MalformedURLException
,
IOException
{
InputArgumentsJavaAgentDetector
detector
=
new
InputArgumentsJavaAgentDetector
(
Arrays
.
asList
(
"-javaagent:my-agent.jar"
));
assertT
rue
(
detector
.
isJavaAgentJar
(
new
File
(
"my-agent.jar"
).
getCanonicalFile
().
toURI
().
toURL
()));
assertT
hat
(
detector
.
isJavaAgentJar
(
new
File
(
"my-agent.jar"
).
getCanonicalFile
().
toURI
().
toURL
()))
.
isTrue
()
;
}
@Test
public
void
singleJavaAgentWithOptions
()
throws
MalformedURLException
,
IOException
{
InputArgumentsJavaAgentDetector
detector
=
new
InputArgumentsJavaAgentDetector
(
Arrays
.
asList
(
"-javaagent:my-agent.jar=a=alpha,b=bravo"
));
assertT
rue
(
detector
.
isJavaAgentJar
(
new
File
(
"my-agent.jar"
).
getCanonicalFile
().
toURI
().
toURL
()));
assertT
hat
(
detector
.
isJavaAgentJar
(
new
File
(
"my-agent.jar"
).
getCanonicalFile
().
toURI
().
toURL
()))
.
isTrue
()
;
}
@Test
...
...
@@ -63,10 +63,11 @@ public class InputArgumentsJavaAgentDetectorTests {
InputArgumentsJavaAgentDetector
detector
=
new
InputArgumentsJavaAgentDetector
(
Arrays
.
asList
(
"-javaagent:my-agent.jar"
,
"-javaagent:my-other-agent.jar"
));
assertTrue
(
detector
.
isJavaAgentJar
(
new
File
(
"my-agent.jar"
).
getCanonicalFile
().
toURI
().
toURL
()));
assertTrue
(
detector
.
isJavaAgentJar
(
new
File
(
"my-other-agent.jar"
).
getCanonicalFile
().
toURI
().
toURL
()));
assertThat
(
detector
.
isJavaAgentJar
(
new
File
(
"my-agent.jar"
).
getCanonicalFile
().
toURI
().
toURL
())).
isTrue
();
assertThat
(
detector
.
isJavaAgentJar
(
new
File
(
"my-other-agent.jar"
).
getCanonicalFile
().
toURI
().
toURL
()))
.
isTrue
();
}
}
spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/LaunchedURLClassLoaderTests.java
View file @
00cfe1d0
...
...
@@ -25,11 +25,7 @@ import org.junit.rules.TemporaryFolder;
import
org.springframework.boot.loader.jar.JarFile
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link LaunchedURLClassLoader}.
...
...
@@ -47,13 +43,13 @@ public class LaunchedURLClassLoaderTests {
public
void
resolveResourceFromWindowsFilesystem
()
throws
Exception
{
// This path is invalid - it should return null even on Windows.
// A regular URLClassLoader will deal with it gracefully.
assert
Null
(
getClass
().
getClassLoader
()
.
getResource
(
"c:\\Users\\user\\bar.properties"
));
assert
That
(
getClass
().
getClassLoader
()
.
getResource
(
"c:\\Users\\user\\bar.properties"
))
.
isNull
()
;
LaunchedURLClassLoader
loader
=
new
LaunchedURLClassLoader
(
new
URL
[]
{
new
URL
(
"jar:file:src/test/resources/jars/app.jar!/"
)
},
getClass
().
getClassLoader
());
// So we should too...
assert
Null
(
loader
.
getResource
(
"c:\\Users\\user\\bar.properties"
)
);
assert
That
(
loader
.
getResource
(
"c:\\Users\\user\\bar.properties"
)).
isNull
(
);
}
@Test
...
...
@@ -61,7 +57,7 @@ public class LaunchedURLClassLoaderTests {
LaunchedURLClassLoader
loader
=
new
LaunchedURLClassLoader
(
new
URL
[]
{
new
URL
(
"jar:file:src/test/resources/jars/app.jar!/"
)
},
getClass
().
getClassLoader
());
assert
NotNull
(
loader
.
getResource
(
"demo/Application.java"
)
);
assert
That
(
loader
.
getResource
(
"demo/Application.java"
)).
isNotNull
(
);
}
@Test
...
...
@@ -69,7 +65,8 @@ public class LaunchedURLClassLoaderTests {
LaunchedURLClassLoader
loader
=
new
LaunchedURLClassLoader
(
new
URL
[]
{
new
URL
(
"jar:file:src/test/resources/jars/app.jar!/"
)
},
getClass
().
getClassLoader
());
assertTrue
(
loader
.
getResources
(
"demo/Application.java"
).
hasMoreElements
());
assertThat
(
loader
.
getResources
(
"demo/Application.java"
).
hasMoreElements
())
.
isTrue
();
}
@Test
...
...
@@ -77,7 +74,7 @@ public class LaunchedURLClassLoaderTests {
LaunchedURLClassLoader
loader
=
new
LaunchedURLClassLoader
(
new
URL
[]
{
new
URL
(
"jar:file:src/test/resources/jars/app.jar!/"
)
},
getClass
().
getClassLoader
());
assert
NotNull
(
loader
.
getResource
(
""
)
);
assert
That
(
loader
.
getResource
(
""
)).
isNotNull
(
);
}
@Test
...
...
@@ -85,7 +82,7 @@ public class LaunchedURLClassLoaderTests {
LaunchedURLClassLoader
loader
=
new
LaunchedURLClassLoader
(
new
URL
[]
{
new
URL
(
"jar:file:src/test/resources/jars/app.jar!/"
)
},
getClass
().
getClassLoader
());
assertT
rue
(
loader
.
getResources
(
""
).
hasMoreElements
()
);
assertT
hat
(
loader
.
getResources
(
""
).
hasMoreElements
()).
isTrue
(
);
}
@Test
...
...
@@ -97,8 +94,8 @@ public class LaunchedURLClassLoaderTests {
LaunchedURLClassLoader
loader
=
new
LaunchedURLClassLoader
(
new
URL
[]
{
url
},
null
);
URL
resource
=
loader
.
getResource
(
"nested.jar!/3.dat"
);
assertThat
(
resource
.
toString
()
,
equalTo
(
url
+
"nested.jar!/3.dat"
)
);
assertThat
(
resource
.
openConnection
().
getInputStream
().
read
()
,
equalTo
(
3
)
);
assertThat
(
resource
.
toString
()
).
isEqualTo
(
url
+
"nested.jar!/3.dat"
);
assertThat
(
resource
.
openConnection
().
getInputStream
().
read
()
).
isEqualTo
(
3
);
}
}
spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java
View file @
00cfe1d0
...
...
@@ -34,13 +34,7 @@ import org.mockito.MockitoAnnotations;
import
org.springframework.boot.loader.archive.Archive
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
verify
;
...
...
@@ -78,31 +72,32 @@ public class PropertiesLauncherTests {
@Test
public
void
testDefaultHome
()
{
PropertiesLauncher
launcher
=
new
PropertiesLauncher
();
assert
Equals
(
new
File
(
System
.
getProperty
(
"loader.home"
)),
launcher
.
getHomeDirectory
(
));
assert
That
(
launcher
.
getHomeDirectory
())
.
isEqualTo
(
new
File
(
System
.
getProperty
(
"loader.home"
)
));
}
@Test
public
void
testUserSpecifiedMain
()
throws
Exception
{
PropertiesLauncher
launcher
=
new
PropertiesLauncher
();
assert
Equals
(
"demo.Application"
,
launcher
.
getMainClass
()
);
assert
Null
(
System
.
getProperty
(
"loader.main"
)
);
assert
That
(
launcher
.
getMainClass
()).
isEqualTo
(
"demo.Application"
);
assert
That
(
System
.
getProperty
(
"loader.main"
)).
isNull
(
);
}
@Test
public
void
testUserSpecifiedConfigName
()
throws
Exception
{
System
.
setProperty
(
"loader.config.name"
,
"foo"
);
PropertiesLauncher
launcher
=
new
PropertiesLauncher
();
assert
Equals
(
"my.Application"
,
launcher
.
getMainClass
()
);
assert
Equals
(
"[etc/]"
,
ReflectionTestUtils
.
getField
(
launcher
,
"paths"
).
toString
()
);
assert
That
(
launcher
.
getMainClass
()).
isEqualTo
(
"my.Application"
);
assert
That
(
ReflectionTestUtils
.
getField
(
launcher
,
"paths"
).
toString
())
.
isEqualTo
(
"[etc/]"
);
}
@Test
public
void
testUserSpecifiedDotPath
()
throws
Exception
{
System
.
setProperty
(
"loader.path"
,
"."
);
PropertiesLauncher
launcher
=
new
PropertiesLauncher
();
assertEquals
(
"[.]"
,
ReflectionTestUtils
.
getField
(
launcher
,
"paths"
).
toString
());
assertThat
(
ReflectionTestUtils
.
getField
(
launcher
,
"paths"
).
toString
())
.
isEqualTo
(
"[.]"
);
}
@Test
...
...
@@ -110,8 +105,8 @@ public class PropertiesLauncherTests {
System
.
setProperty
(
"loader.path"
,
"jars/*"
);
System
.
setProperty
(
"loader.main"
,
"demo.Application"
);
PropertiesLauncher
launcher
=
new
PropertiesLauncher
();
assert
Equals
(
"[jars/]"
,
ReflectionTestUtils
.
getField
(
launcher
,
"paths"
).
toString
()
);
assert
That
(
ReflectionTestUtils
.
getField
(
launcher
,
"paths"
).
toString
())
.
isEqualTo
(
"[jars/]"
);
launcher
.
launch
(
new
String
[
0
]);
waitFor
(
"Hello World"
);
}
...
...
@@ -121,8 +116,8 @@ public class PropertiesLauncherTests {
System
.
setProperty
(
"loader.path"
,
"jars/app.jar"
);
System
.
setProperty
(
"loader.main"
,
"demo.Application"
);
PropertiesLauncher
launcher
=
new
PropertiesLauncher
();
assert
Equals
(
"[jars/app.jar]"
,
ReflectionTestUtils
.
getField
(
launcher
,
"paths"
).
toString
()
);
assert
That
(
ReflectionTestUtils
.
getField
(
launcher
,
"paths"
).
toString
())
.
isEqualTo
(
"[jars/app.jar]"
);
launcher
.
launch
(
new
String
[
0
]);
waitFor
(
"Hello World"
);
}
...
...
@@ -132,8 +127,8 @@ public class PropertiesLauncherTests {
System
.
setProperty
(
"loader.path"
,
"./jars/app.jar"
);
System
.
setProperty
(
"loader.main"
,
"demo.Application"
);
PropertiesLauncher
launcher
=
new
PropertiesLauncher
();
assert
Equals
(
"[jars/app.jar]"
,
ReflectionTestUtils
.
getField
(
launcher
,
"paths"
).
toString
()
);
assert
That
(
ReflectionTestUtils
.
getField
(
launcher
,
"paths"
).
toString
())
.
isEqualTo
(
"[jars/app.jar]"
);
launcher
.
launch
(
new
String
[
0
]);
waitFor
(
"Hello World"
);
}
...
...
@@ -143,8 +138,8 @@ public class PropertiesLauncherTests {
System
.
setProperty
(
"loader.path"
,
"jars/app.jar"
);
System
.
setProperty
(
"loader.classLoader"
,
URLClassLoader
.
class
.
getName
());
PropertiesLauncher
launcher
=
new
PropertiesLauncher
();
assert
Equals
(
"[jars/app.jar]"
,
ReflectionTestUtils
.
getField
(
launcher
,
"paths"
).
toString
()
);
assert
That
(
ReflectionTestUtils
.
getField
(
launcher
,
"paths"
).
toString
())
.
isEqualTo
(
"[jars/app.jar]"
);
launcher
.
launch
(
new
String
[
0
]);
waitFor
(
"Hello World"
);
}
...
...
@@ -154,8 +149,8 @@ public class PropertiesLauncherTests {
System
.
setProperty
(
"loader.path"
,
"more-jars/app.jar,jars/app.jar"
);
System
.
setProperty
(
"loader.classLoader"
,
URLClassLoader
.
class
.
getName
());
PropertiesLauncher
launcher
=
new
PropertiesLauncher
();
assert
Equals
(
"[more-jars/app.jar, jars/app.jar]"
,
ReflectionTestUtils
.
getField
(
launcher
,
"paths"
).
toString
()
);
assert
That
(
ReflectionTestUtils
.
getField
(
launcher
,
"paths"
).
toString
())
.
isEqualTo
(
"[more-jars/app.jar, jars/app.jar]"
);
launcher
.
launch
(
new
String
[
0
]);
waitFor
(
"Hello Other World"
);
}
...
...
@@ -165,8 +160,8 @@ public class PropertiesLauncherTests {
System
.
setProperty
(
"loader.classLoader"
,
TestLoader
.
class
.
getName
());
PropertiesLauncher
launcher
=
new
PropertiesLauncher
();
ClassLoader
loader
=
launcher
.
createClassLoader
(
Collections
.<
Archive
>
emptyList
());
assert
NotNull
(
loader
);
assert
Equals
(
TestLoader
.
class
.
getName
(),
loader
.
getClass
()
.
getName
());
assert
That
(
loader
).
isNotNull
(
);
assert
That
(
loader
.
getClass
().
getName
()).
isEqualTo
(
TestLoader
.
class
.
getName
());
}
@Test
...
...
@@ -175,28 +170,29 @@ public class PropertiesLauncherTests {
System
.
setProperty
(
"loader.config.name"
,
"foo"
);
System
.
setProperty
(
"loader.config.location"
,
"classpath:bar.properties"
);
PropertiesLauncher
launcher
=
new
PropertiesLauncher
();
assert
Equals
(
"my.BarApplication"
,
launcher
.
getMainClass
()
);
assert
That
(
launcher
.
getMainClass
()).
isEqualTo
(
"my.BarApplication"
);
}
@Test
public
void
testSystemPropertySpecifiedMain
()
throws
Exception
{
System
.
setProperty
(
"loader.main"
,
"foo.Bar"
);
PropertiesLauncher
launcher
=
new
PropertiesLauncher
();
assert
Equals
(
"foo.Bar"
,
launcher
.
getMainClass
()
);
assert
That
(
launcher
.
getMainClass
()).
isEqualTo
(
"foo.Bar"
);
}
@Test
public
void
testSystemPropertiesSet
()
throws
Exception
{
System
.
setProperty
(
"loader.system"
,
"true"
);
new
PropertiesLauncher
();
assert
Equals
(
"demo.Application"
,
System
.
getProperty
(
"loader.main"
)
);
assert
That
(
System
.
getProperty
(
"loader.main"
)).
isEqualTo
(
"demo.Application"
);
}
@Test
public
void
testArgsEnhanced
()
throws
Exception
{
System
.
setProperty
(
"loader.args"
,
"foo"
);
PropertiesLauncher
launcher
=
new
PropertiesLauncher
();
assertEquals
(
"[foo, bar]"
,
Arrays
.
asList
(
launcher
.
getArgs
(
"bar"
)).
toString
());
assertThat
(
Arrays
.
asList
(
launcher
.
getArgs
(
"bar"
)).
toString
())
.
isEqualTo
(
"[foo, bar]"
);
}
@Test
...
...
@@ -208,8 +204,7 @@ public class PropertiesLauncherTests {
}
List
<
Archive
>
nonAgentArchives
=
new
PropertiesLauncher
(
this
.
javaAgentDetector
)
.
getClassPathArchives
();
assertThat
(
nonAgentArchives
.
size
(),
is
(
equalTo
(
allArchives
.
size
()
-
parentUrls
.
length
)));
assertThat
(
nonAgentArchives
).
hasSize
(
allArchives
.
size
()
-
parentUrls
.
length
);
for
(
URL
url
:
parentUrls
)
{
verify
(
this
.
javaAgentDetector
).
isJavaAgentJar
(
url
);
}
...
...
@@ -223,7 +218,7 @@ public class PropertiesLauncherTests {
Thread
.
sleep
(
50L
);
timeout
=
this
.
output
.
toString
().
contains
(
value
);
}
assertT
rue
(
"Timed out waiting for ("
+
value
+
")"
,
timeout
);
assertT
hat
(
timeout
).
as
(
"Timed out waiting for ("
+
value
+
")"
).
isTrue
(
);
}
public
static
class
TestLoader
extends
URLClassLoader
{
...
...
spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/WarLauncherTests.java
View file @
00cfe1d0
...
...
@@ -38,9 +38,7 @@ import org.springframework.boot.loader.archive.ExplodedArchive;
import
org.springframework.boot.loader.archive.JarFileArchive
;
import
org.springframework.util.FileSystemUtils
;
import
static
org
.
hamcrest
.
Matchers
.
hasItems
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link WarLauncher}
...
...
@@ -61,28 +59,23 @@ public class WarLauncherTests {
webInfLib
.
mkdirs
();
File
webInfLibFoo
=
new
File
(
webInfLib
,
"foo.jar"
);
new
JarOutputStream
(
new
FileOutputStream
(
webInfLibFoo
)).
close
();
WarLauncher
launcher
=
new
WarLauncher
(
new
ExplodedArchive
(
warRoot
,
true
));
List
<
Archive
>
archives
=
launcher
.
getClassPathArchives
();
assertEquals
(
2
,
archives
.
size
());
assertThat
(
getUrls
(
archives
),
hasItems
(
webInfClasses
.
toURI
().
toURL
(),
new
URL
(
"jar:"
+
webInfLibFoo
.
toURI
().
toURL
()
+
"!/"
)));
assertThat
(
archives
).
hasSize
(
2
);
assertThat
(
getUrls
(
archives
)).
containsOnly
(
webInfClasses
.
toURI
().
toURL
(),
new
URL
(
"jar:"
+
webInfLibFoo
.
toURI
().
toURL
()
+
"!/"
));
}
@Test
public
void
archivedWarHasOnlyWebInfClassesAndContentsOfWebInfLibOnClasspath
()
throws
Exception
{
File
warRoot
=
createWarArchive
();
WarLauncher
launcher
=
new
WarLauncher
(
new
JarFileArchive
(
warRoot
));
List
<
Archive
>
archives
=
launcher
.
getClassPathArchives
();
assertEquals
(
2
,
archives
.
size
());
assertThat
(
getUrls
(
archives
),
hasItems
(
new
URL
(
"jar:"
+
warRoot
.
toURI
().
toURL
()
+
"!/WEB-INF/classes!/"
),
new
URL
(
"jar:"
+
warRoot
.
toURI
().
toURL
()
+
"!/WEB-INF/lib/foo.jar!/"
)));
assertThat
(
archives
).
hasSize
(
2
);
assertThat
(
getUrls
(
archives
)).
containsOnly
(
new
URL
(
"jar:"
+
warRoot
.
toURI
().
toURL
()
+
"!/WEB-INF/classes!/"
),
new
URL
(
"jar:"
+
warRoot
.
toURI
().
toURL
()
+
"!/WEB-INF/lib/foo.jar!/"
));
}
private
Set
<
URL
>
getUrls
(
List
<
Archive
>
archives
)
throws
MalformedURLException
{
...
...
@@ -96,14 +89,11 @@ public class WarLauncherTests {
private
File
createWarArchive
()
throws
IOException
,
FileNotFoundException
{
File
warRoot
=
new
File
(
"target/archive.war"
);
warRoot
.
delete
();
JarOutputStream
jarOutputStream
=
new
JarOutputStream
(
new
FileOutputStream
(
warRoot
));
jarOutputStream
.
putNextEntry
(
new
JarEntry
(
"WEB-INF/"
));
jarOutputStream
.
putNextEntry
(
new
JarEntry
(
"WEB-INF/classes/"
));
jarOutputStream
.
putNextEntry
(
new
JarEntry
(
"WEB-INF/lib/"
));
JarEntry
webInfLibFoo
=
new
JarEntry
(
"WEB-INF/lib/foo.jar"
);
webInfLibFoo
.
setMethod
(
ZipEntry
.
STORED
);
ByteArrayOutputStream
fooJarStream
=
new
ByteArrayOutputStream
();
...
...
@@ -114,7 +104,6 @@ public class WarLauncherTests {
webInfLibFoo
.
setCrc
(
crc32
.
getValue
());
jarOutputStream
.
putNextEntry
(
webInfLibFoo
);
jarOutputStream
.
write
(
fooJarStream
.
toByteArray
());
jarOutputStream
.
close
();
return
warRoot
;
}
...
...
spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/ExplodedArchiveTests.java
View file @
00cfe1d0
...
...
@@ -38,10 +38,7 @@ import org.junit.rules.TemporaryFolder;
import
org.springframework.boot.loader.TestJarCreator
;
import
org.springframework.boot.loader.archive.Archive.Entry
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
greaterThan
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link ExplodedArchive}.
...
...
@@ -93,29 +90,29 @@ public class ExplodedArchiveTests {
@Test
public
void
getManifest
()
throws
Exception
{
assertThat
(
this
.
archive
.
getManifest
().
getMainAttributes
().
getValue
(
"Built-By"
)
,
equalTo
(
"j1"
)
);
assertThat
(
this
.
archive
.
getManifest
().
getMainAttributes
().
getValue
(
"Built-By"
)
)
.
isEqualTo
(
"j1"
);
}
@Test
public
void
getEntries
()
throws
Exception
{
Map
<
String
,
Archive
.
Entry
>
entries
=
getEntriesMap
(
this
.
archive
);
assertThat
(
entries
.
size
()
,
equalTo
(
10
)
);
assertThat
(
entries
.
size
()
).
isEqualTo
(
10
);
}
@Test
public
void
getUrl
()
throws
Exception
{
URL
url
=
this
.
archive
.
getUrl
();
assertThat
(
new
File
(
URLDecoder
.
decode
(
url
.
getFile
(),
"UTF-8"
))
,
equalTo
(
this
.
rootFolder
)
);
assertThat
(
new
File
(
URLDecoder
.
decode
(
url
.
getFile
(),
"UTF-8"
))
)
.
isEqualTo
(
this
.
rootFolder
);
}
@Test
public
void
getNestedArchive
()
throws
Exception
{
Entry
entry
=
getEntriesMap
(
this
.
archive
).
get
(
"nested.jar"
);
Archive
nested
=
this
.
archive
.
getNestedArchive
(
entry
);
assertThat
(
nested
.
getUrl
().
toString
()
,
equalTo
(
"jar:"
+
this
.
rootFolder
.
toURI
()
+
"nested.jar!/"
)
);
assertThat
(
nested
.
getUrl
().
toString
()
)
.
isEqualTo
(
"jar:"
+
this
.
rootFolder
.
toURI
()
+
"nested.jar!/"
);
}
@Test
...
...
@@ -123,43 +120,44 @@ public class ExplodedArchiveTests {
Entry
entry
=
getEntriesMap
(
this
.
archive
).
get
(
"d/"
);
Archive
nested
=
this
.
archive
.
getNestedArchive
(
entry
);
Map
<
String
,
Entry
>
nestedEntries
=
getEntriesMap
(
nested
);
assertThat
(
nestedEntries
.
size
()
,
equalTo
(
1
)
);
assertThat
(
nested
.
getUrl
().
toString
()
,
equalTo
(
"file:"
+
this
.
rootFolder
.
toURI
().
getPath
()
+
"d/"
)
);
assertThat
(
nestedEntries
.
size
()
).
isEqualTo
(
1
);
assertThat
(
nested
.
getUrl
().
toString
()
)
.
isEqualTo
(
"file:"
+
this
.
rootFolder
.
toURI
().
getPath
()
+
"d/"
);
}
@Test
public
void
getNonRecursiveEntriesForRoot
()
throws
Exception
{
ExplodedArchive
archive
=
new
ExplodedArchive
(
new
File
(
"/"
),
false
);
Map
<
String
,
Archive
.
Entry
>
entries
=
getEntriesMap
(
archive
);
assertThat
(
entries
.
size
()
,
greaterThan
(
1
)
);
assertThat
(
entries
.
size
()
).
isGreaterThan
(
1
);
}
@Test
public
void
getNonRecursiveManifest
()
throws
Exception
{
ExplodedArchive
archive
=
new
ExplodedArchive
(
new
File
(
"src/test/resources/root"
));
assert
NotNull
(
archive
.
getManifest
()
);
assert
That
(
archive
.
getManifest
()).
isNotNull
(
);
Map
<
String
,
Archive
.
Entry
>
entries
=
getEntriesMap
(
archive
);
assertThat
(
entries
.
size
()
,
equalTo
(
4
)
);
assertThat
(
entries
.
size
()
).
isEqualTo
(
4
);
}
@Test
public
void
getNonRecursiveManifestEvenIfNonRecursive
()
throws
Exception
{
ExplodedArchive
archive
=
new
ExplodedArchive
(
new
File
(
"src/test/resources/root"
),
false
);
assert
NotNull
(
archive
.
getManifest
()
);
assert
That
(
archive
.
getManifest
()).
isNotNull
(
);
Map
<
String
,
Archive
.
Entry
>
entries
=
getEntriesMap
(
archive
);
assertThat
(
entries
.
size
()
,
equalTo
(
3
)
);
assertThat
(
entries
.
size
()
).
isEqualTo
(
3
);
}
@Test
public
void
getResourceAsStream
()
throws
Exception
{
ExplodedArchive
archive
=
new
ExplodedArchive
(
new
File
(
"src/test/resources/root"
));
assert
NotNull
(
archive
.
getManifest
()
);
assert
That
(
archive
.
getManifest
()).
isNotNull
(
);
URLClassLoader
loader
=
new
URLClassLoader
(
new
URL
[]
{
archive
.
getUrl
()
});
assertNotNull
(
loader
.
getResourceAsStream
(
"META-INF/spring/application.xml"
));
assertThat
(
loader
.
getResourceAsStream
(
"META-INF/spring/application.xml"
))
.
isNotNull
();
loader
.
close
();
}
...
...
@@ -167,9 +165,10 @@ public class ExplodedArchiveTests {
public
void
getResourceAsStreamNonRecursive
()
throws
Exception
{
ExplodedArchive
archive
=
new
ExplodedArchive
(
new
File
(
"src/test/resources/root"
),
false
);
assert
NotNull
(
archive
.
getManifest
()
);
assert
That
(
archive
.
getManifest
()).
isNotNull
(
);
URLClassLoader
loader
=
new
URLClassLoader
(
new
URL
[]
{
archive
.
getUrl
()
});
assertNotNull
(
loader
.
getResourceAsStream
(
"META-INF/spring/application.xml"
));
assertThat
(
loader
.
getResourceAsStream
(
"META-INF/spring/application.xml"
))
.
isNotNull
();
loader
.
close
();
}
...
...
@@ -180,4 +179,5 @@ public class ExplodedArchiveTests {
}
return
entries
;
}
}
spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/JarFileArchiveTests.java
View file @
00cfe1d0
...
...
@@ -29,12 +29,7 @@ import org.junit.rules.TemporaryFolder;
import
org.springframework.boot.loader.TestJarCreator
;
import
org.springframework.boot.loader.archive.Archive.Entry
;
import
static
org
.
hamcrest
.
Matchers
.
endsWith
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
not
;
import
static
org
.
hamcrest
.
Matchers
.
startsWith
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link JarFileArchive}.
...
...
@@ -67,28 +62,28 @@ public class JarFileArchiveTests {
@Test
public
void
getManifest
()
throws
Exception
{
assertThat
(
this
.
archive
.
getManifest
().
getMainAttributes
().
getValue
(
"Built-By"
)
,
equalTo
(
"j1"
)
);
assertThat
(
this
.
archive
.
getManifest
().
getMainAttributes
().
getValue
(
"Built-By"
)
)
.
isEqualTo
(
"j1"
);
}
@Test
public
void
getEntries
()
throws
Exception
{
Map
<
String
,
Archive
.
Entry
>
entries
=
getEntriesMap
(
this
.
archive
);
assertThat
(
entries
.
size
()
,
equalTo
(
10
)
);
assertThat
(
entries
.
size
()
).
isEqualTo
(
10
);
}
@Test
public
void
getUrl
()
throws
Exception
{
URL
url
=
this
.
archive
.
getUrl
();
assertThat
(
url
.
toString
()
,
equalTo
(
"jar:"
+
this
.
rootJarFileUrl
+
"!/"
)
);
assertThat
(
url
.
toString
()
).
isEqualTo
(
"jar:"
+
this
.
rootJarFileUrl
+
"!/"
);
}
@Test
public
void
getNestedArchive
()
throws
Exception
{
Entry
entry
=
getEntriesMap
(
this
.
archive
).
get
(
"nested.jar"
);
Archive
nested
=
this
.
archive
.
getNestedArchive
(
entry
);
assertThat
(
nested
.
getUrl
().
toString
()
,
equalTo
(
"jar:"
+
this
.
rootJarFileUrl
+
"!/nested.jar!/"
)
);
assertThat
(
nested
.
getUrl
().
toString
()
)
.
isEqualTo
(
"jar:"
+
this
.
rootJarFileUrl
+
"!/nested.jar!/"
);
}
@Test
...
...
@@ -96,8 +91,8 @@ public class JarFileArchiveTests {
setup
(
true
);
Entry
entry
=
getEntriesMap
(
this
.
archive
).
get
(
"nested.jar"
);
Archive
nested
=
this
.
archive
.
getNestedArchive
(
entry
);
assertThat
(
nested
.
getUrl
().
toString
()
,
startsWith
(
"file:"
)
);
assertThat
(
nested
.
getUrl
().
toString
()
,
endsWith
(
"/nested.jar"
)
);
assertThat
(
nested
.
getUrl
().
toString
()
).
startsWith
(
"file:"
);
assertThat
(
nested
.
getUrl
().
toString
()
).
endsWith
(
"/nested.jar"
);
}
@Test
...
...
@@ -108,7 +103,7 @@ public class JarFileArchiveTests {
setup
(
true
);
entry
=
getEntriesMap
(
this
.
archive
).
get
(
"nested.jar"
);
URL
secondNested
=
this
.
archive
.
getNestedArchive
(
entry
).
getUrl
();
assertThat
(
secondNested
,
is
(
not
(
equalTo
(
firstNested
)))
);
assertThat
(
secondNested
).
isNotEqualTo
(
firstNested
);
}
@Test
...
...
@@ -122,7 +117,7 @@ public class JarFileArchiveTests {
.
getNestedArchive
(
getEntriesMap
(
this
.
archive
).
get
(
"another-nested.jar"
))
.
getUrl
().
toURI
());
assertThat
(
nested
.
getParent
()
,
is
(
equalTo
(
anotherNested
.
getParent
())
));
assertThat
(
nested
.
getParent
()
).
isEqualTo
(
anotherNested
.
getParent
(
));
}
private
Map
<
String
,
Archive
.
Entry
>
getEntriesMap
(
Archive
archive
)
{
...
...
@@ -132,4 +127,5 @@ public class JarFileArchiveTests {
}
return
entries
;
}
}
spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/data/ByteArrayRandomAccessDataTests.java
View file @
00cfe1d0
...
...
@@ -16,13 +16,14 @@
package
org
.
springframework
.
boot
.
loader
.
data
;
import
java.io.InputStream
;
import
org.junit.Test
;
import
org.springframework.boot.loader.data.RandomAccessData.ResourceAccess
;
import
org.springframework.util.FileCopyUtils
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link ByteArrayRandomAccessData}.
...
...
@@ -35,9 +36,9 @@ public class ByteArrayRandomAccessDataTests {
public
void
testGetInputStream
()
throws
Exception
{
byte
[]
bytes
=
new
byte
[]
{
0
,
1
,
2
,
3
,
4
,
5
};
RandomAccessData
data
=
new
ByteArrayRandomAccessData
(
bytes
);
assertThat
(
FileCopyUtils
.
copyToByteArray
(
data
.
getInputStream
(
ResourceAccess
.
PER_READ
)),
equalTo
(
bytes
)
);
assertThat
(
data
.
getSize
()
,
equalTo
((
long
)
bytes
.
length
)
);
InputStream
inputStream
=
data
.
getInputStream
(
ResourceAccess
.
PER_READ
);
assertThat
(
FileCopyUtils
.
copyToByteArray
(
inputStream
)).
isEqualTo
(
bytes
);
assertThat
(
data
.
getSize
()
).
isEqualTo
(
bytes
.
length
);
}
@Test
...
...
@@ -45,10 +46,10 @@ public class ByteArrayRandomAccessDataTests {
byte
[]
bytes
=
new
byte
[]
{
0
,
1
,
2
,
3
,
4
,
5
};
RandomAccessData
data
=
new
ByteArrayRandomAccessData
(
bytes
);
data
=
data
.
getSubsection
(
1
,
4
).
getSubsection
(
1
,
2
);
assertThat
(
FileCopyUtils
.
copyToByteArray
(
data
.
getInputStream
(
ResourceAccess
.
PER_READ
)),
equalTo
(
new
byte
[]
{
2
,
3
}));
assertThat
(
data
.
getSize
(),
equalTo
(
2L
));
InputStream
inputStream
=
data
.
getInputStream
(
ResourceAccess
.
PER_READ
);
assertThat
(
FileCopyUtils
.
copyToByteArray
(
inputStream
))
.
isEqualTo
(
new
byte
[]
{
2
,
3
});
assertThat
(
data
.
getSize
()).
isEqualTo
(
2L
);
}
}
spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/data/RandomAccessDataFileTests.java
View file @
00cfe1d0
...
...
@@ -29,7 +29,6 @@ import java.util.concurrent.ExecutorService;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.Future
;
import
org.hamcrest.Matcher
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Rule
;
...
...
@@ -37,11 +36,9 @@ import org.junit.Test;
import
org.junit.rules.ExpectedException
;
import
org.junit.rules.TemporaryFolder
;
import
org.springframework.boot.loader.ByteArrayStartsWith
;
import
org.springframework.boot.loader.data.RandomAccessData.ResourceAccess
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link RandomAccessDataFile}.
...
...
@@ -118,7 +115,7 @@ public class RandomAccessDataFileTests {
@Test
public
void
inputStreamRead
()
throws
Exception
{
for
(
int
i
=
0
;
i
<=
255
;
i
++)
{
assertThat
(
this
.
inputStream
.
read
()
,
equalTo
(
i
)
);
assertThat
(
this
.
inputStream
.
read
()
).
isEqualTo
(
i
);
}
}
...
...
@@ -140,8 +137,8 @@ public class RandomAccessDataFileTests {
public
void
inputStreamReadBytes
()
throws
Exception
{
byte
[]
b
=
new
byte
[
256
];
int
amountRead
=
this
.
inputStream
.
read
(
b
);
assertThat
(
b
,
equalTo
(
BYTES
)
);
assertThat
(
amountRead
,
equalTo
(
256
)
);
assertThat
(
b
).
isEqualTo
(
BYTES
);
assertThat
(
amountRead
).
isEqualTo
(
256
);
}
@Test
...
...
@@ -149,54 +146,54 @@ public class RandomAccessDataFileTests {
byte
[]
b
=
new
byte
[
7
];
this
.
inputStream
.
skip
(
1
);
int
amountRead
=
this
.
inputStream
.
read
(
b
,
2
,
3
);
assertThat
(
b
,
equalTo
(
new
byte
[]
{
0
,
0
,
1
,
2
,
3
,
0
,
0
})
);
assertThat
(
amountRead
,
equalTo
(
3
)
);
assertThat
(
b
).
isEqualTo
(
new
byte
[]
{
0
,
0
,
1
,
2
,
3
,
0
,
0
}
);
assertThat
(
amountRead
).
isEqualTo
(
3
);
}
@Test
public
void
inputStreamReadMoreBytesThanAvailable
()
throws
Exception
{
byte
[]
b
=
new
byte
[
257
];
int
amountRead
=
this
.
inputStream
.
read
(
b
);
assertThat
(
b
,
startsWith
(
BYTES
)
);
assertThat
(
amountRead
,
equalTo
(
256
)
);
assertThat
(
b
).
startsWith
(
BYTES
);
assertThat
(
amountRead
).
isEqualTo
(
256
);
}
@Test
public
void
inputStreamReadPastEnd
()
throws
Exception
{
this
.
inputStream
.
skip
(
255
);
assertThat
(
this
.
inputStream
.
read
()
,
equalTo
(
0xFF
)
);
assertThat
(
this
.
inputStream
.
read
()
,
equalTo
(-
1
)
);
assertThat
(
this
.
inputStream
.
read
()
,
equalTo
(-
1
)
);
assertThat
(
this
.
inputStream
.
read
()
).
isEqualTo
(
0xFF
);
assertThat
(
this
.
inputStream
.
read
()
).
isEqualTo
(-
1
);
assertThat
(
this
.
inputStream
.
read
()
).
isEqualTo
(-
1
);
}
@Test
public
void
inputStreamReadZeroLength
()
throws
Exception
{
byte
[]
b
=
new
byte
[]
{
0x0F
};
int
amountRead
=
this
.
inputStream
.
read
(
b
,
0
,
0
);
assertThat
(
b
,
equalTo
(
new
byte
[]
{
0x0F
})
);
assertThat
(
amountRead
,
equalTo
(
0
)
);
assertThat
(
this
.
inputStream
.
read
()
,
equalTo
(
0
)
);
assertThat
(
b
).
isEqualTo
(
new
byte
[]
{
0x0F
}
);
assertThat
(
amountRead
).
isEqualTo
(
0
);
assertThat
(
this
.
inputStream
.
read
()
).
isEqualTo
(
0
);
}
@Test
public
void
inputStreamSkip
()
throws
Exception
{
long
amountSkipped
=
this
.
inputStream
.
skip
(
4
);
assertThat
(
this
.
inputStream
.
read
()
,
equalTo
(
4
)
);
assertThat
(
amountSkipped
,
equalTo
(
4L
)
);
assertThat
(
this
.
inputStream
.
read
()
).
isEqualTo
(
4
);
assertThat
(
amountSkipped
).
isEqualTo
(
4L
);
}
@Test
public
void
inputStreamSkipMoreThanAvailable
()
throws
Exception
{
long
amountSkipped
=
this
.
inputStream
.
skip
(
257
);
assertThat
(
this
.
inputStream
.
read
()
,
equalTo
(-
1
)
);
assertThat
(
amountSkipped
,
equalTo
(
256L
)
);
assertThat
(
this
.
inputStream
.
read
()
).
isEqualTo
(-
1
);
assertThat
(
amountSkipped
).
isEqualTo
(
256L
);
}
@Test
public
void
inputStreamSkipPastEnd
()
throws
Exception
{
this
.
inputStream
.
skip
(
256
);
long
amountSkipped
=
this
.
inputStream
.
skip
(
1
);
assertThat
(
amountSkipped
,
equalTo
(
0L
)
);
assertThat
(
amountSkipped
).
isEqualTo
(
0L
);
}
@Test
...
...
@@ -214,8 +211,8 @@ public class RandomAccessDataFileTests {
@Test
public
void
subsectionZeroLength
()
throws
Exception
{
RandomAccessData
subsection
=
this
.
file
.
getSubsection
(
0
,
0
);
assertThat
(
subsection
.
getInputStream
(
ResourceAccess
.
PER_READ
).
read
()
,
equalTo
(-
1
)
);
assertThat
(
subsection
.
getInputStream
(
ResourceAccess
.
PER_READ
).
read
()
)
.
isEqualTo
(-
1
);
}
@Test
...
...
@@ -235,16 +232,17 @@ public class RandomAccessDataFileTests {
@Test
public
void
subsection
()
throws
Exception
{
RandomAccessData
subsection
=
this
.
file
.
getSubsection
(
1
,
1
);
assertThat
(
subsection
.
getInputStream
(
ResourceAccess
.
PER_READ
).
read
(),
equalTo
(
1
));
assertThat
(
subsection
.
getInputStream
(
ResourceAccess
.
PER_READ
).
read
())
.
isEqualTo
(
1
);
}
@Test
public
void
inputStreamReadPastSubsection
()
throws
Exception
{
RandomAccessData
subsection
=
this
.
file
.
getSubsection
(
1
,
2
);
InputStream
inputStream
=
subsection
.
getInputStream
(
ResourceAccess
.
PER_READ
);
assertThat
(
inputStream
.
read
()
,
equalTo
(
1
)
);
assertThat
(
inputStream
.
read
()
,
equalTo
(
2
)
);
assertThat
(
inputStream
.
read
()
,
equalTo
(-
1
)
);
assertThat
(
inputStream
.
read
()
).
isEqualTo
(
1
);
assertThat
(
inputStream
.
read
()
).
isEqualTo
(
2
);
assertThat
(
inputStream
.
read
()
).
isEqualTo
(-
1
);
}
@Test
...
...
@@ -253,26 +251,26 @@ public class RandomAccessDataFileTests {
InputStream
inputStream
=
subsection
.
getInputStream
(
ResourceAccess
.
PER_READ
);
byte
[]
b
=
new
byte
[
3
];
int
amountRead
=
inputStream
.
read
(
b
);
assertThat
(
b
,
equalTo
(
new
byte
[]
{
1
,
2
,
0
})
);
assertThat
(
amountRead
,
equalTo
(
2
)
);
assertThat
(
b
).
isEqualTo
(
new
byte
[]
{
1
,
2
,
0
}
);
assertThat
(
amountRead
).
isEqualTo
(
2
);
}
@Test
public
void
inputStreamSkipPastSubsection
()
throws
Exception
{
RandomAccessData
subsection
=
this
.
file
.
getSubsection
(
1
,
2
);
InputStream
inputStream
=
subsection
.
getInputStream
(
ResourceAccess
.
PER_READ
);
assertThat
(
inputStream
.
skip
(
3
)
,
equalTo
(
2L
)
);
assertThat
(
inputStream
.
read
()
,
equalTo
(-
1
)
);
assertThat
(
inputStream
.
skip
(
3
)
).
isEqualTo
(
2L
);
assertThat
(
inputStream
.
read
()
).
isEqualTo
(-
1
);
}
@Test
public
void
inputStreamSkipNegative
()
throws
Exception
{
assertThat
(
this
.
inputStream
.
skip
(-
1
)
,
equalTo
(
0L
)
);
assertThat
(
this
.
inputStream
.
skip
(-
1
)
).
isEqualTo
(
0L
);
}
@Test
public
void
getFile
()
throws
Exception
{
assertThat
(
this
.
file
.
getFile
()
,
equalTo
(
this
.
tempFile
)
);
assertThat
(
this
.
file
.
getFile
()
).
isEqualTo
(
this
.
tempFile
);
}
@Test
...
...
@@ -294,7 +292,7 @@ public class RandomAccessDataFileTests {
}));
}
for
(
Future
<
Boolean
>
future
:
results
)
{
assertThat
(
future
.
get
()
,
equalTo
(
true
)
);
assertThat
(
future
.
get
()
).
isTrue
(
);
}
}
...
...
@@ -308,11 +306,7 @@ public class RandomAccessDataFileTests {
Field
filesField
=
filePool
.
getClass
().
getDeclaredField
(
"files"
);
filesField
.
setAccessible
(
true
);
Queue
<?>
queue
=
(
Queue
<?>)
filesField
.
get
(
filePool
);
assertThat
(
queue
.
size
(),
equalTo
(
0
));
}
private
static
Matcher
<?
super
byte
[]>
startsWith
(
byte
[]
bytes
)
{
return
new
ByteArrayStartsWith
(
bytes
);
assertThat
(
queue
.
size
()).
isEqualTo
(
0
);
}
}
spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/AsciiBytesTests.java
View file @
00cfe1d0
...
...
@@ -20,9 +20,7 @@ import org.junit.Rule;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
not
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link AsciiBytes}.
...
...
@@ -37,27 +35,27 @@ public class AsciiBytesTests {
@Test
public
void
createFromBytes
()
throws
Exception
{
AsciiBytes
bytes
=
new
AsciiBytes
(
new
byte
[]
{
65
,
66
});
assertThat
(
bytes
.
toString
()
,
equalTo
(
"AB"
)
);
assertThat
(
bytes
.
toString
()
).
isEqualTo
(
"AB"
);
}
@Test
public
void
createFromBytesWithOffset
()
throws
Exception
{
AsciiBytes
bytes
=
new
AsciiBytes
(
new
byte
[]
{
65
,
66
,
67
,
68
},
1
,
2
);
assertThat
(
bytes
.
toString
()
,
equalTo
(
"BC"
)
);
assertThat
(
bytes
.
toString
()
).
isEqualTo
(
"BC"
);
}
@Test
public
void
createFromString
()
throws
Exception
{
AsciiBytes
bytes
=
new
AsciiBytes
(
"AB"
);
assertThat
(
bytes
.
toString
()
,
equalTo
(
"AB"
)
);
assertThat
(
bytes
.
toString
()
).
isEqualTo
(
"AB"
);
}
@Test
public
void
length
()
throws
Exception
{
AsciiBytes
b1
=
new
AsciiBytes
(
new
byte
[]
{
65
,
66
});
AsciiBytes
b2
=
new
AsciiBytes
(
new
byte
[]
{
65
,
66
,
67
,
68
},
1
,
2
);
assertThat
(
b1
.
length
()
,
equalTo
(
2
)
);
assertThat
(
b2
.
length
()
,
equalTo
(
2
)
);
assertThat
(
b1
.
length
()
).
isEqualTo
(
2
);
assertThat
(
b2
.
length
()
).
isEqualTo
(
2
);
}
@Test
...
...
@@ -66,10 +64,10 @@ public class AsciiBytesTests {
AsciiBytes
ab
=
new
AsciiBytes
(
new
byte
[]
{
65
,
66
});
AsciiBytes
bc
=
new
AsciiBytes
(
new
byte
[]
{
65
,
66
,
67
},
1
,
2
);
AsciiBytes
abcd
=
new
AsciiBytes
(
new
byte
[]
{
65
,
66
,
67
,
68
});
assertThat
(
abc
.
startsWith
(
abc
)
,
equalTo
(
true
)
);
assertThat
(
abc
.
startsWith
(
ab
)
,
equalTo
(
true
)
);
assertThat
(
abc
.
startsWith
(
bc
)
,
equalTo
(
false
)
);
assertThat
(
abc
.
startsWith
(
abcd
)
,
equalTo
(
false
)
);
assertThat
(
abc
.
startsWith
(
abc
)
).
isTrue
(
);
assertThat
(
abc
.
startsWith
(
ab
)
).
isTrue
(
);
assertThat
(
abc
.
startsWith
(
bc
)
).
isFalse
(
);
assertThat
(
abc
.
startsWith
(
abcd
)
).
isFalse
(
);
}
@Test
...
...
@@ -78,20 +76,20 @@ public class AsciiBytesTests {
AsciiBytes
bc
=
new
AsciiBytes
(
new
byte
[]
{
65
,
66
,
67
},
1
,
2
);
AsciiBytes
ab
=
new
AsciiBytes
(
new
byte
[]
{
65
,
66
});
AsciiBytes
aabc
=
new
AsciiBytes
(
new
byte
[]
{
65
,
65
,
66
,
67
});
assertThat
(
abc
.
endsWith
(
abc
)
,
equalTo
(
true
)
);
assertThat
(
abc
.
endsWith
(
bc
)
,
equalTo
(
true
)
);
assertThat
(
abc
.
endsWith
(
ab
)
,
equalTo
(
false
)
);
assertThat
(
abc
.
endsWith
(
aabc
)
,
equalTo
(
false
)
);
assertThat
(
abc
.
endsWith
(
abc
)
).
isTrue
(
);
assertThat
(
abc
.
endsWith
(
bc
)
).
isTrue
(
);
assertThat
(
abc
.
endsWith
(
ab
)
).
isFalse
(
);
assertThat
(
abc
.
endsWith
(
aabc
)
).
isFalse
(
);
}
@Test
public
void
substringFromBeingIndex
()
throws
Exception
{
AsciiBytes
abcd
=
new
AsciiBytes
(
new
byte
[]
{
65
,
66
,
67
,
68
});
assertThat
(
abcd
.
substring
(
0
).
toString
()
,
equalTo
(
"ABCD"
)
);
assertThat
(
abcd
.
substring
(
1
).
toString
()
,
equalTo
(
"BCD"
)
);
assertThat
(
abcd
.
substring
(
2
).
toString
()
,
equalTo
(
"CD"
)
);
assertThat
(
abcd
.
substring
(
3
).
toString
()
,
equalTo
(
"D"
)
);
assertThat
(
abcd
.
substring
(
4
).
toString
()
,
equalTo
(
""
)
);
assertThat
(
abcd
.
substring
(
0
).
toString
()
).
isEqualTo
(
"ABCD"
);
assertThat
(
abcd
.
substring
(
1
).
toString
()
).
isEqualTo
(
"BCD"
);
assertThat
(
abcd
.
substring
(
2
).
toString
()
).
isEqualTo
(
"CD"
);
assertThat
(
abcd
.
substring
(
3
).
toString
()
).
isEqualTo
(
"D"
);
assertThat
(
abcd
.
substring
(
4
).
toString
()
).
isEqualTo
(
""
);
this
.
thrown
.
expect
(
IndexOutOfBoundsException
.
class
);
abcd
.
substring
(
5
);
}
...
...
@@ -99,10 +97,10 @@ public class AsciiBytesTests {
@Test
public
void
substring
()
throws
Exception
{
AsciiBytes
abcd
=
new
AsciiBytes
(
new
byte
[]
{
65
,
66
,
67
,
68
});
assertThat
(
abcd
.
substring
(
0
,
4
).
toString
()
,
equalTo
(
"ABCD"
)
);
assertThat
(
abcd
.
substring
(
1
,
3
).
toString
()
,
equalTo
(
"BC"
)
);
assertThat
(
abcd
.
substring
(
3
,
4
).
toString
()
,
equalTo
(
"D"
)
);
assertThat
(
abcd
.
substring
(
3
,
3
).
toString
()
,
equalTo
(
""
)
);
assertThat
(
abcd
.
substring
(
0
,
4
).
toString
()
).
isEqualTo
(
"ABCD"
);
assertThat
(
abcd
.
substring
(
1
,
3
).
toString
()
).
isEqualTo
(
"BC"
);
assertThat
(
abcd
.
substring
(
3
,
4
).
toString
()
).
isEqualTo
(
"D"
);
assertThat
(
abcd
.
substring
(
3
,
3
).
toString
()
).
isEqualTo
(
""
);
this
.
thrown
.
expect
(
IndexOutOfBoundsException
.
class
);
abcd
.
substring
(
3
,
5
);
}
...
...
@@ -111,16 +109,16 @@ public class AsciiBytesTests {
public
void
appendString
()
throws
Exception
{
AsciiBytes
bc
=
new
AsciiBytes
(
new
byte
[]
{
65
,
66
,
67
,
68
},
1
,
2
);
AsciiBytes
appended
=
bc
.
append
(
"D"
);
assertThat
(
bc
.
toString
()
,
equalTo
(
"BC"
)
);
assertThat
(
appended
.
toString
()
,
equalTo
(
"BCD"
)
);
assertThat
(
bc
.
toString
()
).
isEqualTo
(
"BC"
);
assertThat
(
appended
.
toString
()
).
isEqualTo
(
"BCD"
);
}
@Test
public
void
appendBytes
()
throws
Exception
{
AsciiBytes
bc
=
new
AsciiBytes
(
new
byte
[]
{
65
,
66
,
67
,
68
},
1
,
2
);
AsciiBytes
appended
=
bc
.
append
(
new
byte
[]
{
68
});
assertThat
(
bc
.
toString
()
,
equalTo
(
"BC"
)
);
assertThat
(
appended
.
toString
()
,
equalTo
(
"BCD"
)
);
assertThat
(
bc
.
toString
()
).
isEqualTo
(
"BC"
);
assertThat
(
appended
.
toString
()
).
isEqualTo
(
"BCD"
);
}
@Test
...
...
@@ -130,28 +128,28 @@ public class AsciiBytesTests {
AsciiBytes
bc_substring
=
new
AsciiBytes
(
new
byte
[]
{
65
,
66
,
67
,
68
})
.
substring
(
1
,
3
);
AsciiBytes
bc_string
=
new
AsciiBytes
(
"BC"
);
assertThat
(
bc
.
hashCode
()
,
equalTo
(
bc
.
hashCode
()
));
assertThat
(
bc
.
hashCode
()
,
equalTo
(
bc_substring
.
hashCode
()
));
assertThat
(
bc
.
hashCode
()
,
equalTo
(
bc_string
.
hashCode
()
));
assertThat
(
bc
,
equalTo
(
bc
)
);
assertThat
(
bc
,
equalTo
(
bc_substring
)
);
assertThat
(
bc
,
equalTo
(
bc_string
)
);
assertThat
(
bc
.
hashCode
()
,
not
(
equalTo
(
abcd
.
hashCode
())
));
assertThat
(
bc
,
not
(
equalTo
(
abcd
))
);
assertThat
(
bc
.
hashCode
()
).
isEqualTo
(
bc
.
hashCode
(
));
assertThat
(
bc
.
hashCode
()
).
isEqualTo
(
bc_substring
.
hashCode
(
));
assertThat
(
bc
.
hashCode
()
).
isEqualTo
(
bc_string
.
hashCode
(
));
assertThat
(
bc
).
isEqualTo
(
bc
);
assertThat
(
bc
).
isEqualTo
(
bc_substring
);
assertThat
(
bc
).
isEqualTo
(
bc_string
);
assertThat
(
bc
.
hashCode
()
).
isNotEqualTo
(
abcd
.
hashCode
(
));
assertThat
(
bc
).
isNotEqualTo
(
abcd
);
}
@Test
public
void
hashCodeSameAsString
()
throws
Exception
{
String
s
=
"abcABC123xyz!"
;
AsciiBytes
a
=
new
AsciiBytes
(
s
);
assertThat
(
s
.
hashCode
()
,
equalTo
(
a
.
hashCode
()
));
assertThat
(
s
.
hashCode
()
).
isEqualTo
(
a
.
hashCode
(
));
}
@Test
public
void
hashCodeSameAsStringWithSpecial
()
throws
Exception
{
String
s
=
"special/\u00EB.dat"
;
AsciiBytes
a
=
new
AsciiBytes
(
s
);
assertThat
(
s
.
hashCode
()
,
equalTo
(
a
.
hashCode
()
));
assertThat
(
s
.
hashCode
()
).
isEqualTo
(
a
.
hashCode
(
));
}
}
spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/CentralDirectoryParserTests.java
View file @
00cfe1d0
...
...
@@ -31,8 +31,7 @@ import org.springframework.boot.loader.TestJarCreator;
import
org.springframework.boot.loader.data.RandomAccessData
;
import
org.springframework.boot.loader.data.RandomAccessDataFile
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Matchers
.
anyInt
;
import
static
org
.
mockito
.
Mockito
.
atLeastOnce
;
...
...
@@ -62,7 +61,7 @@ public class CentralDirectoryParserTests {
@Test
public
void
visitsInOrder
()
throws
Exception
{
CentralDirectoryVisitor
visitor
=
mock
(
CentralDirectoryVisitor
.
class
);
CentralDirectoryVisitor
visitor
=
mock
(
Test
CentralDirectoryVisitor
.
class
);
CentralDirectoryParser
parser
=
new
CentralDirectoryParser
();
parser
.
addVisitor
(
visitor
);
parser
.
parse
(
this
.
jarData
,
false
);
...
...
@@ -81,17 +80,17 @@ public class CentralDirectoryParserTests {
parser
.
addVisitor
(
collector
);
parser
.
parse
(
this
.
jarData
,
false
);
Iterator
<
CentralDirectoryFileHeader
>
headers
=
collector
.
getHeaders
().
iterator
();
assertThat
(
headers
.
next
().
getName
().
toString
()
,
equalTo
(
"META-INF/"
)
);
assertThat
(
headers
.
next
().
getName
().
toString
()
,
equalTo
(
"META-INF/MANIFEST.MF"
)
);
assertThat
(
headers
.
next
().
getName
().
toString
()
,
equalTo
(
"1.dat"
)
);
assertThat
(
headers
.
next
().
getName
().
toString
()
,
equalTo
(
"2.dat"
)
);
assertThat
(
headers
.
next
().
getName
().
toString
()
,
equalTo
(
"d/"
)
);
assertThat
(
headers
.
next
().
getName
().
toString
()
,
equalTo
(
"d/9.dat"
)
);
assertThat
(
headers
.
next
().
getName
().
toString
()
,
equalTo
(
"special/"
)
);
assertThat
(
headers
.
next
().
getName
().
toString
()
,
equalTo
(
"special/\u00EB.dat"
)
);
assertThat
(
headers
.
next
().
getName
().
toString
()
,
equalTo
(
"nested.jar"
)
);
assertThat
(
headers
.
next
().
getName
().
toString
()
,
equalTo
(
"another-nested.jar"
)
);
assertThat
(
headers
.
hasNext
()
,
equalTo
(
false
)
);
assertThat
(
headers
.
next
().
getName
().
toString
()
).
isEqualTo
(
"META-INF/"
);
assertThat
(
headers
.
next
().
getName
().
toString
()
).
isEqualTo
(
"META-INF/MANIFEST.MF"
);
assertThat
(
headers
.
next
().
getName
().
toString
()
).
isEqualTo
(
"1.dat"
);
assertThat
(
headers
.
next
().
getName
().
toString
()
).
isEqualTo
(
"2.dat"
);
assertThat
(
headers
.
next
().
getName
().
toString
()
).
isEqualTo
(
"d/"
);
assertThat
(
headers
.
next
().
getName
().
toString
()
).
isEqualTo
(
"d/9.dat"
);
assertThat
(
headers
.
next
().
getName
().
toString
()
).
isEqualTo
(
"special/"
);
assertThat
(
headers
.
next
().
getName
().
toString
()
).
isEqualTo
(
"special/\u00EB.dat"
);
assertThat
(
headers
.
next
().
getName
().
toString
()
).
isEqualTo
(
"nested.jar"
);
assertThat
(
headers
.
next
().
getName
().
toString
()
).
isEqualTo
(
"another-nested.jar"
);
assertThat
(
headers
.
hasNext
()
).
isFalse
(
);
}
private
static
class
Collector
implements
CentralDirectoryVisitor
{
...
...
@@ -119,4 +118,8 @@ public class CentralDirectoryParserTests {
}
public
interface
TestCentralDirectoryVisitor
extends
CentralDirectoryVisitor
{
}
}
spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/JarFileTests.java
View file @
00cfe1d0
...
...
@@ -41,14 +41,7 @@ import org.springframework.boot.loader.data.RandomAccessDataFile;
import
org.springframework.util.FileCopyUtils
;
import
org.springframework.util.StreamUtils
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
greaterThan
;
import
static
org
.
hamcrest
.
Matchers
.
instanceOf
;
import
static
org
.
hamcrest
.
Matchers
.
notNullValue
;
import
static
org
.
hamcrest
.
Matchers
.
nullValue
;
import
static
org
.
hamcrest
.
Matchers
.
sameInstance
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
spy
;
import
static
org
.
mockito
.
Mockito
.
verify
;
...
...
@@ -82,21 +75,21 @@ public class JarFileTests {
// Sanity checks to see how the default jar file operates
java
.
util
.
jar
.
JarFile
jarFile
=
new
java
.
util
.
jar
.
JarFile
(
this
.
rootJarFile
);
Enumeration
<
java
.
util
.
jar
.
JarEntry
>
entries
=
jarFile
.
entries
();
assertThat
(
entries
.
nextElement
().
getName
()
,
equalTo
(
"META-INF/"
)
);
assertThat
(
entries
.
nextElement
().
getName
()
,
equalTo
(
"META-INF/MANIFEST.MF"
)
);
assertThat
(
entries
.
nextElement
().
getName
()
,
equalTo
(
"1.dat"
)
);
assertThat
(
entries
.
nextElement
().
getName
()
,
equalTo
(
"2.dat"
)
);
assertThat
(
entries
.
nextElement
().
getName
()
,
equalTo
(
"d/"
)
);
assertThat
(
entries
.
nextElement
().
getName
()
,
equalTo
(
"d/9.dat"
)
);
assertThat
(
entries
.
nextElement
().
getName
()
,
equalTo
(
"special/"
)
);
assertThat
(
entries
.
nextElement
().
getName
()
,
equalTo
(
"special/\u00EB.dat"
)
);
assertThat
(
entries
.
nextElement
().
getName
()
,
equalTo
(
"nested.jar"
)
);
assertThat
(
entries
.
nextElement
().
getName
()
,
equalTo
(
"another-nested.jar"
)
);
assertThat
(
entries
.
hasMoreElements
()
,
equalTo
(
false
)
);
assertThat
(
entries
.
nextElement
().
getName
()
).
isEqualTo
(
"META-INF/"
);
assertThat
(
entries
.
nextElement
().
getName
()
).
isEqualTo
(
"META-INF/MANIFEST.MF"
);
assertThat
(
entries
.
nextElement
().
getName
()
).
isEqualTo
(
"1.dat"
);
assertThat
(
entries
.
nextElement
().
getName
()
).
isEqualTo
(
"2.dat"
);
assertThat
(
entries
.
nextElement
().
getName
()
).
isEqualTo
(
"d/"
);
assertThat
(
entries
.
nextElement
().
getName
()
).
isEqualTo
(
"d/9.dat"
);
assertThat
(
entries
.
nextElement
().
getName
()
).
isEqualTo
(
"special/"
);
assertThat
(
entries
.
nextElement
().
getName
()
).
isEqualTo
(
"special/\u00EB.dat"
);
assertThat
(
entries
.
nextElement
().
getName
()
).
isEqualTo
(
"nested.jar"
);
assertThat
(
entries
.
nextElement
().
getName
()
).
isEqualTo
(
"another-nested.jar"
);
assertThat
(
entries
.
hasMoreElements
()
).
isFalse
(
);
URL
jarUrl
=
new
URL
(
"jar:"
+
this
.
rootJarFile
.
toURI
()
+
"!/"
);
URLClassLoader
urlClassLoader
=
new
URLClassLoader
(
new
URL
[]
{
jarUrl
});
assertThat
(
urlClassLoader
.
getResource
(
"special/\u00EB.dat"
)
,
notNullValue
()
);
assertThat
(
urlClassLoader
.
getResource
(
"d/9.dat"
)
,
notNullValue
()
);
assertThat
(
urlClassLoader
.
getResource
(
"special/\u00EB.dat"
)
).
isNotNull
(
);
assertThat
(
urlClassLoader
.
getResource
(
"d/9.dat"
)
).
isNotNull
(
);
jarFile
.
close
();
urlClassLoader
.
close
();
}
...
...
@@ -104,79 +97,79 @@ public class JarFileTests {
@Test
public
void
createFromFile
()
throws
Exception
{
JarFile
jarFile
=
new
JarFile
(
this
.
rootJarFile
);
assertThat
(
jarFile
.
getName
()
,
notNullValue
(
String
.
class
)
);
assertThat
(
jarFile
.
getName
()
).
isNotNull
(
);
jarFile
.
close
();
}
@Test
public
void
getManifest
()
throws
Exception
{
assertThat
(
this
.
jarFile
.
getManifest
().
getMainAttributes
().
getValue
(
"Built-By"
)
,
equalTo
(
"j1"
)
);
assertThat
(
this
.
jarFile
.
getManifest
().
getMainAttributes
().
getValue
(
"Built-By"
)
)
.
isEqualTo
(
"j1"
);
}
@Test
public
void
getManifestEntry
()
throws
Exception
{
ZipEntry
entry
=
this
.
jarFile
.
getJarEntry
(
"META-INF/MANIFEST.MF"
);
Manifest
manifest
=
new
Manifest
(
this
.
jarFile
.
getInputStream
(
entry
));
assertThat
(
manifest
.
getMainAttributes
().
getValue
(
"Built-By"
)
,
equalTo
(
"j1"
)
);
assertThat
(
manifest
.
getMainAttributes
().
getValue
(
"Built-By"
)
).
isEqualTo
(
"j1"
);
}
@Test
public
void
getEntries
()
throws
Exception
{
Enumeration
<
java
.
util
.
jar
.
JarEntry
>
entries
=
this
.
jarFile
.
entries
();
assertThat
(
entries
.
nextElement
().
getName
()
,
equalTo
(
"META-INF/"
)
);
assertThat
(
entries
.
nextElement
().
getName
()
,
equalTo
(
"META-INF/MANIFEST.MF"
)
);
assertThat
(
entries
.
nextElement
().
getName
()
,
equalTo
(
"1.dat"
)
);
assertThat
(
entries
.
nextElement
().
getName
()
,
equalTo
(
"2.dat"
)
);
assertThat
(
entries
.
nextElement
().
getName
()
,
equalTo
(
"d/"
)
);
assertThat
(
entries
.
nextElement
().
getName
()
,
equalTo
(
"d/9.dat"
)
);
assertThat
(
entries
.
nextElement
().
getName
()
,
equalTo
(
"special/"
)
);
assertThat
(
entries
.
nextElement
().
getName
()
,
equalTo
(
"special/\u00EB.dat"
)
);
assertThat
(
entries
.
nextElement
().
getName
()
,
equalTo
(
"nested.jar"
)
);
assertThat
(
entries
.
nextElement
().
getName
()
,
equalTo
(
"another-nested.jar"
)
);
assertThat
(
entries
.
hasMoreElements
()
,
equalTo
(
false
)
);
assertThat
(
entries
.
nextElement
().
getName
()
).
isEqualTo
(
"META-INF/"
);
assertThat
(
entries
.
nextElement
().
getName
()
).
isEqualTo
(
"META-INF/MANIFEST.MF"
);
assertThat
(
entries
.
nextElement
().
getName
()
).
isEqualTo
(
"1.dat"
);
assertThat
(
entries
.
nextElement
().
getName
()
).
isEqualTo
(
"2.dat"
);
assertThat
(
entries
.
nextElement
().
getName
()
).
isEqualTo
(
"d/"
);
assertThat
(
entries
.
nextElement
().
getName
()
).
isEqualTo
(
"d/9.dat"
);
assertThat
(
entries
.
nextElement
().
getName
()
).
isEqualTo
(
"special/"
);
assertThat
(
entries
.
nextElement
().
getName
()
).
isEqualTo
(
"special/\u00EB.dat"
);
assertThat
(
entries
.
nextElement
().
getName
()
).
isEqualTo
(
"nested.jar"
);
assertThat
(
entries
.
nextElement
().
getName
()
).
isEqualTo
(
"another-nested.jar"
);
assertThat
(
entries
.
hasMoreElements
()
).
isFalse
(
);
}
@Test
public
void
getSpecialResourceViaClassLoader
()
throws
Exception
{
URLClassLoader
urlClassLoader
=
new
URLClassLoader
(
new
URL
[]
{
this
.
jarFile
.
getUrl
()
});
assertThat
(
urlClassLoader
.
getResource
(
"special/\u00EB.dat"
)
,
notNullValue
()
);
assertThat
(
urlClassLoader
.
getResource
(
"special/\u00EB.dat"
)
).
isNotNull
(
);
urlClassLoader
.
close
();
}
@Test
public
void
getJarEntry
()
throws
Exception
{
java
.
util
.
jar
.
JarEntry
entry
=
this
.
jarFile
.
getJarEntry
(
"1.dat"
);
assertThat
(
entry
,
notNullValue
(
ZipEntry
.
class
)
);
assertThat
(
entry
.
getName
()
,
equalTo
(
"1.dat"
)
);
assertThat
(
entry
).
isNotNull
(
);
assertThat
(
entry
.
getName
()
).
isEqualTo
(
"1.dat"
);
}
@Test
public
void
getInputStream
()
throws
Exception
{
InputStream
inputStream
=
this
.
jarFile
.
getInputStream
(
this
.
jarFile
.
getEntry
(
"1.dat"
));
assertThat
(
inputStream
.
available
()
,
equalTo
(
1
)
);
assertThat
(
inputStream
.
read
()
,
equalTo
(
1
)
);
assertThat
(
inputStream
.
available
()
,
equalTo
(
0
)
);
assertThat
(
inputStream
.
read
()
,
equalTo
(-
1
)
);
assertThat
(
inputStream
.
available
()
).
isEqualTo
(
1
);
assertThat
(
inputStream
.
read
()
).
isEqualTo
(
1
);
assertThat
(
inputStream
.
available
()
).
isEqualTo
(
0
);
assertThat
(
inputStream
.
read
()
).
isEqualTo
(-
1
);
}
@Test
public
void
getName
()
throws
Exception
{
assertThat
(
this
.
jarFile
.
getName
()
,
equalTo
(
this
.
rootJarFile
.
getPath
()
));
assertThat
(
this
.
jarFile
.
getName
()
).
isEqualTo
(
this
.
rootJarFile
.
getPath
(
));
}
@Test
public
void
getSize
()
throws
Exception
{
assertThat
(
this
.
jarFile
.
size
()
,
equalTo
((
int
)
this
.
rootJarFile
.
length
()
));
assertThat
(
this
.
jarFile
.
size
()
).
isEqualTo
((
int
)
this
.
rootJarFile
.
length
(
));
}
@Test
public
void
getEntryTime
()
throws
Exception
{
java
.
util
.
jar
.
JarFile
jdkJarFile
=
new
java
.
util
.
jar
.
JarFile
(
this
.
rootJarFile
);
assertThat
(
this
.
jarFile
.
getEntry
(
"META-INF/MANIFEST.MF"
).
getTime
()
,
equalTo
(
jdkJarFile
.
getEntry
(
"META-INF/MANIFEST.MF"
).
getTime
()
));
assertThat
(
this
.
jarFile
.
getEntry
(
"META-INF/MANIFEST.MF"
).
getTime
()
)
.
isEqualTo
(
jdkJarFile
.
getEntry
(
"META-INF/MANIFEST.MF"
).
getTime
(
));
jdkJarFile
.
close
();
}
...
...
@@ -192,36 +185,36 @@ public class JarFileTests {
@Test
public
void
getUrl
()
throws
Exception
{
URL
url
=
this
.
jarFile
.
getUrl
();
assertThat
(
url
.
toString
()
,
equalTo
(
"jar:"
+
this
.
rootJarFile
.
toURI
()
+
"!/"
)
);
assertThat
(
url
.
toString
()
).
isEqualTo
(
"jar:"
+
this
.
rootJarFile
.
toURI
()
+
"!/"
);
JarURLConnection
jarURLConnection
=
(
JarURLConnection
)
url
.
openConnection
();
assertThat
(
jarURLConnection
.
getJarFile
()
,
sameInstance
(
this
.
jarFile
)
);
assertThat
(
jarURLConnection
.
getJarEntry
()
,
nullValue
()
);
assertThat
(
jarURLConnection
.
getContentLength
()
,
greaterThan
(
1
)
);
assertThat
(
jarURLConnection
.
getContent
()
,
sameInstance
((
Object
)
this
.
jarFile
)
);
assertThat
(
jarURLConnection
.
getContentType
()
,
equalTo
(
"x-java/jar"
)
);
assertThat
(
jarURLConnection
.
getJarFileURL
().
toURI
()
,
equalTo
(
this
.
rootJarFile
.
toURI
()
));
assertThat
(
jarURLConnection
.
getJarFile
()
).
isSameAs
(
this
.
jarFile
);
assertThat
(
jarURLConnection
.
getJarEntry
()
).
isNull
(
);
assertThat
(
jarURLConnection
.
getContentLength
()
).
isGreaterThan
(
1
);
assertThat
(
jarURLConnection
.
getContent
()
).
isSameAs
(
this
.
jarFile
);
assertThat
(
jarURLConnection
.
getContentType
()
).
isEqualTo
(
"x-java/jar"
);
assertThat
(
jarURLConnection
.
getJarFileURL
().
toURI
()
)
.
isEqualTo
(
this
.
rootJarFile
.
toURI
(
));
}
@Test
public
void
createEntryUrl
()
throws
Exception
{
URL
url
=
new
URL
(
this
.
jarFile
.
getUrl
(),
"1.dat"
);
assertThat
(
url
.
toString
()
,
equalTo
(
"jar:"
+
this
.
rootJarFile
.
toURI
()
+
"!/1.dat"
)
);
assertThat
(
url
.
toString
()
)
.
isEqualTo
(
"jar:"
+
this
.
rootJarFile
.
toURI
()
+
"!/1.dat"
);
JarURLConnection
jarURLConnection
=
(
JarURLConnection
)
url
.
openConnection
();
assertThat
(
jarURLConnection
.
getJarFile
()
,
sameInstance
(
this
.
jarFile
)
);
assertThat
(
jarURLConnection
.
getJarEntry
()
,
sameInstance
(
this
.
jarFile
.
getJarEntry
(
"1.dat"
)
));
assertThat
(
jarURLConnection
.
getContentLength
()
,
equalTo
(
1
)
);
assertThat
(
jarURLConnection
.
getContent
()
,
instanceOf
(
InputStream
.
class
)
);
assertThat
(
jarURLConnection
.
getContentType
()
,
equalTo
(
"content/unknown"
)
);
assertThat
(
jarURLConnection
.
getJarFile
()
).
isSameAs
(
this
.
jarFile
);
assertThat
(
jarURLConnection
.
getJarEntry
()
)
.
isSameAs
(
this
.
jarFile
.
getJarEntry
(
"1.dat"
));
assertThat
(
jarURLConnection
.
getContentLength
()
).
isEqualTo
(
1
);
assertThat
(
jarURLConnection
.
getContent
()
).
isInstanceOf
(
InputStream
.
class
);
assertThat
(
jarURLConnection
.
getContentType
()
).
isEqualTo
(
"content/unknown"
);
}
@Test
public
void
getMissingEntryUrl
()
throws
Exception
{
URL
url
=
new
URL
(
this
.
jarFile
.
getUrl
(),
"missing.dat"
);
assertThat
(
url
.
toString
()
,
equalTo
(
"jar:"
+
this
.
rootJarFile
.
toURI
()
+
"!/missing.dat"
)
);
assertThat
(
url
.
toString
()
)
.
isEqualTo
(
"jar:"
+
this
.
rootJarFile
.
toURI
()
+
"!/missing.dat"
);
this
.
thrown
.
expect
(
FileNotFoundException
.
class
);
((
JarURLConnection
)
url
.
openConnection
()).
getJarEntry
();
}
...
...
@@ -239,8 +232,8 @@ public class JarFileTests {
URL
url
=
new
URL
(
this
.
jarFile
.
getUrl
(),
"1.dat"
);
url
.
openConnection
();
InputStream
stream
=
url
.
openStream
();
assertThat
(
stream
.
read
()
,
equalTo
(
1
)
);
assertThat
(
stream
.
read
()
,
equalTo
(-
1
)
);
assertThat
(
stream
.
read
()
).
isEqualTo
(
1
);
assertThat
(
stream
.
read
()
).
isEqualTo
(-
1
);
}
@Test
...
...
@@ -249,25 +242,25 @@ public class JarFileTests {
.
getNestedJarFile
(
this
.
jarFile
.
getEntry
(
"nested.jar"
));
Enumeration
<
java
.
util
.
jar
.
JarEntry
>
entries
=
nestedJarFile
.
entries
();
assertThat
(
entries
.
nextElement
().
getName
()
,
equalTo
(
"META-INF/"
)
);
assertThat
(
entries
.
nextElement
().
getName
()
,
equalTo
(
"META-INF/MANIFEST.MF"
)
);
assertThat
(
entries
.
nextElement
().
getName
()
,
equalTo
(
"3.dat"
)
);
assertThat
(
entries
.
nextElement
().
getName
()
,
equalTo
(
"4.dat"
)
);
assertThat
(
entries
.
nextElement
().
getName
()
,
equalTo
(
"\u00E4.dat"
)
);
assertThat
(
entries
.
hasMoreElements
()
,
equalTo
(
false
)
);
assertThat
(
entries
.
nextElement
().
getName
()
).
isEqualTo
(
"META-INF/"
);
assertThat
(
entries
.
nextElement
().
getName
()
).
isEqualTo
(
"META-INF/MANIFEST.MF"
);
assertThat
(
entries
.
nextElement
().
getName
()
).
isEqualTo
(
"3.dat"
);
assertThat
(
entries
.
nextElement
().
getName
()
).
isEqualTo
(
"4.dat"
);
assertThat
(
entries
.
nextElement
().
getName
()
).
isEqualTo
(
"\u00E4.dat"
);
assertThat
(
entries
.
hasMoreElements
()
).
isFalse
(
);
InputStream
inputStream
=
nestedJarFile
.
getInputStream
(
nestedJarFile
.
getEntry
(
"3.dat"
));
assertThat
(
inputStream
.
read
()
,
equalTo
(
3
)
);
assertThat
(
inputStream
.
read
()
,
equalTo
(-
1
)
);
assertThat
(
inputStream
.
read
()
).
isEqualTo
(
3
);
assertThat
(
inputStream
.
read
()
).
isEqualTo
(-
1
);
URL
url
=
nestedJarFile
.
getUrl
();
assertThat
(
url
.
toString
()
,
equalTo
(
"jar:"
+
this
.
rootJarFile
.
toURI
()
+
"!/nested.jar!/"
)
);
assertThat
(
url
.
toString
()
)
.
isEqualTo
(
"jar:"
+
this
.
rootJarFile
.
toURI
()
+
"!/nested.jar!/"
);
JarURLConnection
conn
=
(
JarURLConnection
)
url
.
openConnection
();
assertThat
(
conn
.
getJarFile
()
,
sameInstance
(
nestedJarFile
)
);
assertThat
(
conn
.
getJarFileURL
().
toString
()
,
equalTo
(
"jar:"
+
this
.
rootJarFile
.
toURI
()
+
"!/nested.jar"
)
);
assertThat
(
conn
.
getJarFile
()
).
isSameAs
(
nestedJarFile
);
assertThat
(
conn
.
getJarFileURL
().
toString
()
)
.
isEqualTo
(
"jar:"
+
this
.
rootJarFile
.
toURI
()
+
"!/nested.jar"
);
}
@Test
...
...
@@ -276,18 +269,18 @@ public class JarFileTests {
.
getNestedJarFile
(
this
.
jarFile
.
getEntry
(
"d/"
));
Enumeration
<
java
.
util
.
jar
.
JarEntry
>
entries
=
nestedJarFile
.
entries
();
assertThat
(
entries
.
nextElement
().
getName
()
,
equalTo
(
"9.dat"
)
);
assertThat
(
entries
.
hasMoreElements
()
,
equalTo
(
false
)
);
assertThat
(
entries
.
nextElement
().
getName
()
).
isEqualTo
(
"9.dat"
);
assertThat
(
entries
.
hasMoreElements
()
).
isFalse
(
);
InputStream
inputStream
=
nestedJarFile
.
getInputStream
(
nestedJarFile
.
getEntry
(
"9.dat"
));
assertThat
(
inputStream
.
read
()
,
equalTo
(
9
)
);
assertThat
(
inputStream
.
read
()
,
equalTo
(-
1
)
);
assertThat
(
inputStream
.
read
()
).
isEqualTo
(
9
);
assertThat
(
inputStream
.
read
()
).
isEqualTo
(-
1
);
URL
url
=
nestedJarFile
.
getUrl
();
assertThat
(
url
.
toString
()
,
equalTo
(
"jar:"
+
this
.
rootJarFile
.
toURI
()
+
"!/d!/"
)
);
assertThat
(((
JarURLConnection
)
url
.
openConnection
()).
getJarFile
()
,
sameInstance
(
nestedJarFile
)
);
assertThat
(
url
.
toString
()
).
isEqualTo
(
"jar:"
+
this
.
rootJarFile
.
toURI
()
+
"!/d!/"
);
assertThat
(((
JarURLConnection
)
url
.
openConnection
()).
getJarFile
()
)
.
isSameAs
(
nestedJarFile
);
}
@Test
...
...
@@ -295,11 +288,11 @@ public class JarFileTests {
JarFile
nestedJarFile
=
this
.
jarFile
.
getNestedJarFile
(
this
.
jarFile
.
getEntry
(
"nested.jar"
));
URL
url
=
nestedJarFile
.
getJarEntry
(
"3.dat"
).
getUrl
();
assertThat
(
url
.
toString
()
,
equalTo
(
"jar:"
+
this
.
rootJarFile
.
toURI
()
+
"!/nested.jar!/3.dat"
)
);
assertThat
(
url
.
toString
()
)
.
isEqualTo
(
"jar:"
+
this
.
rootJarFile
.
toURI
()
+
"!/nested.jar!/3.dat"
);
InputStream
inputStream
=
url
.
openStream
();
assertThat
(
inputStream
,
notNullValue
()
);
assertThat
(
inputStream
.
read
()
,
equalTo
(
3
)
);
assertThat
(
inputStream
).
isNotNull
(
);
assertThat
(
inputStream
.
read
()
).
isEqualTo
(
3
);
}
@Test
...
...
@@ -307,15 +300,15 @@ public class JarFileTests {
JarFile
.
registerUrlProtocolHandler
();
String
spec
=
"jar:"
+
this
.
rootJarFile
.
toURI
()
+
"!/nested.jar!/3.dat"
;
URL
url
=
new
URL
(
spec
);
assertThat
(
url
.
toString
()
,
equalTo
(
spec
)
);
assertThat
(
url
.
toString
()
).
isEqualTo
(
spec
);
InputStream
inputStream
=
url
.
openStream
();
assertThat
(
inputStream
,
notNullValue
()
);
assertThat
(
inputStream
.
read
()
,
equalTo
(
3
)
);
assertThat
(
inputStream
).
isNotNull
(
);
assertThat
(
inputStream
.
read
()
).
isEqualTo
(
3
);
JarURLConnection
connection
=
(
JarURLConnection
)
url
.
openConnection
();
assertThat
(
connection
.
getURL
().
toString
()
,
equalTo
(
spec
)
);
assertThat
(
connection
.
getJarFileURL
().
toString
()
,
equalTo
(
"jar:"
+
this
.
rootJarFile
.
toURI
()
+
"!/nested.jar"
)
);
assertThat
(
connection
.
getEntryName
()
,
equalTo
(
"3.dat"
)
);
assertThat
(
connection
.
getURL
().
toString
()
).
isEqualTo
(
spec
);
assertThat
(
connection
.
getJarFileURL
().
toString
()
)
.
isEqualTo
(
"jar:"
+
this
.
rootJarFile
.
toURI
()
+
"!/nested.jar"
);
assertThat
(
connection
.
getEntryName
()
).
isEqualTo
(
"3.dat"
);
}
@Test
...
...
@@ -323,38 +316,37 @@ public class JarFileTests {
JarFile
.
registerUrlProtocolHandler
();
String
spec
=
"jar:"
+
this
.
rootJarFile
.
toURI
()
+
"!/2.dat"
;
URL
url
=
new
URL
(
spec
);
assertThat
(
url
.
toString
()
,
equalTo
(
spec
)
);
assertThat
(
url
.
toString
()
).
isEqualTo
(
spec
);
InputStream
inputStream
=
url
.
openStream
();
assertThat
(
inputStream
,
notNullValue
()
);
assertThat
(
inputStream
.
read
()
,
equalTo
(
2
)
);
assertThat
(
inputStream
).
isNotNull
(
);
assertThat
(
inputStream
.
read
()
).
isEqualTo
(
2
);
JarURLConnection
connection
=
(
JarURLConnection
)
url
.
openConnection
();
assertThat
(
connection
.
getURL
().
toString
(),
equalTo
(
spec
));
assertThat
(
connection
.
getJarFileURL
().
toURI
(),
equalTo
(
this
.
rootJarFile
.
toURI
()));
assertThat
(
connection
.
getEntryName
(),
equalTo
(
"2.dat"
));
assertThat
(
connection
.
getURL
().
toString
()).
isEqualTo
(
spec
);
assertThat
(
connection
.
getJarFileURL
().
toURI
())
.
isEqualTo
(
this
.
rootJarFile
.
toURI
());
assertThat
(
connection
.
getEntryName
()).
isEqualTo
(
"2.dat"
);
}
@Test
public
void
getDirectoryInputStream
()
throws
Exception
{
InputStream
inputStream
=
this
.
jarFile
.
getInputStream
(
this
.
jarFile
.
getEntry
(
"d/"
));
assertThat
(
inputStream
,
notNullValue
()
);
assertThat
(
inputStream
.
read
()
,
equalTo
(-
1
)
);
assertThat
(
inputStream
).
isNotNull
(
);
assertThat
(
inputStream
.
read
()
).
isEqualTo
(-
1
);
}
@Test
public
void
getDirectoryInputStreamWithoutSlash
()
throws
Exception
{
InputStream
inputStream
=
this
.
jarFile
.
getInputStream
(
this
.
jarFile
.
getEntry
(
"d"
));
assertThat
(
inputStream
,
notNullValue
()
);
assertThat
(
inputStream
.
read
()
,
equalTo
(-
1
)
);
assertThat
(
inputStream
).
isNotNull
(
);
assertThat
(
inputStream
.
read
()
).
isEqualTo
(-
1
);
}
@Test
public
void
sensibleToString
()
throws
Exception
{
assertThat
(
this
.
jarFile
.
toString
(),
equalTo
(
this
.
rootJarFile
.
getPath
()));
assertThat
(
this
.
jarFile
.
getNestedJarFile
(
this
.
jarFile
.
getEntry
(
"nested.jar"
))
.
toString
(),
equalTo
(
this
.
rootJarFile
.
getPath
()
+
"!/nested.jar"
));
assertThat
(
this
.
jarFile
.
toString
()).
isEqualTo
(
this
.
rootJarFile
.
getPath
());
assertThat
(
this
.
jarFile
.
getNestedJarFile
(
this
.
jarFile
.
getEntry
(
"nested.jar"
))
.
toString
()).
isEqualTo
(
this
.
rootJarFile
.
getPath
()
+
"!/nested.jar"
);
}
@Test
...
...
@@ -367,7 +359,7 @@ public class JarFileTests {
signedJarFile
=
entry
;
}
}
assert
NotNull
(
signedJarFile
);
assert
That
(
signedJarFile
).
isNotNull
(
);
java
.
util
.
jar
.
JarFile
jarFile
=
new
JarFile
(
new
File
(
signedJarFile
));
jarFile
.
getManifest
();
Enumeration
<
JarEntry
>
jarEntries
=
jarFile
.
entries
();
...
...
@@ -378,8 +370,7 @@ public class JarFileTests {
inputStream
.
close
();
if
(!
jarEntry
.
getName
().
startsWith
(
"META-INF"
)
&&
!
jarEntry
.
isDirectory
()
&&
!
jarEntry
.
getName
().
endsWith
(
"TigerDigest.class"
))
{
assertNotNull
(
"Missing cert "
+
jarEntry
.
getName
(),
jarEntry
.
getCertificates
());
assertThat
(
jarEntry
.
getCertificates
()).
isNotNull
();
}
}
jarFile
.
close
();
...
...
spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/util/SystemPropertyUtilsTests.java
View file @
00cfe1d0
...
...
@@ -20,9 +20,11 @@ import org.junit.AfterClass;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link SystemPropertyUtils}.
*
* @author Dave Syer
*/
public
class
SystemPropertyUtilsTests
{
...
...
@@ -39,23 +41,25 @@ public class SystemPropertyUtilsTests {
@Test
public
void
testVanillaPlaceholder
()
{
assert
Equals
(
"bar"
,
SystemPropertyUtils
.
resolvePlaceholders
(
"${foo}"
)
);
assert
That
(
SystemPropertyUtils
.
resolvePlaceholders
(
"${foo}"
)).
isEqualTo
(
"bar"
);
}
@Test
public
void
testDefaultValue
()
{
assertEquals
(
"foo"
,
SystemPropertyUtils
.
resolvePlaceholders
(
"${bar:foo}"
));
assertThat
(
SystemPropertyUtils
.
resolvePlaceholders
(
"${bar:foo}"
))
.
isEqualTo
(
"foo"
);
}
@Test
public
void
testNestedPlaceholder
()
{
assert
Equals
(
"foo"
,
SystemPropertyUtils
.
resolvePlaceholders
(
"${bar:${spam:foo}}"
)
);
assert
That
(
SystemPropertyUtils
.
resolvePlaceholders
(
"${bar:${spam:foo}}"
))
.
isEqualTo
(
"foo"
);
}
@Test
public
void
testEnvVar
()
{
assertEquals
(
System
.
getenv
(
"LANG"
),
SystemPropertyUtils
.
getProperty
(
"lang"
));
assertThat
(
SystemPropertyUtils
.
getProperty
(
"lang"
))
.
isEqualTo
(
System
.
getenv
(
"LANG"
));
}
}
spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ArtifactsLibrariesTests.java
View file @
00cfe1d0
...
...
@@ -36,8 +36,7 @@ import org.springframework.boot.loader.tools.Library;
import
org.springframework.boot.loader.tools.LibraryCallback
;
import
org.springframework.boot.loader.tools.LibraryScope
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
times
;
...
...
@@ -80,9 +79,9 @@ public class ArtifactsLibrariesTests {
this
.
libs
.
doWithLibraries
(
this
.
callback
);
verify
(
this
.
callback
).
library
(
this
.
libraryCaptor
.
capture
());
Library
library
=
this
.
libraryCaptor
.
getValue
();
assertThat
(
library
.
getFile
()
,
equalTo
(
this
.
file
)
);
assertThat
(
library
.
getScope
()
,
equalTo
(
LibraryScope
.
COMPILE
)
);
assertThat
(
library
.
isUnpackRequired
()
,
equalTo
(
false
)
);
assertThat
(
library
.
getFile
()
).
isEqualTo
(
this
.
file
);
assertThat
(
library
.
getScope
()
).
isEqualTo
(
LibraryScope
.
COMPILE
);
assertThat
(
library
.
isUnpackRequired
()
).
isFalse
(
);
}
@Test
...
...
@@ -98,7 +97,7 @@ public class ArtifactsLibrariesTests {
mock
(
Log
.
class
));
this
.
libs
.
doWithLibraries
(
this
.
callback
);
verify
(
this
.
callback
).
library
(
this
.
libraryCaptor
.
capture
());
assertThat
(
this
.
libraryCaptor
.
getValue
().
isUnpackRequired
()
,
equalTo
(
true
)
);
assertThat
(
this
.
libraryCaptor
.
getValue
().
isUnpackRequired
()
).
isTrue
(
);
}
@Test
...
...
@@ -117,8 +116,8 @@ public class ArtifactsLibrariesTests {
this
.
libs
=
new
ArtifactsLibraries
(
this
.
artifacts
,
null
,
mock
(
Log
.
class
));
this
.
libs
.
doWithLibraries
(
this
.
callback
);
verify
(
this
.
callback
,
times
(
2
)).
library
(
this
.
libraryCaptor
.
capture
());
assertThat
(
this
.
libraryCaptor
.
getAllValues
().
get
(
0
).
getName
()
,
equalTo
(
"g1-a"
)
);
assertThat
(
this
.
libraryCaptor
.
getAllValues
().
get
(
1
).
getName
()
,
equalTo
(
"g2-a"
)
);
assertThat
(
this
.
libraryCaptor
.
getAllValues
().
get
(
0
).
getName
()
).
isEqualTo
(
"g1-a"
);
assertThat
(
this
.
libraryCaptor
.
getAllValues
().
get
(
1
).
getName
()
).
isEqualTo
(
"g2-a"
);
}
}
spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/DependencyFilterMojoTests.java
View file @
00cfe1d0
...
...
@@ -27,8 +27,7 @@ import org.apache.maven.plugin.MojoExecutionException;
import
org.apache.maven.plugin.MojoFailureException
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertSame
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
...
...
@@ -48,8 +47,8 @@ public class DependencyFilterMojoTests {
Set
<
Artifact
>
artifacts
=
mojo
.
filterDependencies
(
createArtifact
(
"com.foo"
,
"one"
),
createArtifact
(
"com.foo"
,
"two"
),
createArtifact
(
"com.bar"
,
"exclude-id"
),
artifact
);
assert
Equals
(
"wrong filtering of artifacts"
,
1
,
artifacts
.
size
()
);
assert
Same
(
"Wrong filtered artifact"
,
artifact
,
artifacts
.
iterator
().
next
()
);
assert
That
(
artifacts
).
hasSize
(
1
);
assert
That
(
artifacts
.
iterator
().
next
()).
isSameAs
(
artifact
);
}
@Test
...
...
@@ -61,8 +60,8 @@ public class DependencyFilterMojoTests {
Set
<
Artifact
>
artifacts
=
mojo
.
filterDependencies
(
createArtifact
(
"com.foo"
,
"one"
),
createArtifact
(
"com.foo"
,
"two"
),
artifact
);
assert
Equals
(
"wrong filtering of artifacts"
,
1
,
artifacts
.
size
()
);
assert
Same
(
"Wrong filtered artifact"
,
artifact
,
artifacts
.
iterator
().
next
()
);
assert
That
(
artifacts
).
hasSize
(
1
);
assert
That
(
artifacts
.
iterator
().
next
()).
isSameAs
(
artifact
);
}
private
Artifact
createArtifact
(
String
groupId
,
String
artifactId
)
{
...
...
spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ExcludeFilterTests.java
View file @
00cfe1d0
...
...
@@ -25,8 +25,7 @@ import org.apache.maven.artifact.Artifact;
import
org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertSame
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
...
...
@@ -36,7 +35,7 @@ import static org.mockito.Mockito.mock;
* @author Stephane Nicoll
* @author David Turanski
*/
@SuppressWarnings
(
"rawtypes"
)
@SuppressWarnings
(
{
"rawtypes"
,
"unchecked"
}
)
public
class
ExcludeFilterTests
{
@Test
...
...
@@ -45,7 +44,7 @@ public class ExcludeFilterTests {
Arrays
.
asList
(
createExclude
(
"com.foo"
,
"bar"
)));
Set
result
=
filter
.
filter
(
Collections
.
singleton
(
createArtifact
(
"com.foo"
,
"bar"
)));
assert
Equals
(
"Should have been filtered"
,
0
,
result
.
size
()
);
assert
That
(
result
).
isEmpty
(
);
}
@Test
...
...
@@ -54,8 +53,8 @@ public class ExcludeFilterTests {
Arrays
.
asList
(
createExclude
(
"com.foo"
,
"bar"
)));
Artifact
artifact
=
createArtifact
(
"com.baz"
,
"bar"
);
Set
result
=
filter
.
filter
(
Collections
.
singleton
(
artifact
));
assert
Equals
(
"Should not have been filtered"
,
1
,
result
.
size
()
);
assert
Same
(
artifact
,
result
.
iterator
().
next
()
);
assert
That
(
result
).
hasSize
(
1
);
assert
That
(
result
.
iterator
().
next
()).
isSameAs
(
artifact
);
}
@Test
...
...
@@ -64,8 +63,8 @@ public class ExcludeFilterTests {
Arrays
.
asList
(
createExclude
(
"com.foo"
,
"bar"
)));
Artifact
artifact
=
createArtifact
(
"com.foo"
,
"biz"
);
Set
result
=
filter
.
filter
(
Collections
.
singleton
(
artifact
));
assert
Equals
(
"Should not have been filtered"
,
1
,
result
.
size
()
);
assert
Same
(
artifact
,
result
.
iterator
().
next
()
);
assert
That
(
result
).
hasSize
(
1
);
assert
That
(
result
.
iterator
().
next
()).
isSameAs
(
artifact
);
}
@Test
...
...
@@ -74,7 +73,7 @@ public class ExcludeFilterTests {
Arrays
.
asList
(
createExclude
(
"com.foo"
,
"bar"
,
"jdk5"
)));
Set
result
=
filter
.
filter
(
Collections
.
singleton
(
createArtifact
(
"com.foo"
,
"bar"
,
"jdk5"
)));
assert
Equals
(
"Should have been filtered"
,
0
,
result
.
size
()
);
assert
That
(
result
).
isEmpty
(
);
}
@Test
...
...
@@ -83,8 +82,8 @@ public class ExcludeFilterTests {
Arrays
.
asList
(
createExclude
(
"com.foo"
,
"bar"
,
"jdk5"
)));
Artifact
artifact
=
createArtifact
(
"com.foo"
,
"bar"
);
Set
result
=
filter
.
filter
(
Collections
.
singleton
(
artifact
));
assert
Equals
(
"Should not have been filtered"
,
1
,
result
.
size
()
);
assert
Same
(
artifact
,
result
.
iterator
().
next
()
);
assert
That
(
result
).
hasSize
(
1
);
assert
That
(
result
.
iterator
().
next
()).
isSameAs
(
artifact
);
}
@Test
...
...
@@ -93,8 +92,8 @@ public class ExcludeFilterTests {
Arrays
.
asList
(
createExclude
(
"com.foo"
,
"bar"
,
"jdk5"
)));
Artifact
artifact
=
createArtifact
(
"com.foo"
,
"bar"
,
"jdk6"
);
Set
result
=
filter
.
filter
(
Collections
.
singleton
(
artifact
));
assert
Equals
(
"Should not have been filtered"
,
1
,
result
.
size
()
);
assert
Same
(
artifact
,
result
.
iterator
().
next
()
);
assert
That
(
result
).
hasSize
(
1
);
assert
That
(
result
.
iterator
().
next
()).
isSameAs
(
artifact
);
}
@Test
...
...
@@ -108,8 +107,8 @@ public class ExcludeFilterTests {
Artifact
anotherAcme
=
createArtifact
(
"org.acme"
,
"another-app"
);
artifacts
.
add
(
anotherAcme
);
Set
result
=
filter
.
filter
(
artifacts
);
assert
Equals
(
"Two dependencies should have been filtered"
,
1
,
result
.
size
()
);
assert
Same
(
anotherAcme
,
result
.
iterator
().
next
()
);
assert
That
(
result
).
hasSize
(
1
);
assert
That
(
result
.
iterator
().
next
()).
isSameAs
(
anotherAcme
);
}
private
Exclude
createExclude
(
String
groupId
,
String
artifactId
)
{
...
...
spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/IncludeFilterTests.java
View file @
00cfe1d0
...
...
@@ -25,8 +25,7 @@ import org.apache.maven.artifact.Artifact;
import
org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertSame
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
...
...
@@ -35,7 +34,7 @@ import static org.mockito.Mockito.mock;
*
* @author David Turanski
*/
@SuppressWarnings
(
"rawtypes"
)
@SuppressWarnings
(
{
"rawtypes"
,
"unchecked"
}
)
public
class
IncludeFilterTests
{
@Test
...
...
@@ -44,8 +43,8 @@ public class IncludeFilterTests {
Arrays
.
asList
(
createInclude
(
"com.foo"
,
"bar"
)));
Artifact
artifact
=
createArtifact
(
"com.foo"
,
"bar"
);
Set
result
=
filter
.
filter
(
Collections
.
singleton
(
artifact
));
assert
Equals
(
"Should not have been filtered"
,
1
,
result
.
size
()
);
assert
Same
(
artifact
,
result
.
iterator
().
next
()
);
assert
That
(
result
).
hasSize
(
1
);
assert
That
(
result
.
iterator
().
next
()).
isSameAs
(
artifact
);
}
@Test
...
...
@@ -54,7 +53,7 @@ public class IncludeFilterTests {
Arrays
.
asList
(
createInclude
(
"com.foo"
,
"bar"
)));
Artifact
artifact
=
createArtifact
(
"com.baz"
,
"bar"
);
Set
result
=
filter
.
filter
(
Collections
.
singleton
(
artifact
));
assert
Equals
(
"Should have been filtered"
,
0
,
result
.
size
()
);
assert
That
(
result
).
isEmpty
(
);
}
@Test
...
...
@@ -63,7 +62,7 @@ public class IncludeFilterTests {
Arrays
.
asList
(
createInclude
(
"com.foo"
,
"bar"
)));
Artifact
artifact
=
createArtifact
(
"com.foo"
,
"biz"
);
Set
result
=
filter
.
filter
(
Collections
.
singleton
(
artifact
));
assert
Equals
(
"Should have been filtered"
,
0
,
result
.
size
()
);
assert
That
(
result
).
isEmpty
(
);
}
@Test
...
...
@@ -72,8 +71,8 @@ public class IncludeFilterTests {
Arrays
.
asList
(
createInclude
(
"com.foo"
,
"bar"
,
"jdk5"
)));
Artifact
artifact
=
createArtifact
(
"com.foo"
,
"bar"
,
"jdk5"
);
Set
result
=
filter
.
filter
(
Collections
.
singleton
(
artifact
));
assert
Equals
(
"Should not have been filtered"
,
1
,
result
.
size
()
);
assert
Same
(
artifact
,
result
.
iterator
().
next
()
);
assert
That
(
result
).
hasSize
(
1
);
assert
That
(
result
.
iterator
().
next
()).
isSameAs
(
artifact
);
}
@Test
...
...
@@ -82,7 +81,7 @@ public class IncludeFilterTests {
Arrays
.
asList
(
createInclude
(
"com.foo"
,
"bar"
,
"jdk5"
)));
Artifact
artifact
=
createArtifact
(
"com.foo"
,
"bar"
);
Set
result
=
filter
.
filter
(
Collections
.
singleton
(
artifact
));
assert
Equals
(
"Should have been filtered"
,
0
,
result
.
size
()
);
assert
That
(
result
).
isEmpty
(
);
}
@Test
...
...
@@ -91,7 +90,7 @@ public class IncludeFilterTests {
Arrays
.
asList
(
createInclude
(
"com.foo"
,
"bar"
,
"jdk5"
)));
Artifact
artifact
=
createArtifact
(
"com.foo"
,
"bar"
,
"jdk6"
);
Set
result
=
filter
.
filter
(
Collections
.
singleton
(
artifact
));
assert
Equals
(
"Should have been filtered"
,
0
,
result
.
size
()
);
assert
That
(
result
).
isEmpty
(
);
}
@Test
...
...
@@ -105,7 +104,7 @@ public class IncludeFilterTests {
Artifact
anotherAcme
=
createArtifact
(
"org.acme"
,
"another-app"
);
artifacts
.
add
(
anotherAcme
);
Set
result
=
filter
.
filter
(
artifacts
);
assert
Equals
(
"One dependency should have been filtered"
,
2
,
result
.
size
()
);
assert
That
(
result
).
hasSize
(
2
);
}
private
Include
createInclude
(
String
groupId
,
String
artifactId
)
{
...
...
spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/PropertiesMergingResourceTransformerTests.java
View file @
00cfe1d0
...
...
@@ -22,10 +22,7 @@ import java.util.jar.JarOutputStream;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link PropertiesMergingResourceTransformer}.
...
...
@@ -38,10 +35,10 @@ public class PropertiesMergingResourceTransformerTests {
@Test
public
void
testProcess
()
throws
Exception
{
assert
False
(
this
.
transformer
.
hasTransformedResource
()
);
assert
That
(
this
.
transformer
.
hasTransformedResource
()).
isFalse
(
);
this
.
transformer
.
processResource
(
"foo"
,
new
ByteArrayInputStream
(
"foo=bar"
.
getBytes
()),
null
);
assertT
rue
(
this
.
transformer
.
hasTransformedResource
()
);
assertT
hat
(
this
.
transformer
.
hasTransformedResource
()).
isTrue
(
);
}
@Test
...
...
@@ -50,7 +47,7 @@ public class PropertiesMergingResourceTransformerTests {
new
ByteArrayInputStream
(
"foo=bar"
.
getBytes
()),
null
);
this
.
transformer
.
processResource
(
"bar"
,
new
ByteArrayInputStream
(
"foo=spam"
.
getBytes
()),
null
);
assert
Equals
(
"bar,spam"
,
this
.
transformer
.
getData
().
getProperty
(
"foo"
)
);
assert
That
(
this
.
transformer
.
getData
().
getProperty
(
"foo"
)).
isEqualTo
(
"bar,spam"
);
}
@Test
...
...
@@ -63,8 +60,8 @@ public class PropertiesMergingResourceTransformerTests {
this
.
transformer
.
modifyOutputStream
(
os
);
os
.
flush
();
os
.
close
();
assert
NotNull
(
out
.
toByteArray
()
);
assertT
rue
(
out
.
toByteArray
().
length
>
0
);
assert
That
(
out
.
toByteArray
()).
isNotNull
(
);
assertT
hat
(
out
.
toByteArray
().
length
>
0
).
isTrue
(
);
}
}
spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/RunArgumentsTests.java
View file @
00cfe1d0
...
...
@@ -18,8 +18,7 @@ package org.springframework.boot.maven;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link RunArguments}.
...
...
@@ -31,48 +30,48 @@ public class RunArgumentsTests {
@Test
public
void
parseNull
()
{
String
[]
args
=
parseArgs
(
null
);
assert
NotNull
(
args
);
assert
Equals
(
0
,
args
.
length
);
assert
That
(
args
).
isNotNull
(
);
assert
That
(
args
.
length
).
isEqualTo
(
0
);
}
@Test
public
void
parseEmpty
()
{
String
[]
args
=
parseArgs
(
" "
);
assert
NotNull
(
args
);
assert
Equals
(
0
,
args
.
length
);
assert
That
(
args
).
isNotNull
(
);
assert
That
(
args
.
length
).
isEqualTo
(
0
);
}
@Test
public
void
parseDebugFlags
()
{
String
[]
args
=
parseArgs
(
"-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
);
assert
Equals
(
2
,
args
.
length
);
assert
Equals
(
"-Xdebug"
,
args
[
0
]
);
assert
Equals
(
"-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
,
args
[
1
]
);
assert
That
(
args
.
length
).
isEqualTo
(
2
);
assert
That
(
args
[
0
]).
isEqualTo
(
"-Xdebug"
);
assert
That
(
args
[
1
]).
isEqualTo
(
"-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
);
}
@Test
public
void
parseWithExtraSpaces
()
{
String
[]
args
=
parseArgs
(
" -Dfoo=bar -Dfoo2=bar2 "
);
assert
Equals
(
2
,
args
.
length
);
assert
Equals
(
"-Dfoo=bar"
,
args
[
0
]
);
assert
Equals
(
"-Dfoo2=bar2"
,
args
[
1
]
);
assert
That
(
args
.
length
).
isEqualTo
(
2
);
assert
That
(
args
[
0
]).
isEqualTo
(
"-Dfoo=bar"
);
assert
That
(
args
[
1
]).
isEqualTo
(
"-Dfoo2=bar2"
);
}
@Test
public
void
parseWithNewLinesAndTabs
()
{
String
[]
args
=
parseArgs
(
" -Dfoo=bar \n"
+
"\t\t -Dfoo2=bar2 "
);
assert
Equals
(
2
,
args
.
length
);
assert
Equals
(
"-Dfoo=bar"
,
args
[
0
]
);
assert
Equals
(
"-Dfoo2=bar2"
,
args
[
1
]
);
assert
That
(
args
.
length
).
isEqualTo
(
2
);
assert
That
(
args
[
0
]).
isEqualTo
(
"-Dfoo=bar"
);
assert
That
(
args
[
1
]).
isEqualTo
(
"-Dfoo2=bar2"
);
}
@Test
public
void
quoteHandledProperly
()
{
String
[]
args
=
parseArgs
(
"-Dvalue=\"My Value\" "
);
assert
Equals
(
1
,
args
.
length
);
assert
Equals
(
"-Dvalue=My Value"
,
args
[
0
]
);
assert
That
(
args
.
length
).
isEqualTo
(
1
);
assert
That
(
args
[
0
]).
isEqualTo
(
"-Dvalue=My Value"
);
}
private
String
[]
parseArgs
(
String
args
)
{
...
...
spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/Verify.java
View file @
00cfe1d0
...
...
@@ -28,11 +28,7 @@ import java.util.zip.ZipFile;
import
org.springframework.util.FileCopyUtils
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Verification utility for use with maven-invoker-plugin verification scripts.
...
...
@@ -107,13 +103,15 @@ public final class Verify {
}
public
void
assertHasNonUnpackEntry
(
String
entryName
)
{
assertTrue
(
"Entry starting with "
+
entryName
+
" was an UNPACK entry"
,
hasNonUnpackEntry
(
entryName
));
assertThat
(
hasNonUnpackEntry
(
entryName
))
.
as
(
"Entry starting with "
+
entryName
+
" was an UNPACK entry"
)
.
isTrue
();
}
public
void
assertHasUnpackEntry
(
String
entryName
)
{
assertTrue
(
"Entry starting with "
+
entryName
+
" was not an UNPACK entry"
,
hasUnpackEntry
(
entryName
));
assertThat
(
hasUnpackEntry
(
entryName
))
.
as
(
"Entry starting with "
+
entryName
+
" was not an UNPACK entry"
)
.
isTrue
();
}
private
boolean
hasNonUnpackEntry
(
String
entryName
)
{
...
...
@@ -167,22 +165,21 @@ public final class Verify {
public
void
verify
(
boolean
executable
,
String
...
scriptContents
)
throws
Exception
{
assertTrue
(
"Archive missing"
,
this
.
file
.
exists
());
assertTrue
(
"Archive not a file"
,
this
.
file
.
isFile
());
assertThat
(
this
.
file
).
exists
().
isFile
();
if
(
scriptContents
.
length
>
0
&&
executable
)
{
String
contents
=
new
String
(
FileCopyUtils
.
copyToByteArray
(
this
.
file
));
contents
=
contents
.
substring
(
0
,
contents
.
indexOf
(
new
String
(
new
byte
[]
{
0x50
,
0x4b
,
0x03
,
0x04
})));
for
(
String
content
:
scriptContents
)
{
assertThat
(
contents
,
containsString
(
content
)
);
assertThat
(
contents
).
contains
(
content
);
}
}
if
(!
executable
)
{
String
contents
=
new
String
(
FileCopyUtils
.
copyToByteArray
(
this
.
file
));
assertT
rue
(
"Is executable"
,
contents
.
startsWith
(
new
String
(
new
byte
[]
{
0x50
,
0x4b
,
0x03
,
0x04
}))
)
;
assertT
hat
(
contents
).
as
(
"Is executable"
)
.
startsWith
(
new
String
(
new
byte
[]
{
0x50
,
0x4b
,
0x03
,
0x04
}));
}
ZipFile
zipFile
=
new
ZipFile
(
this
.
file
);
...
...
@@ -224,18 +221,21 @@ public final class Verify {
verifier
.
assertHasEntryNameStartingWith
(
"lib/spring-context"
);
verifier
.
assertHasEntryNameStartingWith
(
"lib/spring-core"
);
verifier
.
assertHasEntryNameStartingWith
(
"lib/javax.servlet-api-3"
);
assertTrue
(
"Unpacked launcher classes"
,
verifier
.
hasEntry
(
"org/"
+
"springframework/boot/loader/JarLauncher.class"
));
assertTrue
(
"Own classes"
,
verifier
.
hasEntry
(
"org/"
+
"test/SampleApplication.class"
));
assertThat
(
verifier
.
hasEntry
(
"org/"
+
"springframework/boot/loader/JarLauncher.class"
))
.
as
(
"Unpacked launcher classes"
).
isTrue
();
assertThat
(
verifier
.
hasEntry
(
"org/"
+
"test/SampleApplication.class"
))
.
as
(
"Own classes"
).
isTrue
();
}
@Override
protected
void
verifyManifest
(
Manifest
manifest
)
throws
Exception
{
assertEquals
(
"org.springframework.boot.loader.JarLauncher"
,
manifest
.
getMainAttributes
().
getValue
(
"Main-Class"
));
assertEquals
(
this
.
main
,
manifest
.
getMainAttributes
().
getValue
(
"Start-Class"
));
assertEquals
(
"Foo"
,
manifest
.
getMainAttributes
().
getValue
(
"Not-Used"
));
assertThat
(
manifest
.
getMainAttributes
().
getValue
(
"Main-Class"
))
.
isEqualTo
(
"org.springframework.boot.loader.JarLauncher"
);
assertThat
(
manifest
.
getMainAttributes
().
getValue
(
"Start-Class"
))
.
isEqualTo
(
this
.
main
);
assertThat
(
manifest
.
getMainAttributes
().
getValue
(
"Not-Used"
))
.
isEqualTo
(
"Foo"
);
}
}
...
...
@@ -252,20 +252,23 @@ public final class Verify {
verifier
.
assertHasEntryNameStartingWith
(
"WEB-INF/lib/spring-core"
);
verifier
.
assertHasEntryNameStartingWith
(
"WEB-INF/lib-provided/javax.servlet-api-3"
);
assertTrue
(
"Unpacked launcher classes"
,
verifier
.
hasEntry
(
"org/"
+
"springframework/boot/loader/JarLauncher.class"
));
assertTrue
(
"Own classes"
,
verifier
.
hasEntry
(
"WEB-INF/classes/org/"
+
"test/SampleApplication.class"
));
assertTrue
(
"Web content"
,
verifier
.
hasEntry
(
"index.html"
));
assertThat
(
verifier
.
hasEntry
(
"org/"
+
"springframework/boot/loader/JarLauncher.class"
))
.
as
(
"Unpacked launcher classes"
).
isTrue
();
assertThat
(
verifier
.
hasEntry
(
"WEB-INF/classes/org/"
+
"test/SampleApplication.class"
))
.
as
(
"Own classes"
).
isTrue
();
assertThat
(
verifier
.
hasEntry
(
"index.html"
)).
as
(
"Web content"
).
isTrue
();
}
@Override
protected
void
verifyManifest
(
Manifest
manifest
)
throws
Exception
{
assertEquals
(
"org.springframework.boot.loader.WarLauncher"
,
manifest
.
getMainAttributes
().
getValue
(
"Main-Class"
));
assertEquals
(
"org.test.SampleApplication"
,
manifest
.
getMainAttributes
().
getValue
(
"Start-Class"
));
assertEquals
(
"Foo"
,
manifest
.
getMainAttributes
().
getValue
(
"Not-Used"
));
assertThat
(
manifest
.
getMainAttributes
().
getValue
(
"Main-Class"
))
.
isEqualTo
(
"org.springframework.boot.loader.WarLauncher"
);
assertThat
(
manifest
.
getMainAttributes
().
getValue
(
"Start-Class"
))
.
isEqualTo
(
"org.test.SampleApplication"
);
assertThat
(
manifest
.
getMainAttributes
().
getValue
(
"Not-Used"
))
.
isEqualTo
(
"Foo"
);
}
}
...
...
@@ -277,11 +280,12 @@ public final class Verify {
@Override
protected
void
verifyManifest
(
Manifest
manifest
)
throws
Exception
{
assertEquals
(
"org.springframework.boot.loader.PropertiesLauncher"
,
manifest
.
getMainAttributes
().
getValue
(
"Main-Class"
));
assertEquals
(
"org.test.SampleApplication"
,
manifest
.
getMainAttributes
().
getValue
(
"Start-Class"
));
assertEquals
(
"Foo"
,
manifest
.
getMainAttributes
().
getValue
(
"Not-Used"
));
assertThat
(
manifest
.
getMainAttributes
().
getValue
(
"Main-Class"
))
.
isEqualTo
(
"org.springframework.boot.loader.PropertiesLauncher"
);
assertThat
(
manifest
.
getMainAttributes
().
getValue
(
"Start-Class"
))
.
isEqualTo
(
"org.test.SampleApplication"
);
assertThat
(
manifest
.
getMainAttributes
().
getValue
(
"Not-Used"
))
.
isEqualTo
(
"Foo"
);
}
}
...
...
@@ -297,10 +301,11 @@ public final class Verify {
verifier
.
assertHasEntryNameStartingWith
(
"lib/spring-context"
);
verifier
.
assertHasEntryNameStartingWith
(
"lib/spring-core"
);
verifier
.
assertHasNoEntryNameStartingWith
(
"lib/javax.servlet-api-3"
);
assertFalse
(
"Unpacked launcher classes"
,
verifier
.
hasEntry
(
"org/"
+
"springframework/boot/loader/JarLauncher.class"
));
assertTrue
(
"Own classes"
,
verifier
.
hasEntry
(
"org/"
+
"test/SampleModule.class"
));
assertThat
(
verifier
.
hasEntry
(
"org/"
+
"springframework/boot/loader/JarLauncher.class"
))
.
as
(
"Unpacked launcher classes"
).
isFalse
();
assertThat
(
verifier
.
hasEntry
(
"org/"
+
"test/SampleModule.class"
))
.
as
(
"Own classes"
).
isTrue
();
}
@Override
...
...
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