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
962a5985
Commit
962a5985
authored
Feb 06, 2016
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use AssertJ in spring-boot-cli
See gh-5083
parent
00cfe1d0
Changes
32
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
32 changed files
with
479 additions
and
576 deletions
+479
-576
ClassLoaderIntegrationTests.java
...springframework/boot/cli/ClassLoaderIntegrationTests.java
+3
-3
DirectorySourcesIntegrationTests.java
...gframework/boot/cli/DirectorySourcesIntegrationTests.java
+5
-5
GrabCommandIntegrationTests.java
...springframework/boot/cli/GrabCommandIntegrationTests.java
+8
-8
ReproIntegrationTests.java
...a/org/springframework/boot/cli/ReproIntegrationTests.java
+5
-8
SampleIntegrationTests.java
.../org/springframework/boot/cli/SampleIntegrationTests.java
+23
-34
TestCommandIntegrationTests.java
...springframework/boot/cli/TestCommandIntegrationTests.java
+12
-12
SpringApplicationLauncherTests.java
...ramework/boot/cli/app/SpringApplicationLauncherTests.java
+9
-14
CommandRunnerIntegrationTests.java
...ework/boot/cli/command/CommandRunnerIntegrationTests.java
+3
-4
CommandRunnerTests.java
.../springframework/boot/cli/command/CommandRunnerTests.java
+18
-24
OptionParsingCommandTests.java
...framework/boot/cli/command/OptionParsingCommandTests.java
+12
-5
ResourceMatcherTests.java
...mework/boot/cli/command/archive/ResourceMatcherTests.java
+38
-58
InitCommandTests.java
...ringframework/boot/cli/command/init/InitCommandTests.java
+80
-81
InitializrServiceMetadataTests.java
...boot/cli/command/init/InitializrServiceMetadataTests.java
+25
-26
InitializrServiceTests.java
...amework/boot/cli/command/init/InitializrServiceTests.java
+7
-10
ProjectGenerationRequestTests.java
.../boot/cli/command/init/ProjectGenerationRequestTests.java
+37
-41
ServiceCapabilitiesReportGeneratorTests.java
...command/init/ServiceCapabilitiesReportGeneratorTests.java
+6
-8
GroovyGrabDependencyResolverTests.java
...li/command/install/GroovyGrabDependencyResolverTests.java
+15
-14
InstallerTests.java
...ingframework/boot/cli/command/install/InstallerTests.java
+13
-22
EscapeAwareWhiteSpaceArgumentDelimiterTests.java
...nd/shell/EscapeAwareWhiteSpaceArgumentDelimiterTests.java
+28
-34
DependencyCustomizerTests.java
...ramework/boot/cli/compiler/DependencyCustomizerTests.java
+18
-18
ExtendedGroovyClassLoaderTests.java
...ork/boot/cli/compiler/ExtendedGroovyClassLoaderTests.java
+2
-3
GenericBomAstTransformationTests.java
...k/boot/cli/compiler/GenericBomAstTransformationTests.java
+5
-4
RepositoryConfigurationFactoryTests.java
...oot/cli/compiler/RepositoryConfigurationFactoryTests.java
+4
-5
ResolveDependencyCoordinatesTransformationTests.java
...iler/ResolveDependencyCoordinatesTransformationTests.java
+4
-4
CompositeDependencyManagementTests.java
...iler/dependencies/CompositeDependencyManagementTests.java
+12
-19
DependencyManagementArtifactCoordinatesResolverTests.java
...DependencyManagementArtifactCoordinatesResolverTests.java
+5
-7
SpringBootDependenciesDependencyManagementTests.java
...cies/SpringBootDependenciesDependencyManagementTests.java
+6
-10
AetherGrapeEngineTests.java
...ework/boot/cli/compiler/grape/AetherGrapeEngineTests.java
+20
-22
DetailedProgressReporterTests.java
...oot/cli/compiler/grape/DetailedProgressReporterTests.java
+8
-12
GrapeRootRepositorySystemSessionAutoConfigurationTests.java
...apeRootRepositorySystemSessionAutoConfigurationTests.java
+6
-12
SettingsXmlRepositorySystemSessionAutoConfigurationTests.java
...ingsXmlRepositorySystemSessionAutoConfigurationTests.java
+15
-21
ResourceUtilsTests.java
...org/springframework/boot/cli/util/ResourceUtilsTests.java
+27
-28
No files found.
spring-boot-cli/src/test/java/org/springframework/boot/cli/ClassLoaderIntegrationTests.java
View file @
962a5985
...
...
@@ -19,8 +19,7 @@ package org.springframework.boot.cli;
import
org.junit.Rule
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for CLI Classloader issues.
...
...
@@ -37,6 +36,7 @@ public class ClassLoaderIntegrationTests {
// CLI classes or dependencies should not be exposed to the app
String
output
=
this
.
cli
.
run
(
"classloader-test-app.groovy"
,
SpringCli
.
class
.
getName
());
assertThat
(
output
,
containsString
(
"HasClasses-false-true-false"
)
);
assertThat
(
output
).
contains
(
"HasClasses-false-true-false"
);
}
}
spring-boot-cli/src/test/java/org/springframework/boot/cli/DirectorySourcesIntegrationTests.java
View file @
962a5985
...
...
@@ -19,8 +19,7 @@ package org.springframework.boot.cli;
import
org.junit.Rule
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for code in directories.
...
...
@@ -35,18 +34,19 @@ public class DirectorySourcesIntegrationTests {
@Test
public
void
runDirectory
()
throws
Exception
{
this
.
cli
.
run
(
"code"
);
assertThat
(
this
.
cli
.
getOutput
()
,
containsString
(
"Hello World"
)
);
assertThat
(
this
.
cli
.
getOutput
()
).
contains
(
"Hello World"
);
}
@Test
public
void
runDirectoryRecursive
()
throws
Exception
{
this
.
cli
.
run
(
""
);
assertThat
(
this
.
cli
.
getOutput
()
,
containsString
(
"Hello World"
)
);
assertThat
(
this
.
cli
.
getOutput
()
).
contains
(
"Hello World"
);
}
@Test
public
void
runPathPattern
()
throws
Exception
{
this
.
cli
.
run
(
"**/*.groovy"
);
assertThat
(
this
.
cli
.
getOutput
()
,
containsString
(
"Hello World"
)
);
assertThat
(
this
.
cli
.
getOutput
()
).
contains
(
"Hello World"
);
}
}
spring-boot-cli/src/test/java/org/springframework/boot/cli/GrabCommandIntegrationTests.java
View file @
962a5985
...
...
@@ -26,9 +26,7 @@ import org.junit.Test;
import
org.springframework.boot.cli.command.grab.GrabCommand
;
import
org.springframework.util.FileSystemUtils
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
junit
.
Assert
.
fail
;
/**
...
...
@@ -58,9 +56,10 @@ public class GrabCommandIntegrationTests {
// Use --autoconfigure=false to limit the amount of downloaded dependencies
String
output
=
this
.
cli
.
grab
(
"grab.groovy"
,
"--autoconfigure=false"
);
assertTrue
(
new
File
(
"target/repository/joda-time/joda-time"
).
isDirectory
());
assertThat
(
new
File
(
"target/repository/joda-time/joda-time"
).
isDirectory
())
.
isTrue
();
// Should be resolved from local repository cache
assertT
rue
(
output
.
contains
(
"Downloading: file:"
)
);
assertT
hat
(
output
.
contains
(
"Downloading: file:"
)).
isTrue
(
);
}
@Test
...
...
@@ -71,8 +70,8 @@ public class GrabCommandIntegrationTests {
fail
();
}
catch
(
Exception
ex
)
{
assertThat
(
ex
.
getMessage
()
,
containsString
(
"Duplicate @DependencyManagementBom annotation"
)
);
assertThat
(
ex
.
getMessage
()
)
.
contains
(
"Duplicate @DependencyManagementBom annotation"
);
}
}
...
...
@@ -83,6 +82,7 @@ public class GrabCommandIntegrationTests {
new
File
(
"src/test/resources/grab-samples/repository"
),
new
File
(
"target/repository"
));
this
.
cli
.
grab
(
"customDependencyManagement.groovy"
,
"--autoconfigure=false"
);
assertTrue
(
new
File
(
"target/repository/javax/ejb/ejb-api/3.0"
).
isDirectory
());
assertThat
(
new
File
(
"target/repository/javax/ejb/ejb-api/3.0"
).
isDirectory
())
.
isTrue
();
}
}
spring-boot-cli/src/test/java/org/springframework/boot/cli/ReproIntegrationTests.java
View file @
962a5985
...
...
@@ -20,8 +20,7 @@ import org.junit.Rule;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests to exercise and reproduce specific issues.
...
...
@@ -41,8 +40,7 @@ public class ReproIntegrationTests {
@Test
public
void
grabAntBuilder
()
throws
Exception
{
this
.
cli
.
run
(
"grab-ant-builder.groovy"
);
assertThat
(
this
.
cli
.
getHttpOutput
(),
containsString
(
"{\"message\":\"Hello World\"}"
));
assertThat
(
this
.
cli
.
getHttpOutput
()).
contains
(
"{\"message\":\"Hello World\"}"
);
}
// Security depends on old versions of Spring so if the dependencies aren't pinned
...
...
@@ -50,20 +48,19 @@ public class ReproIntegrationTests {
@Test
public
void
securityDependencies
()
throws
Exception
{
this
.
cli
.
run
(
"secure.groovy"
);
assertThat
(
this
.
cli
.
getOutput
()
,
containsString
(
"Hello World"
)
);
assertThat
(
this
.
cli
.
getOutput
()
).
contains
(
"Hello World"
);
}
@Test
public
void
shellDependencies
()
throws
Exception
{
this
.
cli
.
run
(
"crsh.groovy"
);
assertThat
(
this
.
cli
.
getHttpOutput
(),
containsString
(
"{\"message\":\"Hello World\"}"
));
assertThat
(
this
.
cli
.
getHttpOutput
()).
contains
(
"{\"message\":\"Hello World\"}"
);
}
@Test
public
void
dataJpaDependencies
()
throws
Exception
{
this
.
cli
.
run
(
"data-jpa.groovy"
);
assertThat
(
this
.
cli
.
getOutput
()
,
containsString
(
"Hello World"
)
);
assertThat
(
this
.
cli
.
getOutput
()
).
contains
(
"Hello World"
);
}
@Test
...
...
spring-boot-cli/src/test/java/org/springframework/boot/cli/SampleIntegrationTests.java
View file @
962a5985
...
...
@@ -23,10 +23,7 @@ import org.junit.Ignore;
import
org.junit.Rule
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests to exercise the samples.
...
...
@@ -45,45 +42,40 @@ public class SampleIntegrationTests {
public
void
appSample
()
throws
Exception
{
String
output
=
this
.
cli
.
run
(
"app.groovy"
);
URI
scriptUri
=
new
File
(
"samples/app.groovy"
).
toURI
();
assertTrue
(
"Wrong output: "
+
output
,
output
.
contains
(
"Hello World! From "
+
scriptUri
));
assertThat
(
output
).
contains
(
"Hello World! From "
+
scriptUri
);
}
@Test
public
void
retrySample
()
throws
Exception
{
String
output
=
this
.
cli
.
run
(
"retry.groovy"
);
URI
scriptUri
=
new
File
(
"samples/retry.groovy"
).
toURI
();
assertTrue
(
"Wrong output: "
+
output
,
output
.
contains
(
"Hello World! From "
+
scriptUri
));
assertThat
(
output
).
contains
(
"Hello World! From "
+
scriptUri
);
}
@Test
public
void
beansSample
()
throws
Exception
{
this
.
cli
.
run
(
"beans.groovy"
);
String
output
=
this
.
cli
.
getHttpOutput
();
assertT
rue
(
"Wrong output: "
+
output
,
output
.
contains
(
"Hello World!"
)
);
assertT
hat
(
output
).
contains
(
"Hello World!"
);
}
@Test
public
void
templateSample
()
throws
Exception
{
String
output
=
this
.
cli
.
run
(
"template.groovy"
);
assertT
rue
(
"Wrong output: "
+
output
,
output
.
contains
(
"Hello World!"
)
);
assertT
hat
(
output
).
contains
(
"Hello World!"
);
}
@Test
public
void
jobSample
()
throws
Exception
{
String
output
=
this
.
cli
.
run
(
"job.groovy"
,
"foo=bar"
);
assertTrue
(
"Wrong output: "
+
output
,
output
.
contains
(
"completed with the following parameters"
));
assertThat
(
output
).
contains
(
"completed with the following parameters"
);
}
@Test
public
void
oauth2Sample
()
throws
Exception
{
String
output
=
this
.
cli
.
run
(
"oauth2.groovy"
);
assertTrue
(
"Wrong output: "
+
output
,
output
.
contains
(
"security.oauth2.client.clientId"
));
assertTrue
(
"Wrong output: "
+
output
,
output
.
contains
(
"security.oauth2.client.secret ="
));
assertThat
(
output
).
contains
(
"security.oauth2.client.clientId"
);
assertThat
(
output
).
contains
(
"security.oauth2.client.secret ="
);
}
@Test
...
...
@@ -94,88 +86,85 @@ public class SampleIntegrationTests {
Thread
.
sleep
(
200
);
output
=
this
.
cli
.
getOutput
();
}
assertT
rue
(
"Wrong output: "
+
output
,
output
.
contains
(
"Hello Phil"
)
);
assertT
hat
(
output
).
contains
(
"Hello Phil"
);
}
@Test
public
void
jobWebSample
()
throws
Exception
{
String
output
=
this
.
cli
.
run
(
"job.groovy"
,
"web.groovy"
,
"foo=bar"
);
assertTrue
(
"Wrong output: "
+
output
,
output
.
contains
(
"completed with the following parameters"
));
assertThat
(
output
).
contains
(
"completed with the following parameters"
);
String
result
=
this
.
cli
.
getHttpOutput
();
assert
Equals
(
"World!"
,
result
);
assert
That
(
result
).
isEqualTo
(
"World!"
);
}
@Test
public
void
webSample
()
throws
Exception
{
this
.
cli
.
run
(
"web.groovy"
);
assert
Equals
(
"World!"
,
this
.
cli
.
getHttpOutput
()
);
assert
That
(
this
.
cli
.
getHttpOutput
()).
isEqualTo
(
"World!"
);
}
@Test
public
void
uiSample
()
throws
Exception
{
this
.
cli
.
run
(
"ui.groovy"
,
"--classpath=.:src/test/resources"
);
String
result
=
this
.
cli
.
getHttpOutput
();
assertT
rue
(
"Wrong output: "
+
result
,
result
.
contains
(
"Hello World"
)
);
assertT
hat
(
result
).
contains
(
"Hello World"
);
result
=
this
.
cli
.
getHttpOutput
(
"/css/bootstrap.min.css"
);
assertT
rue
(
"Wrong output: "
+
result
,
result
.
contains
(
"container"
)
);
assertT
hat
(
result
).
contains
(
"container"
);
}
@Test
public
void
actuatorSample
()
throws
Exception
{
this
.
cli
.
run
(
"actuator.groovy"
);
assert
Equals
(
"{\"message\":\"Hello World!\"}"
,
this
.
cli
.
getHttpOutput
()
);
assert
That
(
this
.
cli
.
getHttpOutput
()).
isEqualTo
(
"{\"message\":\"Hello World!\"}"
);
}
@Test
public
void
httpSample
()
throws
Exception
{
String
output
=
this
.
cli
.
run
(
"http.groovy"
);
assertT
rue
(
"Wrong output: "
+
output
,
output
.
contains
(
"Hello World"
)
);
assertT
hat
(
output
).
contains
(
"Hello World"
);
}
@Test
public
void
integrationSample
()
throws
Exception
{
String
output
=
this
.
cli
.
run
(
"integration.groovy"
);
assertT
rue
(
"Wrong output: "
+
output
,
output
.
contains
(
"Hello, World"
)
);
assertT
hat
(
output
).
contains
(
"Hello, World"
);
}
@Test
public
void
xmlSample
()
throws
Exception
{
String
output
=
this
.
cli
.
run
(
"runner.xml"
,
"runner.groovy"
);
assertT
rue
(
"Wrong output: "
+
output
,
output
.
contains
(
"Hello World"
)
);
assertT
hat
(
output
).
contains
(
"Hello World"
);
}
@Test
public
void
txSample
()
throws
Exception
{
String
output
=
this
.
cli
.
run
(
"tx.groovy"
);
assertT
rue
(
"Wrong output: "
+
output
,
output
.
contains
(
"Foo count="
)
);
assertT
hat
(
output
).
contains
(
"Foo count="
);
}
@Test
public
void
jmsSample
()
throws
Exception
{
String
output
=
this
.
cli
.
run
(
"jms.groovy"
);
assertTrue
(
"Wrong output: "
+
output
,
output
.
contains
(
"Received Greetings from Spring Boot via HornetQ"
));
assertThat
(
output
).
contains
(
"Received Greetings from Spring Boot via HornetQ"
);
}
@Test
@Ignore
(
"Requires RabbitMQ to be run, so disable it be default"
)
public
void
rabbitSample
()
throws
Exception
{
String
output
=
this
.
cli
.
run
(
"rabbit.groovy"
);
assertTrue
(
"Wrong output: "
+
output
,
output
.
contains
(
"Received Greetings from Spring Boot via RabbitMQ"
));
assertThat
(
output
).
contains
(
"Received Greetings from Spring Boot via RabbitMQ"
);
}
@Test
public
void
deviceSample
()
throws
Exception
{
this
.
cli
.
run
(
"device.groovy"
);
assert
Equals
(
"Hello Normal Device!"
,
this
.
cli
.
getHttpOutput
()
);
assert
That
(
this
.
cli
.
getHttpOutput
()).
isEqualTo
(
"Hello Normal Device!"
);
}
@Test
public
void
caching
()
throws
Exception
{
this
.
cli
.
run
(
"caching.groovy"
);
assertThat
(
this
.
cli
.
getOutput
()
,
containsString
(
"Hello World"
)
);
assertThat
(
this
.
cli
.
getOutput
()
).
contains
(
"Hello World"
);
}
}
spring-boot-cli/src/test/java/org/springframework/boot/cli/TestCommandIntegrationTests.java
View file @
962a5985
...
...
@@ -24,8 +24,7 @@ import org.junit.rules.ExpectedException;
import
org.springframework.boot.cli.command.test.TestCommand
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests to exercise the CLI's test command.
...
...
@@ -54,13 +53,13 @@ public class TestCommandIntegrationTests {
@Test
public
void
noTests
()
throws
Throwable
{
String
output
=
this
.
cli
.
test
(
"book.groovy"
);
assertThat
(
output
,
containsString
(
"No tests found"
)
);
assertThat
(
output
).
contains
(
"No tests found"
);
}
@Test
public
void
empty
()
throws
Exception
{
String
output
=
this
.
cli
.
test
(
"empty.groovy"
);
assertThat
(
output
,
containsString
(
"No tests found"
)
);
assertThat
(
output
).
contains
(
"No tests found"
);
}
@Test
...
...
@@ -74,48 +73,49 @@ public class TestCommandIntegrationTests {
@Test
public
void
appAndTestsInOneFile
()
throws
Exception
{
String
output
=
this
.
cli
.
test
(
"book_and_tests.groovy"
);
assertThat
(
output
,
containsString
(
"OK (1 test)"
)
);
assertThat
(
output
).
contains
(
"OK (1 test)"
);
}
@Test
public
void
appInOneFileTestsInAnotherFile
()
throws
Exception
{
String
output
=
this
.
cli
.
test
(
"book.groovy"
,
"test.groovy"
);
assertThat
(
output
,
containsString
(
"OK (1 test)"
)
);
assertThat
(
output
).
contains
(
"OK (1 test)"
);
}
@Test
public
void
integrationTest
()
throws
Exception
{
String
output
=
this
.
cli
.
test
(
"integration.groovy"
);
assertThat
(
output
,
containsString
(
"OK (1 test)"
)
);
assertThat
(
output
).
contains
(
"OK (1 test)"
);
}
@Test
public
void
integrationAutoConfigEmbeddedTest
()
throws
Exception
{
String
output
=
this
.
cli
.
test
(
"integration_auto.groovy"
);
assertThat
(
output
,
containsString
(
"OK (1 test)"
)
);
assertThat
(
output
).
contains
(
"OK (1 test)"
);
}
@Test
public
void
integrationAutoConfigTest
()
throws
Exception
{
String
output
=
this
.
cli
.
test
(
"integration_auto_test.groovy"
,
"reactor.groovy"
);
assertThat
(
output
,
containsString
(
"OK (1 test)"
)
);
assertThat
(
output
).
contains
(
"OK (1 test)"
);
}
@Test
public
void
spockTester
()
throws
Exception
{
String
output
=
this
.
cli
.
test
(
"spock.groovy"
);
assertThat
(
output
,
containsString
(
"OK (1 test)"
)
);
assertThat
(
output
).
contains
(
"OK (1 test)"
);
}
@Test
public
void
spockAndJunitTester
()
throws
Exception
{
String
output
=
this
.
cli
.
test
(
"spock.groovy"
,
"book_and_tests.groovy"
);
assertThat
(
output
,
containsString
(
"OK (2 tests)"
)
);
assertThat
(
output
).
contains
(
"OK (2 tests)"
);
}
@Test
public
void
verifyFailures
()
throws
Exception
{
String
output
=
this
.
cli
.
test
(
"failures.groovy"
);
assertThat
(
output
,
containsString
(
"Tests run: 5, Failures: 3"
)
);
assertThat
(
output
).
contains
(
"Tests run: 5, Failures: 3"
);
}
}
spring-boot-cli/src/test/java/org/springframework/boot/cli/app/SpringApplicationLauncherTests.java
View file @
962a5985
...
...
@@ -24,10 +24,7 @@ import java.util.Set;
import
org.junit.After
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
Matchers
.
contains
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link SpringApplicationLauncher}
...
...
@@ -45,21 +42,21 @@ public class SpringApplicationLauncherTests {
@Test
public
void
defaultLaunch
()
throws
Exception
{
assertThat
(
launch
()
,
contains
(
"org.springframework.boot.SpringApplication"
)
);
assertThat
(
launch
()
).
contains
(
"org.springframework.boot.SpringApplication"
);
}
@Test
public
void
launchWithClassConfiguredBySystemProperty
()
{
System
.
setProperty
(
"spring.application.class.name"
,
"system.property.SpringApplication"
);
assertThat
(
launch
()
,
contains
(
"system.property.SpringApplication"
)
);
assertThat
(
launch
()
).
contains
(
"system.property.SpringApplication"
);
}
@Test
public
void
launchWithClassConfiguredByEnvironmentVariable
()
{
this
.
env
.
put
(
"SPRING_APPLICATION_CLASS_NAME"
,
"environment.variable.SpringApplication"
);
assertThat
(
launch
()
,
contains
(
"environment.variable.SpringApplication"
)
);
assertThat
(
launch
()
).
contains
(
"environment.variable.SpringApplication"
);
}
@Test
...
...
@@ -68,7 +65,7 @@ public class SpringApplicationLauncherTests {
"system.property.SpringApplication"
);
this
.
env
.
put
(
"SPRING_APPLICATION_CLASS_NAME"
,
"environment.variable.SpringApplication"
);
assertThat
(
launch
()
,
contains
(
"system.property.SpringApplication"
)
);
assertThat
(
launch
()
).
contains
(
"system.property.SpringApplication"
);
}
...
...
@@ -80,14 +77,12 @@ public class SpringApplicationLauncherTests {
String
[]
args
=
new
String
[
0
];
new
SpringApplicationLauncher
(
getClass
().
getClassLoader
()).
launch
(
sources
,
args
);
assertT
rue
(
sources
==
TestSpringApplication
.
sources
);
assertT
rue
(
args
==
TestSpringApplication
.
args
);
assertT
hat
(
sources
==
TestSpringApplication
.
sources
).
isTrue
(
);
assertT
hat
(
args
==
TestSpringApplication
.
args
).
isTrue
(
);
Map
<
String
,
String
>
defaultProperties
=
TestSpringApplication
.
defaultProperties
;
assertThat
(
defaultProperties
.
size
(),
equalTo
(
1
));
assertThat
(
defaultProperties
.
get
(
"spring.groovy.template.check-template-location"
),
equalTo
(
"false"
));
assertThat
(
defaultProperties
).
hasSize
(
1
)
.
containsEntry
(
"spring.groovy.template.check-template-location"
,
"false"
);
}
private
Set
<
String
>
launch
()
{
...
...
spring-boot-cli/src/test/java/org/springframework/boot/cli/command/CommandRunnerIntegrationTests.java
View file @
962a5985
...
...
@@ -22,8 +22,7 @@ import org.junit.Test;
import
org.springframework.boot.cli.command.run.RunCommand
;
import
org.springframework.boot.cli.util.OutputCapture
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* @author Dave Syer
...
...
@@ -40,7 +39,7 @@ public class CommandRunnerIntegrationTests {
// -d counts as "debug" for the spring command, but not for the
// LoggingApplicationListener
runner
.
runAndHandleErrors
(
"run"
,
"samples/app.groovy"
,
"-d"
);
assertT
rue
(
this
.
output
.
toString
().
contains
(
"Negative matches:"
)
);
assertT
hat
(
this
.
output
.
toString
()).
contains
(
"Negative matches:"
);
}
@Test
...
...
@@ -48,6 +47,6 @@ public class CommandRunnerIntegrationTests {
CommandRunner
runner
=
new
CommandRunner
(
"spring"
);
runner
.
addCommand
(
new
RunCommand
());
runner
.
runAndHandleErrors
(
"run"
,
"samples/app.groovy"
,
"--"
,
"-d"
);
assert
False
(
this
.
output
.
toString
().
contains
(
"Negative matches:"
)
);
assert
That
(
this
.
output
.
toString
()).
doesNotContain
(
"Negative matches:"
);
}
}
spring-boot-cli/src/test/java/org/springframework/boot/cli/command/CommandRunnerTests.java
View file @
962a5985
...
...
@@ -30,10 +30,7 @@ import org.mockito.MockitoAnnotations;
import
org.springframework.boot.cli.command.core.HelpCommand
;
import
org.springframework.boot.cli.command.core.HintCommand
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
BDDMockito
.
willThrow
;
import
static
org
.
mockito
.
Mockito
.
verify
;
...
...
@@ -126,64 +123,61 @@ public class CommandRunnerTests {
verify
(
this
.
regularCommand
).
run
(
"--"
,
"--debug"
,
"bar"
);
// When handled by the command itself it shouldn't cause the system property to be
// set
assert
Null
(
System
.
getProperty
(
"debug"
)
);
assert
That
(
System
.
getProperty
(
"debug"
)).
isNull
(
);
}
@Test
public
void
handlesSuccess
()
throws
Exception
{
int
status
=
this
.
commandRunner
.
runAndHandleErrors
(
"command"
);
assertThat
(
status
,
equalTo
(
0
)
);
assertThat
(
this
.
calls
,
equalTo
((
Set
<
Call
>)
EnumSet
.
noneOf
(
Call
.
class
))
);
assertThat
(
status
).
isEqualTo
(
0
);
assertThat
(
this
.
calls
).
isEmpty
(
);
}
@Test
public
void
handlesNoSuchCommand
()
throws
Exception
{
int
status
=
this
.
commandRunner
.
runAndHandleErrors
(
"missing"
);
assertThat
(
status
,
equalTo
(
1
)
);
assertThat
(
this
.
calls
,
equalTo
((
Set
<
Call
>)
EnumSet
.
of
(
Call
.
ERROR_MESSAGE
))
);
assertThat
(
status
).
isEqualTo
(
1
);
assertThat
(
this
.
calls
).
containsOnly
(
Call
.
ERROR_MESSAGE
);
}
@Test
public
void
handlesRegularExceptionWithMessage
()
throws
Exception
{
willThrow
(
new
RuntimeException
(
"With Message"
)).
given
(
this
.
regularCommand
).
run
();
int
status
=
this
.
commandRunner
.
runAndHandleErrors
(
"command"
);
assertThat
(
status
,
equalTo
(
1
)
);
assertThat
(
this
.
calls
,
equalTo
((
Set
<
Call
>)
EnumSet
.
of
(
Call
.
ERROR_MESSAGE
))
);
assertThat
(
status
).
isEqualTo
(
1
);
assertThat
(
this
.
calls
).
containsOnly
(
Call
.
ERROR_MESSAGE
);
}
@Test
public
void
handlesRegularExceptionWithoutMessage
()
throws
Exception
{
willThrow
(
new
NullPointerException
()).
given
(
this
.
regularCommand
).
run
();
int
status
=
this
.
commandRunner
.
runAndHandleErrors
(
"command"
);
assertThat
(
status
,
equalTo
(
1
));
assertThat
(
this
.
calls
,
equalTo
(
(
Set
<
Call
>)
EnumSet
.
of
(
Call
.
ERROR_MESSAGE
,
Call
.
PRINT_STACK_TRACE
)));
assertThat
(
status
).
isEqualTo
(
1
);
assertThat
(
this
.
calls
).
containsOnly
(
Call
.
ERROR_MESSAGE
,
Call
.
PRINT_STACK_TRACE
);
}
@Test
public
void
handlesExceptionWithDashD
()
throws
Exception
{
willThrow
(
new
RuntimeException
()).
given
(
this
.
regularCommand
).
run
();
int
status
=
this
.
commandRunner
.
runAndHandleErrors
(
"command"
,
"-d"
);
assertEquals
(
"true"
,
System
.
getProperty
(
"debug"
));
assertThat
(
status
,
equalTo
(
1
));
assertThat
(
this
.
calls
,
equalTo
(
(
Set
<
Call
>)
EnumSet
.
of
(
Call
.
ERROR_MESSAGE
,
Call
.
PRINT_STACK_TRACE
)));
assertThat
(
System
.
getProperty
(
"debug"
)).
isEqualTo
(
"true"
);
assertThat
(
status
).
isEqualTo
(
1
);
assertThat
(
this
.
calls
).
containsOnly
(
Call
.
ERROR_MESSAGE
,
Call
.
PRINT_STACK_TRACE
);
}
@Test
public
void
handlesExceptionWithDashDashDebug
()
throws
Exception
{
willThrow
(
new
RuntimeException
()).
given
(
this
.
regularCommand
).
run
();
int
status
=
this
.
commandRunner
.
runAndHandleErrors
(
"command"
,
"--debug"
);
assertEquals
(
"true"
,
System
.
getProperty
(
"debug"
));
assertThat
(
status
,
equalTo
(
1
));
assertThat
(
this
.
calls
,
equalTo
(
(
Set
<
Call
>)
EnumSet
.
of
(
Call
.
ERROR_MESSAGE
,
Call
.
PRINT_STACK_TRACE
)));
assertThat
(
System
.
getProperty
(
"debug"
)).
isEqualTo
(
"true"
);
assertThat
(
status
).
isEqualTo
(
1
);
assertThat
(
this
.
calls
).
containsOnly
(
Call
.
ERROR_MESSAGE
,
Call
.
PRINT_STACK_TRACE
);
}
@Test
public
void
exceptionMessages
()
throws
Exception
{
assertThat
(
new
NoSuchCommandException
(
"name"
).
getMessage
()
,
equalTo
(
"'name' is not a valid command. See 'help'."
)
);
assertThat
(
new
NoSuchCommandException
(
"name"
).
getMessage
()
)
.
isEqualTo
(
"'name' is not a valid command. See 'help'."
);
}
@Test
...
...
spring-boot-cli/src/test/java/org/springframework/boot/cli/command/OptionParsingCommandTests.java
View file @
962a5985
...
...
@@ -20,8 +20,7 @@ import org.junit.Test;
import
org.springframework.boot.cli.command.options.OptionHandler
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link OptionParsingCommand}.
...
...
@@ -34,9 +33,17 @@ public class OptionParsingCommandTests {
public
void
optionHelp
()
{
OptionHandler
handler
=
new
OptionHandler
();
handler
.
option
(
"bar"
,
"Bar"
);
OptionParsingCommand
command
=
new
OptionParsingCommand
(
"foo"
,
"Foo"
,
handler
)
{
};
assertThat
(
command
.
getHelp
(),
containsString
(
"--bar"
));
OptionParsingCommand
command
=
new
TestOptionParsingCommand
(
"foo"
,
"Foo"
,
handler
);
assertThat
(
command
.
getHelp
()).
contains
(
"--bar"
);
}
private
static
class
TestOptionParsingCommand
extends
OptionParsingCommand
{
TestOptionParsingCommand
(
String
name
,
String
description
,
OptionHandler
handler
)
{
super
(
name
,
description
,
handler
);
}
}
}
spring-boot-cli/src/test/java/org/springframework/boot/cli/command/archive/ResourceMatcherTests.java
View file @
962a5985
...
...
@@ -23,19 +23,13 @@ import java.util.Arrays;
import
java.util.Collection
;
import
java.util.List
;
import
org.hamcrest.Description
;
import
org.hamcrest.TypeSafeMatcher
;
import
org.assertj.core.api.Condition
;
import
org.junit.Test
;
import
org.springframework.boot.cli.command.archive.ResourceMatcher.MatchedResource
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
static
org
.
hamcrest
.
Matchers
.
hasItem
;
import
static
org
.
hamcrest
.
Matchers
.
not
;
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
;
/**
* Tests for {@link ResourceMatcher}.
...
...
@@ -51,7 +45,7 @@ public class ResourceMatcherTests {
Arrays
.
asList
(
".*"
,
"alpha/**/excluded"
));
List
<
MatchedResource
>
matchedResources
=
resourceMatcher
.
find
(
Arrays
.
asList
(
new
File
(
"does-not-exist"
)));
assert
Equals
(
0
,
matchedResources
.
size
()
);
assert
That
(
matchedResources
).
isEmpty
(
);
}
@SuppressWarnings
(
"unchecked"
)
...
...
@@ -59,10 +53,12 @@ public class ResourceMatcherTests {
public
void
defaults
()
throws
Exception
{
ResourceMatcher
resourceMatcher
=
new
ResourceMatcher
(
Arrays
.
asList
(
""
),
Arrays
.
asList
(
""
));
assertTrue
(((
Collection
<
String
>)
ReflectionTestUtils
.
getField
(
resourceMatcher
,
"includes"
)).
contains
(
"static/**"
));
assertTrue
(((
Collection
<
String
>)
ReflectionTestUtils
.
getField
(
resourceMatcher
,
"excludes"
)).
contains
(
"**/*.jar"
));
Collection
<
String
>
includes
=
(
Collection
<
String
>)
ReflectionTestUtils
.
getField
(
resourceMatcher
,
"includes"
);
Collection
<
String
>
excludes
=
(
Collection
<
String
>)
ReflectionTestUtils
.
getField
(
resourceMatcher
,
"excludes"
);
assertThat
(
includes
).
contains
(
"static/**"
);
assertThat
(
excludes
).
contains
(
"**/*.jar"
);
}
@Test
...
...
@@ -71,7 +67,14 @@ public class ResourceMatcherTests {
Arrays
.
asList
(
"**/*.jar"
));
List
<
MatchedResource
>
found
=
resourceMatcher
.
find
(
Arrays
.
asList
(
new
File
(
"src/test/resources"
)));
assertThat
(
found
,
not
(
hasItem
(
new
FooJarMatcher
(
MatchedResource
.
class
))));
assertThat
(
found
).
areNot
(
new
Condition
<
MatchedResource
>()
{
@Override
public
boolean
matches
(
MatchedResource
value
)
{
return
value
.
getFile
().
getName
().
equals
(
"foo.jar"
);
}
});
}
@SuppressWarnings
(
"unchecked"
)
...
...
@@ -81,8 +84,8 @@ public class ResourceMatcherTests {
Arrays
.
asList
(
""
));
Collection
<
String
>
includes
=
(
Collection
<
String
>)
ReflectionTestUtils
.
getField
(
resourceMatcher
,
"includes"
);
assertT
rue
(
includes
.
contains
(
"templates/**"
)
);
assert
False
(
includes
.
contains
(
"static/**"
)
);
assertT
hat
(
includes
).
contains
(
"templates/**"
);
assert
That
(
includes
).
doesNotContain
(
"static/**"
);
}
@SuppressWarnings
(
"unchecked"
)
...
...
@@ -92,11 +95,12 @@ public class ResourceMatcherTests {
Arrays
.
asList
(
"-static/**"
,
"foo.jar"
),
Arrays
.
asList
(
"-**/*.jar"
));
Collection
<
String
>
includes
=
(
Collection
<
String
>)
ReflectionTestUtils
.
getField
(
resourceMatcher
,
"includes"
);
assertTrue
(
includes
.
contains
(
"foo.jar"
));
assertTrue
(
includes
.
contains
(
"templates/**"
));
assertFalse
(
includes
.
contains
(
"static/**"
));
assertFalse
(((
Collection
<
String
>)
ReflectionTestUtils
.
getField
(
resourceMatcher
,
"excludes"
)).
contains
(
"**/*.jar"
));
Collection
<
String
>
excludes
=
(
Collection
<
String
>)
ReflectionTestUtils
.
getField
(
resourceMatcher
,
"excludes"
);
assertThat
(
includes
).
contains
(
"foo.jar"
);
assertThat
(
includes
).
contains
(
"templates/**"
);
assertThat
(
includes
).
doesNotContain
(
"static/**"
);
assertThat
(
excludes
).
doesNotContain
(
"**/*.jar"
);
}
@SuppressWarnings
(
"unchecked"
)
...
...
@@ -104,8 +108,9 @@ public class ResourceMatcherTests {
public
void
excludedDeltas
()
throws
Exception
{
ResourceMatcher
resourceMatcher
=
new
ResourceMatcher
(
Arrays
.
asList
(
""
),
Arrays
.
asList
(
"-**/*.jar"
));
assertFalse
(((
Collection
<
String
>)
ReflectionTestUtils
.
getField
(
resourceMatcher
,
"excludes"
)).
contains
(
"**/*.jar"
));
Collection
<
String
>
excludes
=
(
Collection
<
String
>)
ReflectionTestUtils
.
getField
(
resourceMatcher
,
"excludes"
);
assertThat
(
excludes
).
doesNotContain
(
"**/*.jar"
);
}
@Test
...
...
@@ -115,10 +120,14 @@ public class ResourceMatcherTests {
List
<
MatchedResource
>
found
=
resourceMatcher
.
find
(
Arrays
.
asList
(
new
File
(
"src/test/resources/templates"
),
new
File
(
"src/test/resources/foo.jar"
)));
FooJarMatcher
matcher
=
new
FooJarMatcher
(
MatchedResource
.
class
);
assertThat
(
found
,
hasItem
(
matcher
));
// A jar file is always treated as a dependency (stick it in /lib)
assertTrue
(
matcher
.
getMatched
().
isRoot
());
assertThat
(
found
).
areAtLeastOne
(
new
Condition
<
MatchedResource
>()
{
@Override
public
boolean
matches
(
MatchedResource
value
)
{
return
value
.
getFile
().
getName
().
equals
(
"foo.jar"
)
&&
value
.
isRoot
();
}
});
}
@Test
...
...
@@ -135,37 +144,8 @@ public class ResourceMatcherTests {
for
(
MatchedResource
resource
:
matchedResources
)
{
paths
.
add
(
resource
.
getName
());
}
assertEquals
(
6
,
paths
.
size
());
assertTrue
(
paths
.
containsAll
(
Arrays
.
asList
(
"alpha/nested/fileA"
,
"bravo/fileC"
,
"fileD"
,
"bravo/fileE"
,
"fileF"
,
"three"
)));
}
private
final
class
FooJarMatcher
extends
TypeSafeMatcher
<
MatchedResource
>
{
private
MatchedResource
matched
;
public
MatchedResource
getMatched
()
{
return
this
.
matched
;
}
private
FooJarMatcher
(
Class
<?>
expectedType
)
{
super
(
expectedType
);
}
@Override
public
void
describeTo
(
Description
description
)
{
description
.
appendText
(
"foo.jar"
);
}
@Override
protected
boolean
matchesSafely
(
MatchedResource
item
)
{
boolean
matches
=
item
.
getFile
().
getName
().
equals
(
"foo.jar"
);
if
(
matches
)
{
this
.
matched
=
item
;
}
return
matches
;
}
assertThat
(
paths
).
containsOnly
(
"alpha/nested/fileA"
,
"bravo/fileC"
,
"fileD"
,
"bravo/fileE"
,
"fileF"
,
"three"
);
}
}
spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/InitCommandTests.java
View file @
962a5985
This diff is collapsed.
Click to expand it.
spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/InitializrServiceMetadataTests.java
View file @
962a5985
...
...
@@ -27,8 +27,7 @@ import org.springframework.core.io.ClassPathResource;
import
org.springframework.core.io.Resource
;
import
org.springframework.util.StreamUtils
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link InitializrServiceMetadata}
...
...
@@ -40,43 +39,43 @@ public class InitializrServiceMetadataTests {
@Test
public
void
parseDefaults
()
{
InitializrServiceMetadata
metadata
=
createInstance
(
"2.0.0"
);
assert
Equals
(
"1.1.8.RELEASE"
,
metadata
.
getDefaults
().
get
(
"bootVersion"
)
);
assert
Equals
(
"1.7"
,
metadata
.
getDefaults
().
get
(
"javaVersion"
)
);
assert
Equals
(
"org.test"
,
metadata
.
getDefaults
().
get
(
"groupId"
)
);
assert
Equals
(
"demo"
,
metadata
.
getDefaults
().
get
(
"name"
)
);
assert
Equals
(
"Demo project for Spring Boot"
,
metadata
.
getDefaults
().
get
(
"description"
)
);
assert
Equals
(
"jar"
,
metadata
.
getDefaults
().
get
(
"packaging"
)
);
assert
Equals
(
"java"
,
metadata
.
getDefaults
().
get
(
"language"
)
);
assert
Equals
(
"demo"
,
metadata
.
getDefaults
().
get
(
"artifactId"
)
);
assert
Equals
(
"demo"
,
metadata
.
getDefaults
().
get
(
"packageName"
)
);
assert
Equals
(
"maven-project"
,
metadata
.
getDefaults
().
get
(
"type"
)
);
assert
Equals
(
"0.0.1-SNAPSHOT"
,
metadata
.
getDefaults
().
get
(
"version"
)
);
assert
Equals
(
"Wrong number of defaults"
,
11
,
metadata
.
getDefaults
().
size
()
);
assert
That
(
metadata
.
getDefaults
().
get
(
"bootVersion"
)).
isEqualTo
(
"1.1.8.RELEASE"
);
assert
That
(
metadata
.
getDefaults
().
get
(
"javaVersion"
)).
isEqualTo
(
"1.7"
);
assert
That
(
metadata
.
getDefaults
().
get
(
"groupId"
)).
isEqualTo
(
"org.test"
);
assert
That
(
metadata
.
getDefaults
().
get
(
"name"
)).
isEqualTo
(
"demo"
);
assert
That
(
metadata
.
getDefaults
().
get
(
"description"
))
.
isEqualTo
(
"Demo project for Spring Boot"
);
assert
That
(
metadata
.
getDefaults
().
get
(
"packaging"
)).
isEqualTo
(
"jar"
);
assert
That
(
metadata
.
getDefaults
().
get
(
"language"
)).
isEqualTo
(
"java"
);
assert
That
(
metadata
.
getDefaults
().
get
(
"artifactId"
)).
isEqualTo
(
"demo"
);
assert
That
(
metadata
.
getDefaults
().
get
(
"packageName"
)).
isEqualTo
(
"demo"
);
assert
That
(
metadata
.
getDefaults
().
get
(
"type"
)).
isEqualTo
(
"maven-project"
);
assert
That
(
metadata
.
getDefaults
().
get
(
"version"
)).
isEqualTo
(
"0.0.1-SNAPSHOT"
);
assert
That
(
metadata
.
getDefaults
()).
as
(
"Wrong number of defaults"
).
hasSize
(
11
);
}
@Test
public
void
parseDependencies
()
{
InitializrServiceMetadata
metadata
=
createInstance
(
"2.0.0"
);
assert
Equals
(
5
,
metadata
.
getDependencies
().
size
()
);
assert
That
(
metadata
.
getDependencies
()).
hasSize
(
5
);
// Security description
assert
Equals
(
"AOP"
,
metadata
.
getDependency
(
"aop"
).
getName
()
);
assert
Equals
(
"Security"
,
metadata
.
getDependency
(
"security"
).
getName
()
);
assert
Equals
(
"Security description"
,
metadata
.
getDependency
(
"security"
).
getDescription
()
);
assert
Equals
(
"JDBC"
,
metadata
.
getDependency
(
"jdbc"
).
getName
()
);
assert
Equals
(
"JPA"
,
metadata
.
getDependency
(
"data-jpa"
).
getName
()
);
assert
Equals
(
"MongoDB"
,
metadata
.
getDependency
(
"data-mongodb"
).
getName
()
);
assert
That
(
metadata
.
getDependency
(
"aop"
).
getName
()).
isEqualTo
(
"AOP"
);
assert
That
(
metadata
.
getDependency
(
"security"
).
getName
()).
isEqualTo
(
"Security"
);
assert
That
(
metadata
.
getDependency
(
"security"
).
getDescription
())
.
isEqualTo
(
"Security description"
);
assert
That
(
metadata
.
getDependency
(
"jdbc"
).
getName
()).
isEqualTo
(
"JDBC"
);
assert
That
(
metadata
.
getDependency
(
"data-jpa"
).
getName
()).
isEqualTo
(
"JPA"
);
assert
That
(
metadata
.
getDependency
(
"data-mongodb"
).
getName
()).
isEqualTo
(
"MongoDB"
);
}
@Test
public
void
parseTypes
()
{
InitializrServiceMetadata
metadata
=
createInstance
(
"2.0.0"
);
ProjectType
projectType
=
metadata
.
getProjectTypes
().
get
(
"maven-project"
);
assert
NotNull
(
projectType
);
assert
Equals
(
"maven"
,
projectType
.
getTags
().
get
(
"build"
)
);
assert
Equals
(
"project"
,
projectType
.
getTags
().
get
(
"format"
)
);
assert
That
(
projectType
).
isNotNull
(
);
assert
That
(
projectType
.
getTags
().
get
(
"build"
)).
isEqualTo
(
"maven"
);
assert
That
(
projectType
.
getTags
().
get
(
"format"
)).
isEqualTo
(
"project"
);
}
private
static
InitializrServiceMetadata
createInstance
(
String
version
)
{
...
...
spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/InitializrServiceTests.java
View file @
962a5985
...
...
@@ -24,10 +24,7 @@ import org.junit.Rule;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
static
org
.
junit
.
Assert
.
assertArrayEquals
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Matchers
.
isA
;
import
static
org
.
mockito
.
Mockito
.
mock
;
...
...
@@ -48,7 +45,7 @@ public class InitializrServiceTests extends AbstractHttpClientMockTests {
public
void
loadMetadata
()
throws
IOException
{
mockSuccessfulMetadataGet
(
false
);
InitializrServiceMetadata
metadata
=
this
.
invoker
.
loadMetadata
(
"http://foo/bar"
);
assert
NotNull
(
metadata
);
assert
That
(
metadata
).
isNotNull
(
);
}
@Test
...
...
@@ -149,20 +146,20 @@ public class InitializrServiceTests extends AbstractHttpClientMockTests {
MockHttpProjectGenerationRequest
mockRequest
)
throws
IOException
{
mockSuccessfulProjectGeneration
(
mockRequest
);
ProjectGenerationResponse
entity
=
this
.
invoker
.
generate
(
request
);
assertArrayEquals
(
"wrong body content"
,
mockRequest
.
content
,
entity
.
getContent
());
assertThat
(
entity
.
getContent
()).
as
(
"wrong body content"
)
.
isEqualTo
(
mockRequest
.
content
);
return
entity
;
}
private
static
void
assertProjectEntity
(
ProjectGenerationResponse
entity
,
String
mimeType
,
String
fileName
)
{
if
(
mimeType
==
null
)
{
assert
Null
(
"No content type expected"
,
entity
.
getContentType
()
);
assert
That
(
entity
.
getContentType
()).
isNull
(
);
}
else
{
assertEquals
(
"wrong mime type"
,
mimeType
,
entity
.
getContentType
().
getMimeType
());
assertThat
(
entity
.
getContentType
().
getMimeType
()).
isEqualTo
(
mimeType
);
}
assert
Equals
(
"wrong filename"
,
fileName
,
entity
.
getFileName
()
);
assert
That
(
entity
.
getFileName
()).
isEqualTo
(
fileName
);
}
}
spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/ProjectGenerationRequestTests.java
View file @
962a5985
...
...
@@ -32,7 +32,7 @@ import org.springframework.core.io.ClassPathResource;
import
org.springframework.core.io.Resource
;
import
org.springframework.util.StreamUtils
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link ProjectGenerationRequest}
...
...
@@ -52,8 +52,8 @@ public class ProjectGenerationRequestTests {
@Test
public
void
defaultSettings
()
{
assert
Equals
(
createDefaultUrl
(
"?type=test-type"
),
this
.
request
.
generateUrl
(
createDefaultMetadata
()
));
assert
That
(
this
.
request
.
generateUrl
(
createDefaultMetadata
()))
.
isEqualTo
(
createDefaultUrl
(
"?type=test-type"
));
}
@Test
...
...
@@ -61,46 +61,44 @@ public class ProjectGenerationRequestTests {
String
customServerUrl
=
"http://foo:8080/initializr"
;
this
.
request
.
setServiceUrl
(
customServerUrl
);
this
.
request
.
getDependencies
().
add
(
"security"
);
assertEquals
(
new
URI
(
customServerUrl
+
"/starter.zip?dependencies=security&type=test-type"
),
this
.
request
.
generateUrl
(
createDefaultMetadata
()));
assertThat
(
this
.
request
.
generateUrl
(
createDefaultMetadata
())).
isEqualTo
(
new
URI
(
customServerUrl
+
"/starter.zip?dependencies=security&type=test-type"
));
}
@Test
public
void
customBootVersion
()
{
this
.
request
.
setBootVersion
(
"1.2.0.RELEASE"
);
assert
Equals
(
createDefaultUrl
(
"?type=test-type&bootVersion=1.2.0.RELEASE"
),
this
.
request
.
generateUrl
(
createDefaultMetadata
()
));
assert
That
(
this
.
request
.
generateUrl
(
createDefaultMetadata
()))
.
isEqualTo
(
createDefaultUrl
(
"?type=test-type&bootVersion=1.2.0.RELEASE"
));
}
@Test
public
void
singleDependency
()
{
this
.
request
.
getDependencies
().
add
(
"web"
);
assert
Equals
(
createDefaultUrl
(
"?dependencies=web&type=test-type"
),
this
.
request
.
generateUrl
(
createDefaultMetadata
()
));
assert
That
(
this
.
request
.
generateUrl
(
createDefaultMetadata
()))
.
isEqualTo
(
createDefaultUrl
(
"?dependencies=web&type=test-type"
));
}
@Test
public
void
multipleDependencies
()
{
this
.
request
.
getDependencies
().
add
(
"web"
);
this
.
request
.
getDependencies
().
add
(
"data-jpa"
);
assert
Equals
(
createDefaultUrl
(
"?dependencies=web%2Cdata-jpa&type=test-type"
),
this
.
request
.
generateUrl
(
createDefaultMetadata
()
));
assert
That
(
this
.
request
.
generateUrl
(
createDefaultMetadata
())).
isEqualTo
(
createDefaultUrl
(
"?dependencies=web%2Cdata-jpa&type=test-type"
));
}
@Test
public
void
customJavaVersion
()
{
this
.
request
.
setJavaVersion
(
"1.8"
);
assert
Equals
(
createDefaultUrl
(
"?type=test-type&javaVersion=1.8"
),
this
.
request
.
generateUrl
(
createDefaultMetadata
()
));
assert
That
(
this
.
request
.
generateUrl
(
createDefaultMetadata
()))
.
isEqualTo
(
createDefaultUrl
(
"?type=test-type&javaVersion=1.8"
));
}
@Test
public
void
customPackageName
()
{
this
.
request
.
setPackageName
(
"demo.foo"
);
assert
Equals
(
createDefaultUrl
(
"?packageName=demo.foo&type=test-type"
),
this
.
request
.
generateUrl
(
createDefaultMetadata
()
));
assert
That
(
this
.
request
.
generateUrl
(
createDefaultMetadata
()))
.
isEqualTo
(
createDefaultUrl
(
"?packageName=demo.foo&type=test-type"
));
}
@Test
...
...
@@ -110,24 +108,23 @@ public class ProjectGenerationRequestTests {
InitializrServiceMetadata
metadata
=
new
InitializrServiceMetadata
(
projectType
);
this
.
request
.
setType
(
"custom"
);
this
.
request
.
getDependencies
().
add
(
"data-rest"
);
assertEquals
(
new
URI
(
ProjectGenerationRequest
.
DEFAULT_SERVICE_URL
+
"/foo?dependencies=data-rest&type=custom"
),
this
.
request
.
generateUrl
(
metadata
));
assertThat
(
this
.
request
.
generateUrl
(
metadata
))
.
isEqualTo
(
new
URI
(
ProjectGenerationRequest
.
DEFAULT_SERVICE_URL
+
"/foo?dependencies=data-rest&type=custom"
));
}
@Test
public
void
customPackaging
()
{
this
.
request
.
setPackaging
(
"war"
);
assert
Equals
(
createDefaultUrl
(
"?type=test-type&packaging=war"
),
this
.
request
.
generateUrl
(
createDefaultMetadata
()
));
assert
That
(
this
.
request
.
generateUrl
(
createDefaultMetadata
()))
.
isEqualTo
(
createDefaultUrl
(
"?type=test-type&packaging=war"
));
}
@Test
public
void
customLanguage
()
{
this
.
request
.
setLanguage
(
"groovy"
);
assert
Equals
(
createDefaultUrl
(
"?type=test-type&language=groovy"
),
this
.
request
.
generateUrl
(
createDefaultMetadata
()
));
assert
That
(
this
.
request
.
generateUrl
(
createDefaultMetadata
()))
.
isEqualTo
(
createDefaultUrl
(
"?type=test-type&language=groovy"
));
}
@Test
...
...
@@ -136,40 +133,39 @@ public class ProjectGenerationRequestTests {
this
.
request
.
setArtifactId
(
"sample"
);
this
.
request
.
setVersion
(
"1.0.1-SNAPSHOT"
);
this
.
request
.
setDescription
(
"Spring Boot Test"
);
assert
Equals
(
createDefaultUrl
(
assert
That
(
this
.
request
.
generateUrl
(
createDefaultMetadata
()))
.
isEqualTo
(
createDefaultUrl
(
"?groupId=org.acme&artifactId=sample&version=1.0.1-SNAPSHOT"
+
"&description=Spring+Boot+Test&type=test-type"
),
this
.
request
.
generateUrl
(
createDefaultMetadata
()));
+
"&description=Spring+Boot+Test&type=test-type"
));
}
@Test
public
void
outputCustomizeArtifactId
()
{
this
.
request
.
setOutput
(
"my-project"
);
assert
Equals
(
createDefaultUrl
(
"?artifactId=my-project&type=test-type"
),
this
.
request
.
generateUrl
(
createDefaultMetadata
()
));
assert
That
(
this
.
request
.
generateUrl
(
createDefaultMetadata
()))
.
isEqualTo
(
createDefaultUrl
(
"?artifactId=my-project&type=test-type"
));
}
@Test
public
void
outputArchiveCustomizeArtifactId
()
{
this
.
request
.
setOutput
(
"my-project.zip"
);
assert
Equals
(
createDefaultUrl
(
"?artifactId=my-project&type=test-type"
),
this
.
request
.
generateUrl
(
createDefaultMetadata
()
));
assert
That
(
this
.
request
.
generateUrl
(
createDefaultMetadata
()))
.
isEqualTo
(
createDefaultUrl
(
"?artifactId=my-project&type=test-type"
));
}
@Test
public
void
outputArchiveWithDotsCustomizeArtifactId
()
{
this
.
request
.
setOutput
(
"my.nice.project.zip"
);
assert
Equals
(
createDefaultUrl
(
"?artifactId=my.nice.project&type=test-type"
),
this
.
request
.
generateUrl
(
createDefaultMetadata
()
));
assert
That
(
this
.
request
.
generateUrl
(
createDefaultMetadata
())).
isEqualTo
(
createDefaultUrl
(
"?artifactId=my.nice.project&type=test-type"
));
}
@Test
public
void
outputDoesNotOverrideCustomArtifactId
()
{
this
.
request
.
setOutput
(
"my-project"
);
this
.
request
.
setArtifactId
(
"my-id"
);
assert
Equals
(
createDefaultUrl
(
"?artifactId=my-id&type=test-type"
),
this
.
request
.
generateUrl
(
createDefaultMetadata
()
));
assert
That
(
this
.
request
.
generateUrl
(
createDefaultMetadata
()))
.
isEqualTo
(
createDefaultUrl
(
"?artifactId=my-id&type=test-type"
));
}
@Test
...
...
@@ -195,8 +191,8 @@ public class ProjectGenerationRequestTests {
public
void
buildOneMatch
()
{
InitializrServiceMetadata
metadata
=
readMetadata
();
setBuildAndFormat
(
"gradle"
,
null
);
assert
Equals
(
createDefaultUrl
(
"?type=gradle-project"
),
this
.
request
.
generateUrl
(
metadata
));
assert
That
(
this
.
request
.
generateUrl
(
metadata
))
.
isEqualTo
(
createDefaultUrl
(
"?type=gradle-project"
));
}
@Test
...
...
@@ -204,8 +200,8 @@ public class ProjectGenerationRequestTests {
InitializrServiceMetadata
metadata
=
readMetadata
();
setBuildAndFormat
(
"gradle"
,
"project"
);
this
.
request
.
setType
(
"maven-build"
);
assert
Equals
(
createUrl
(
"/pom.xml?type=maven-build"
),
this
.
request
.
generateUrl
(
metadata
));
assert
That
(
this
.
request
.
generateUrl
(
metadata
))
.
isEqualTo
(
createUrl
(
"/pom.xml?type=maven-build"
));
}
@Test
...
...
spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/ServiceCapabilitiesReportGeneratorTests.java
View file @
962a5985
...
...
@@ -20,9 +20,7 @@ import java.io.IOException;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link ServiceCapabilitiesReportGenerator}
...
...
@@ -40,7 +38,7 @@ public class ServiceCapabilitiesReportGeneratorTests extends AbstractHttpClientM
String
expected
=
new
String
(
readClasspathResource
(
"metadata/service-metadata-2.1.0.txt"
));
String
content
=
this
.
command
.
generate
(
"http://localhost"
);
assertThat
(
content
,
equalTo
(
expected
)
);
assertThat
(
content
).
isEqualTo
(
expected
);
}
@Test
...
...
@@ -57,10 +55,10 @@ public class ServiceCapabilitiesReportGeneratorTests extends AbstractHttpClientM
private
void
doTestGenerateCapabilitiesFromJson
()
throws
IOException
{
String
content
=
this
.
command
.
generate
(
"http://localhost"
);
assertThat
(
content
,
containsString
(
"aop - AOP"
)
);
assertThat
(
content
,
containsString
(
"security - Security: Security description"
)
);
assertThat
(
content
,
containsString
(
"type: maven-project"
)
);
assertThat
(
content
,
containsString
(
"packaging: jar"
)
);
assertThat
(
content
).
contains
(
"aop - AOP"
);
assertThat
(
content
).
contains
(
"security - Security: Security description"
);
assertThat
(
content
).
contains
(
"type: maven-project"
);
assertThat
(
content
).
contains
(
"packaging: jar"
);
}
}
spring-boot-cli/src/test/java/org/springframework/boot/cli/command/install/GroovyGrabDependencyResolverTests.java
View file @
962a5985
...
...
@@ -23,6 +23,7 @@ import java.util.HashSet;
import
java.util.List
;
import
java.util.Set
;
import
org.assertj.core.api.Condition
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -30,11 +31,11 @@ import org.springframework.boot.cli.compiler.GroovyCompilerConfiguration;
import
org.springframework.boot.cli.compiler.GroovyCompilerScope
;
import
org.springframework.boot.cli.compiler.RepositoryConfigurationFactory
;
import
org.springframework.boot.cli.compiler.grape.RepositoryConfiguration
;
import
org.springframework.boot.test.assertj.Matched
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
hamcrest
.
Matchers
.
hasItems
;
import
static
org
.
hamcrest
.
Matchers
.
hasSize
;
import
static
org
.
hamcrest
.
Matchers
.
startsWith
;
import
static
org
.
junit
.
Assert
.
assertThat
;
/**
* Tests for {@link GroovyGrabDependencyResolver}.
...
...
@@ -88,35 +89,35 @@ public class GroovyGrabDependencyResolverTests {
public
void
resolveArtifactWithNoDependencies
()
throws
Exception
{
List
<
File
>
resolved
=
this
.
resolver
.
resolve
(
Arrays
.
asList
(
"commons-logging:commons-logging:1.1.3"
));
assertThat
(
resolved
,
hasSize
(
1
)
);
assertThat
(
getNames
(
resolved
)
,
hasItems
(
"commons-logging-1.1.3.jar"
)
);
assertThat
(
resolved
).
hasSize
(
1
);
assertThat
(
getNames
(
resolved
)
).
containsOnly
(
"commons-logging-1.1.3.jar"
);
}
@Test
public
void
resolveArtifactWithDependencies
()
throws
Exception
{
List
<
File
>
resolved
=
this
.
resolver
.
resolve
(
Arrays
.
asList
(
"org.springframework:spring-core:4.1.1.RELEASE"
));
assertThat
(
resolved
,
hasSize
(
2
)
);
assertThat
(
getNames
(
resolved
),
hasItems
(
"commons-logging-1.1.3.jar"
,
"spring-core-4.1.1.RELEASE.jar"
)
);
assertThat
(
resolved
).
hasSize
(
2
);
assertThat
(
getNames
(
resolved
)
).
containsOnly
(
"commons-logging-1.1.3.jar"
,
"spring-core-4.1.1.RELEASE.jar"
);
}
@SuppressWarnings
(
"unchecked"
)
@Test
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
public
void
resolveShorthandArtifactWithDependencies
()
throws
Exception
{
List
<
File
>
resolved
=
this
.
resolver
.
resolve
(
Arrays
.
asList
(
"spring-core"
));
assertThat
(
resolved
,
hasSize
(
2
)
);
assertThat
(
getNames
(
resolved
)
,
hasItems
(
startsWith
(
"commons-logging-"
),
startsWith
(
"spring-core-"
)));
assertThat
(
resolved
).
hasSize
(
2
);
assertThat
(
getNames
(
resolved
)
).
has
((
Condition
)
Matched
.
by
(
hasItems
(
startsWith
(
"commons-logging-"
),
startsWith
(
"spring-core-"
)))
)
;
}
@Test
public
void
resolveMultipleArtifacts
()
throws
Exception
{
List
<
File
>
resolved
=
this
.
resolver
.
resolve
(
Arrays
.
asList
(
"junit:junit:4.11"
,
"commons-logging:commons-logging:1.1.3"
));
assertThat
(
resolved
,
hasSize
(
3
)
);
assertThat
(
getNames
(
resolved
)
,
hasItems
(
"junit-4.11.jar"
,
"commons-logging-1.1.3.jar"
,
"hamcrest-core-1.3.jar"
)
)
;
assertThat
(
resolved
).
hasSize
(
3
);
assertThat
(
getNames
(
resolved
)
).
containsOnly
(
"junit-4.11.jar"
,
"commons-logging-1.1.3.jar"
,
"hamcrest-core-1.3.jar"
);
}
public
Set
<
String
>
getNames
(
Collection
<
File
>
files
)
{
...
...
spring-boot-cli/src/test/java/org/springframework/boot/cli/command/install/InstallerTests.java
View file @
962a5985
...
...
@@ -30,9 +30,7 @@ import org.junit.rules.TemporaryFolder;
import
org.springframework.util.FileSystemUtils
;
import
static
org
.
hamcrest
.
Matchers
.
contains
;
import
static
org
.
hamcrest
.
Matchers
.
containsInAnyOrder
;
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
;
...
...
@@ -68,7 +66,7 @@ public class InstallerTests {
File
foo
=
createTemporaryFile
(
"foo.jar"
);
given
(
this
.
resolver
.
resolve
(
Arrays
.
asList
(
"foo"
))).
willReturn
(
Arrays
.
asList
(
foo
));
this
.
installer
.
install
(
Arrays
.
asList
(
"foo"
));
assertThat
(
getNamesOfFilesInLib
()
,
containsInAnyOrder
(
"foo.jar"
,
".installed"
)
);
assertThat
(
getNamesOfFilesInLib
()
).
containsOnly
(
"foo.jar"
,
".installed"
);
}
@Test
...
...
@@ -77,7 +75,7 @@ public class InstallerTests {
given
(
this
.
resolver
.
resolve
(
Arrays
.
asList
(
"foo"
))).
willReturn
(
Arrays
.
asList
(
foo
));
this
.
installer
.
install
(
Arrays
.
asList
(
"foo"
));
this
.
installer
.
uninstall
(
Arrays
.
asList
(
"foo"
));
assertThat
(
getNamesOfFilesInLib
()
,
contains
(
".installed"
)
);
assertThat
(
getNamesOfFilesInLib
()
).
contains
(
".installed"
);
}
@Test
...
...
@@ -89,21 +87,17 @@ public class InstallerTests {
.
willReturn
(
Arrays
.
asList
(
bravo
,
alpha
));
given
(
this
.
resolver
.
resolve
(
Arrays
.
asList
(
"charlie"
)))
.
willReturn
(
Arrays
.
asList
(
charlie
,
alpha
));
this
.
installer
.
install
(
Arrays
.
asList
(
"bravo"
));
assertThat
(
getNamesOfFilesInLib
(),
containsInAnyOrder
(
"alpha.jar"
,
"bravo.jar"
,
".installed"
));
assertThat
(
getNamesOfFilesInLib
()).
containsOnly
(
"alpha.jar"
,
"bravo.jar"
,
".installed"
);
this
.
installer
.
install
(
Arrays
.
asList
(
"charlie"
));
assertThat
(
getNamesOfFilesInLib
(),
containsInAnyOrder
(
"alpha.jar"
,
"bravo.jar"
,
"charlie.jar"
,
".installed"
));
assertThat
(
getNamesOfFilesInLib
()).
containsOnly
(
"alpha.jar"
,
"bravo.jar"
,
"charlie.jar"
,
".installed"
);
this
.
installer
.
uninstall
(
Arrays
.
asList
(
"bravo"
));
assertThat
(
getNamesOfFilesInLib
(),
containsInAnyOrder
(
"alpha.jar"
,
"charlie.jar"
,
".installed"
));
assertThat
(
getNamesOfFilesInLib
()).
containsOnly
(
"alpha.jar"
,
"charlie.jar"
,
".installed"
);
this
.
installer
.
uninstall
(
Arrays
.
asList
(
"charlie"
));
assertThat
(
getNamesOfFilesInLib
()
,
containsInAnyOrder
(
".installed"
)
);
assertThat
(
getNamesOfFilesInLib
()
).
containsOnly
(
".installed"
);
}
@Test
...
...
@@ -111,19 +105,16 @@ public class InstallerTests {
File
alpha
=
createTemporaryFile
(
"alpha.jar"
);
File
bravo
=
createTemporaryFile
(
"bravo.jar"
);
File
charlie
=
createTemporaryFile
(
"charlie.jar"
);
given
(
this
.
resolver
.
resolve
(
Arrays
.
asList
(
"bravo"
)))
.
willReturn
(
Arrays
.
asList
(
bravo
,
alpha
));
given
(
this
.
resolver
.
resolve
(
Arrays
.
asList
(
"charlie"
)))
.
willReturn
(
Arrays
.
asList
(
charlie
,
alpha
));
this
.
installer
.
install
(
Arrays
.
asList
(
"bravo"
));
this
.
installer
.
install
(
Arrays
.
asList
(
"charlie"
));
assertThat
(
getNamesOfFilesInLib
(),
containsInAnyOrder
(
"alpha.jar"
,
"bravo.jar"
,
"charlie.jar"
,
".installed"
));
assertThat
(
getNamesOfFilesInLib
()).
containsOnly
(
"alpha.jar"
,
"bravo.jar"
,
"charlie.jar"
,
".installed"
);
this
.
installer
.
uninstallAll
();
assertThat
(
getNamesOfFilesInLib
()
,
containsInAnyOrder
(
".installed"
)
);
assertThat
(
getNamesOfFilesInLib
()
).
containsOnly
(
".installed"
);
}
private
Set
<
String
>
getNamesOfFilesInLib
()
{
...
...
spring-boot-cli/src/test/java/org/springframework/boot/cli/command/shell/EscapeAwareWhiteSpaceArgumentDelimiterTests.java
View file @
962a5985
...
...
@@ -19,8 +19,7 @@ package org.springframework.boot.cli.command.shell;
import
jline.console.completer.ArgumentCompleter.ArgumentList
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link EscapeAwareWhiteSpaceArgumentDelimiter}.
...
...
@@ -34,68 +33,63 @@ public class EscapeAwareWhiteSpaceArgumentDelimiterTests {
@Test
public
void
simple
()
throws
Exception
{
String
s
=
"one two"
;
assertThat
(
this
.
delimiter
.
delimit
(
s
,
0
).
getArguments
(),
equalTo
(
new
String
[]
{
"one"
,
"two"
}));
assertThat
(
this
.
delimiter
.
parseArguments
(
s
),
equalTo
(
new
String
[]
{
"one"
,
"two"
}));
assertThat
(
this
.
delimiter
.
isDelimiter
(
s
,
2
),
equalTo
(
false
));
assertThat
(
this
.
delimiter
.
isDelimiter
(
s
,
3
),
equalTo
(
true
));
assertThat
(
this
.
delimiter
.
isDelimiter
(
s
,
4
),
equalTo
(
false
));
assertThat
(
this
.
delimiter
.
delimit
(
s
,
0
).
getArguments
()).
containsExactly
(
"one"
,
"two"
);
assertThat
(
this
.
delimiter
.
parseArguments
(
s
)).
containsExactly
(
"one"
,
"two"
);
assertThat
(
this
.
delimiter
.
isDelimiter
(
s
,
2
)).
isFalse
();
assertThat
(
this
.
delimiter
.
isDelimiter
(
s
,
3
)).
isTrue
();
assertThat
(
this
.
delimiter
.
isDelimiter
(
s
,
4
)).
isFalse
();
}
@Test
public
void
escaped
()
throws
Exception
{
String
s
=
"o\\ ne two"
;
assertThat
(
this
.
delimiter
.
delimit
(
s
,
0
).
getArguments
(),
equalTo
(
new
String
[]
{
"o\\ ne"
,
"two"
}));
assertThat
(
this
.
delimiter
.
parseArguments
(
s
),
equalTo
(
new
String
[]
{
"o ne"
,
"two"
}));
assertThat
(
this
.
delimiter
.
isDelimiter
(
s
,
2
),
equalTo
(
false
));
assertThat
(
this
.
delimiter
.
isDelimiter
(
s
,
3
),
equalTo
(
false
));
assertThat
(
this
.
delimiter
.
isDelimiter
(
s
,
4
),
equalTo
(
false
));
assertThat
(
this
.
delimiter
.
isDelimiter
(
s
,
5
),
equalTo
(
true
));
assertThat
(
this
.
delimiter
.
delimit
(
s
,
0
).
getArguments
()).
containsExactly
(
"o\\ ne"
,
"two"
);
assertThat
(
this
.
delimiter
.
parseArguments
(
s
)).
containsExactly
(
"o ne"
,
"two"
);
assertThat
(
this
.
delimiter
.
isDelimiter
(
s
,
2
)).
isFalse
();
assertThat
(
this
.
delimiter
.
isDelimiter
(
s
,
3
)).
isFalse
();
assertThat
(
this
.
delimiter
.
isDelimiter
(
s
,
4
)).
isFalse
();
assertThat
(
this
.
delimiter
.
isDelimiter
(
s
,
5
)).
isTrue
();
}
@Test
public
void
quoted
()
throws
Exception
{
String
s
=
"'o ne' 't w o'"
;
assertThat
(
this
.
delimiter
.
delimit
(
s
,
0
).
getArguments
(),
equalTo
(
new
String
[]
{
"'o ne'"
,
"'t w o'"
}));
assertThat
(
this
.
delimiter
.
parseArguments
(
s
),
equalTo
(
new
String
[]
{
"o ne"
,
"t w o"
}));
assertThat
(
this
.
delimiter
.
delimit
(
s
,
0
).
getArguments
()).
containsExactly
(
"'o ne'"
,
"'t w o'"
);
assertThat
(
this
.
delimiter
.
parseArguments
(
s
)).
containsExactly
(
"o ne"
,
"t w o"
);
}
@Test
public
void
doubleQuoted
()
throws
Exception
{
String
s
=
"\"o ne\" \"t w o\""
;
assertThat
(
this
.
delimiter
.
delimit
(
s
,
0
).
getArguments
(),
equalTo
(
new
String
[]
{
"\"o ne\""
,
"\"t w o\""
}));
assertThat
(
this
.
delimiter
.
parseArguments
(
s
),
equalTo
(
new
String
[]
{
"o ne"
,
"t w o"
}));
assertThat
(
this
.
delimiter
.
delimit
(
s
,
0
).
getArguments
())
.
containsExactly
(
"\"o ne\""
,
"\"t w o\""
);
assertThat
(
this
.
delimiter
.
parseArguments
(
s
)).
containsExactly
(
"o ne"
,
"t w o"
);
}
@Test
public
void
nestedQuotes
()
throws
Exception
{
String
s
=
"\"o 'n''e\" 't \"w o'"
;
assertThat
(
this
.
delimiter
.
delimit
(
s
,
0
).
getArguments
()
,
equalTo
(
new
String
[]
{
"\"o 'n''e\""
,
"'t \"w o'"
})
);
assertThat
(
this
.
delimiter
.
parseArguments
(
s
),
equalTo
(
new
String
[]
{
"o 'n''e"
,
"t \"w o"
})
);
assertThat
(
this
.
delimiter
.
delimit
(
s
,
0
).
getArguments
()
)
.
containsExactly
(
"\"o 'n''e\""
,
"'t \"w o'"
);
assertThat
(
this
.
delimiter
.
parseArguments
(
s
)
).
containsExactly
(
"o 'n''e"
,
"t \"w o"
);
}
@Test
public
void
escapedQuotes
()
throws
Exception
{
String
s
=
"\\'a b"
;
ArgumentList
argumentList
=
this
.
delimiter
.
delimit
(
s
,
0
);
assertThat
(
argumentList
.
getArguments
()
,
equalTo
(
new
String
[]
{
"\\'a"
,
"b"
})
);
assertThat
(
this
.
delimiter
.
parseArguments
(
s
)
,
equalTo
(
new
String
[]
{
"'a"
,
"b"
})
);
assertThat
(
argumentList
.
getArguments
()
).
isEqualTo
(
new
String
[]
{
"\\'a"
,
"b"
}
);
assertThat
(
this
.
delimiter
.
parseArguments
(
s
)
).
containsExactly
(
"'a"
,
"b"
);
}
@Test
public
void
escapes
()
throws
Exception
{
String
s
=
"\\ \\\\.\\\\\\t"
;
assertThat
(
this
.
delimiter
.
parseArguments
(
s
),
equalTo
(
new
String
[]
{
" \\.\\\t"
}));
assertThat
(
this
.
delimiter
.
parseArguments
(
s
)).
containsExactly
(
" \\.\\\t"
);
}
}
spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/DependencyCustomizerTests.java
View file @
962a5985
...
...
@@ -33,8 +33,7 @@ import org.mockito.MockitoAnnotations;
import
org.springframework.boot.cli.compiler.dependencies.ArtifactCoordinatesResolver
;
import
org.springframework.boot.cli.compiler.grape.DependencyResolutionContext
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
/**
...
...
@@ -78,7 +77,7 @@ public class DependencyCustomizerTests {
this
.
dependencyCustomizer
.
add
(
"spring-boot-starter-logging"
);
List
<
AnnotationNode
>
grabAnnotations
=
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
));
assert
Equals
(
1
,
grabAnnotations
.
size
()
);
assert
That
(
grabAnnotations
).
hasSize
(
1
);
AnnotationNode
annotationNode
=
grabAnnotations
.
get
(
0
);
assertGrabAnnotation
(
annotationNode
,
"org.springframework.boot"
,
"spring-boot-starter-logging"
,
"1.2.3"
,
null
,
null
,
true
);
...
...
@@ -89,7 +88,7 @@ public class DependencyCustomizerTests {
this
.
dependencyCustomizer
.
add
(
"spring-boot-starter-logging"
,
false
);
List
<
AnnotationNode
>
grabAnnotations
=
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
));
assert
Equals
(
1
,
grabAnnotations
.
size
()
);
assert
That
(
grabAnnotations
).
hasSize
(
1
);
AnnotationNode
annotationNode
=
grabAnnotations
.
get
(
0
);
assertGrabAnnotation
(
annotationNode
,
"org.springframework.boot"
,
"spring-boot-starter-logging"
,
"1.2.3"
,
null
,
null
,
false
);
...
...
@@ -101,7 +100,7 @@ public class DependencyCustomizerTests {
"my-type"
,
false
);
List
<
AnnotationNode
>
grabAnnotations
=
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
));
assert
Equals
(
1
,
grabAnnotations
.
size
()
);
assert
That
(
grabAnnotations
).
hasSize
(
1
);
AnnotationNode
annotationNode
=
grabAnnotations
.
get
(
0
);
assertGrabAnnotation
(
annotationNode
,
"org.springframework.boot"
,
"spring-boot-starter-logging"
,
"1.2.3"
,
"my-classifier"
,
"my-type"
,
...
...
@@ -112,7 +111,7 @@ public class DependencyCustomizerTests {
public
void
anyMissingClassesWithMissingClassesPerformsAdd
()
{
this
.
dependencyCustomizer
.
ifAnyMissingClasses
(
"does.not.Exist"
)
.
add
(
"spring-boot-starter-logging"
);
assert
Equals
(
1
,
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
)).
size
()
);
assert
That
(
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
))).
hasSize
(
1
);
}
@Test
...
...
@@ -120,21 +119,21 @@ public class DependencyCustomizerTests {
this
.
dependencyCustomizer
.
ifAnyMissingClasses
(
getClass
().
getName
(),
"does.not.Exist"
)
.
add
(
"spring-boot-starter-logging"
);
assert
Equals
(
1
,
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
)).
size
()
);
assert
That
(
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
))).
hasSize
(
1
);
}
@Test
public
void
anyMissingClassesWithNoMissingClassesDoesNotPerformAdd
()
{
this
.
dependencyCustomizer
.
ifAnyMissingClasses
(
getClass
().
getName
())
.
add
(
"spring-boot-starter-logging"
);
assert
Equals
(
0
,
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
)).
size
()
);
assert
That
(
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
))).
isEmpty
(
);
}
@Test
public
void
allMissingClassesWithNoMissingClassesDoesNotPerformAdd
()
{
this
.
dependencyCustomizer
.
ifAllMissingClasses
(
getClass
().
getName
())
.
add
(
"spring-boot-starter-logging"
);
assert
Equals
(
0
,
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
)).
size
()
);
assert
That
(
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
))).
isEmpty
(
);
}
@Test
...
...
@@ -142,7 +141,7 @@ public class DependencyCustomizerTests {
this
.
dependencyCustomizer
.
ifAllMissingClasses
(
getClass
().
getName
(),
"does.not.Exist"
)
.
add
(
"spring-boot-starter-logging"
);
assert
Equals
(
0
,
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
)).
size
()
);
assert
That
(
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
))).
isEmpty
(
);
}
@Test
...
...
@@ -150,27 +149,28 @@ public class DependencyCustomizerTests {
this
.
dependencyCustomizer
.
ifAllMissingClasses
(
"does.not.Exist"
,
"does.not.exist.Either"
)
.
add
(
"spring-boot-starter-logging"
);
assert
Equals
(
1
,
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
)).
size
()
);
assert
That
(
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
))).
hasSize
(
1
);
}
private
void
assertGrabAnnotation
(
AnnotationNode
annotationNode
,
String
group
,
String
module
,
String
version
,
String
classifier
,
String
type
,
boolean
transitive
)
{
assert
Equals
(
group
,
getMemberValue
(
annotationNode
,
"group"
)
);
assert
Equals
(
module
,
getMemberValue
(
annotationNode
,
"module"
)
);
assert
That
(
getMemberValue
(
annotationNode
,
"group"
)).
isEqualTo
(
group
);
assert
That
(
getMemberValue
(
annotationNode
,
"module"
)).
isEqualTo
(
module
);
if
(
type
==
null
)
{
assert
Null
(
annotationNode
.
getMember
(
"type"
)
);
assert
That
(
annotationNode
.
getMember
(
"type"
)).
isNull
(
);
}
else
{
assert
Equals
(
type
,
getMemberValue
(
annotationNode
,
"type"
)
);
assert
That
(
getMemberValue
(
annotationNode
,
"type"
)).
isEqualTo
(
type
);
}
if
(
classifier
==
null
)
{
assert
Null
(
annotationNode
.
getMember
(
"classifier"
)
);
assert
That
(
annotationNode
.
getMember
(
"classifier"
)).
isNull
(
);
}
else
{
assertEquals
(
classifier
,
getMemberValue
(
annotationNode
,
"classifier"
));
assertThat
(
getMemberValue
(
annotationNode
,
"classifier"
))
.
isEqualTo
(
classifier
);
}
assert
Equals
(
transitive
,
getMemberValue
(
annotationNode
,
"transitive"
)
);
assert
That
(
getMemberValue
(
annotationNode
,
"transitive"
)).
isEqualTo
(
transitive
);
}
private
Object
getMemberValue
(
AnnotationNode
annotationNode
,
String
member
)
{
...
...
spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/ExtendedGroovyClassLoaderTests.java
View file @
962a5985
...
...
@@ -21,8 +21,7 @@ import org.junit.Rule;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
static
org
.
hamcrest
.
Matchers
.
sameInstance
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link ExtendedGroovyClassLoader}.
...
...
@@ -49,7 +48,7 @@ public class ExtendedGroovyClassLoaderTests {
public
void
loadsGroovyFromSameClassLoader
()
throws
Exception
{
Class
<?>
c1
=
this
.
contextClassLoader
.
loadClass
(
"groovy.lang.Script"
);
Class
<?>
c2
=
this
.
defaultScopeGroovyClassLoader
.
loadClass
(
"groovy.lang.Script"
);
assertThat
(
c1
.
getClassLoader
()
,
sameInstance
(
c2
.
getClassLoader
()
));
assertThat
(
c1
.
getClassLoader
()
).
isSameAs
(
c2
.
getClassLoader
(
));
}
@Test
...
...
spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/GenericBomAstTransformationTests.java
View file @
962a5985
...
...
@@ -35,7 +35,7 @@ import org.junit.Test;
import
org.springframework.boot.groovy.DependencyManagementBom
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link ResolveDependencyCoordinatesTransformation}
...
...
@@ -68,14 +68,14 @@ public final class GenericBomAstTransformationTests {
public
void
transformationOfEmptyPackage
()
{
this
.
moduleNode
.
setPackage
(
new
PackageNode
(
"foo"
));
this
.
transformation
.
visit
(
new
ASTNode
[]
{
this
.
moduleNode
},
this
.
sourceUnit
);
assert
Equals
(
"[test:child:1.0.0]"
,
getValue
().
toString
()
);
assert
That
(
getValue
().
toString
()).
isEqualTo
(
"[test:child:1.0.0]"
);
}
@Test
public
void
transformationOfClass
()
{
this
.
moduleNode
.
addClass
(
ClassHelper
.
make
(
"MyClass"
));
this
.
transformation
.
visit
(
new
ASTNode
[]
{
this
.
moduleNode
},
this
.
sourceUnit
);
assert
Equals
(
"[test:child:1.0.0]"
,
getValue
().
toString
()
);
assert
That
(
getValue
().
toString
()).
isEqualTo
(
"[test:child:1.0.0]"
);
}
@Test
...
...
@@ -88,7 +88,8 @@ public final class GenericBomAstTransformationTests {
annotation
.
addMember
(
"value"
,
new
ConstantExpression
(
"test:parent:1.0.0"
));
cls
.
addAnnotation
(
annotation
);
this
.
transformation
.
visit
(
new
ASTNode
[]
{
this
.
moduleNode
},
this
.
sourceUnit
);
assertEquals
(
"[test:parent:1.0.0, test:child:1.0.0]"
,
getValue
().
toString
());
assertThat
(
getValue
().
toString
())
.
isEqualTo
(
"[test:parent:1.0.0, test:child:1.0.0]"
);
}
private
List
<
String
>
getValue
()
{
...
...
spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/RepositoryConfigurationFactoryTests.java
View file @
962a5985
...
...
@@ -25,9 +25,7 @@ import org.junit.Test;
import
org.springframework.boot.cli.compiler.grape.RepositoryConfiguration
;
import
org.springframework.boot.cli.util.SystemProperties
;
import
static
org
.
hamcrest
.
Matchers
.
hasItems
;
import
static
org
.
hamcrest
.
Matchers
.
hasSize
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link RepositoryConfigurationFactory}
...
...
@@ -107,11 +105,12 @@ public class RepositoryConfigurationFactoryTests {
private
void
assertRepositoryConfiguration
(
List
<
RepositoryConfiguration
>
configurations
,
String
...
expectedNames
)
{
assertThat
(
configurations
,
hasSize
(
expectedNames
.
length
)
);
assertThat
(
configurations
).
hasSize
(
expectedNames
.
length
);
Set
<
String
>
actualNames
=
new
HashSet
<
String
>();
for
(
RepositoryConfiguration
configuration
:
configurations
)
{
actualNames
.
add
(
configuration
.
getName
());
}
assertThat
(
actualNames
,
hasItems
(
expectedNames
)
);
assertThat
(
actualNames
).
containsOnly
(
expectedNames
);
}
}
spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/ResolveDependencyCoordinatesTransformationTests.java
View file @
962a5985
...
...
@@ -45,7 +45,7 @@ import org.junit.Test;
import
org.springframework.boot.cli.compiler.dependencies.ArtifactCoordinatesResolver
;
import
org.springframework.boot.cli.compiler.grape.DependencyResolutionContext
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
...
...
@@ -220,9 +220,9 @@ public final class ResolveDependencyCoordinatesTransformationTests {
private
void
assertGrabAnnotationHasBeenTransformed
()
{
this
.
transformation
.
visit
(
new
ASTNode
[]
{
this
.
moduleNode
},
this
.
sourceUnit
);
assertEquals
(
"org.springframework"
,
getGrabAnnotationMemberAsString
(
"group"
)
);
assert
Equals
(
"spring-core"
,
getGrabAnnotationMemberAsString
(
"module"
)
);
assertThat
(
getGrabAnnotationMemberAsString
(
"group"
))
.
isEqualTo
(
"org.springframework"
);
assert
That
(
getGrabAnnotationMemberAsString
(
"module"
)).
isEqualTo
(
"spring-core"
);
}
private
Object
getGrabAnnotationMemberAsString
(
String
memberName
)
{
...
...
spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/dependencies/CompositeDependencyManagementTests.java
View file @
962a5985
...
...
@@ -23,10 +23,7 @@ import org.junit.runner.RunWith;
import
org.mockito.Mock
;
import
org.mockito.runners.MockitoJUnitRunner
;
import
static
org
.
hamcrest
.
Matchers
.
contains
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
nullValue
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
/**
...
...
@@ -47,10 +44,8 @@ public class CompositeDependencyManagementTests {
public
void
unknownSpringBootVersion
()
{
given
(
this
.
dependencyManagement1
.
getSpringBootVersion
()).
willReturn
(
null
);
given
(
this
.
dependencyManagement2
.
getSpringBootVersion
()).
willReturn
(
null
);
assertThat
(
new
CompositeDependencyManagement
(
this
.
dependencyManagement1
,
this
.
dependencyManagement2
).
getSpringBootVersion
(),
is
(
nullValue
()));
assertThat
(
new
CompositeDependencyManagement
(
this
.
dependencyManagement1
,
this
.
dependencyManagement2
).
getSpringBootVersion
()).
isNull
();
}
@Test
...
...
@@ -58,7 +53,7 @@ public class CompositeDependencyManagementTests {
given
(
this
.
dependencyManagement1
.
getSpringBootVersion
()).
willReturn
(
"1.2.3"
);
given
(
this
.
dependencyManagement2
.
getSpringBootVersion
()).
willReturn
(
"1.2.4"
);
assertThat
(
new
CompositeDependencyManagement
(
this
.
dependencyManagement1
,
this
.
dependencyManagement2
).
getSpringBootVersion
()
,
is
(
"1.2.3"
)
);
this
.
dependencyManagement2
).
getSpringBootVersion
()
).
isEqualTo
(
"1.2.3"
);
}
@Test
...
...
@@ -66,7 +61,7 @@ public class CompositeDependencyManagementTests {
given
(
this
.
dependencyManagement1
.
find
(
"artifact"
)).
willReturn
(
null
);
given
(
this
.
dependencyManagement2
.
find
(
"artifact"
)).
willReturn
(
null
);
assertThat
(
new
CompositeDependencyManagement
(
this
.
dependencyManagement1
,
this
.
dependencyManagement2
).
find
(
"artifact"
)
,
is
(
nullValue
())
);
this
.
dependencyManagement2
).
find
(
"artifact"
)
).
isNull
(
);
}
@Test
...
...
@@ -75,10 +70,9 @@ public class CompositeDependencyManagementTests {
.
willReturn
(
new
Dependency
(
"test"
,
"artifact"
,
"1.2.3"
));
given
(
this
.
dependencyManagement2
.
find
(
"artifact"
))
.
willReturn
(
new
Dependency
(
"test"
,
"artifact"
,
"1.2.4"
));
assertThat
(
new
CompositeDependencyManagement
(
this
.
dependencyManagement1
,
this
.
dependencyManagement2
).
find
(
"artifact"
),
is
(
new
Dependency
(
"test"
,
"artifact"
,
"1.2.3"
)));
assertThat
(
new
CompositeDependencyManagement
(
this
.
dependencyManagement1
,
this
.
dependencyManagement2
).
find
(
"artifact"
))
.
isEqualTo
(
new
Dependency
(
"test"
,
"artifact"
,
"1.2.3"
));
}
@Test
...
...
@@ -87,11 +81,10 @@ public class CompositeDependencyManagementTests {
.
willReturn
(
Arrays
.
asList
(
new
Dependency
(
"test"
,
"artifact"
,
"1.2.3"
)));
given
(
this
.
dependencyManagement2
.
getDependencies
())
.
willReturn
(
Arrays
.
asList
(
new
Dependency
(
"test"
,
"artifact"
,
"1.2.4"
)));
assertThat
(
new
CompositeDependencyManagement
(
this
.
dependencyManagement1
,
this
.
dependencyManagement2
).
getDependencies
(),
contains
(
new
Dependency
(
"test"
,
"artifact"
,
"1.2.3"
),
new
Dependency
(
"test"
,
"artifact"
,
"1.2.4"
)));
assertThat
(
new
CompositeDependencyManagement
(
this
.
dependencyManagement1
,
this
.
dependencyManagement2
).
getDependencies
()).
containsOnly
(
new
Dependency
(
"test"
,
"artifact"
,
"1.2.3"
),
new
Dependency
(
"test"
,
"artifact"
,
"1.2.4"
));
}
}
spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/dependencies/DependencyManagementArtifactCoordinatesResolverTests.java
View file @
962a5985
...
...
@@ -19,9 +19,7 @@ package org.springframework.boot.cli.compiler.dependencies;
import
org.junit.Before
;
import
org.junit.Test
;
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
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Matchers
.
anyString
;
import
static
org
.
mockito
.
Mockito
.
mock
;
...
...
@@ -52,19 +50,19 @@ public class DependencyManagementArtifactCoordinatesResolverTests {
@Test
public
void
getGroupIdForBootArtifact
()
throws
Exception
{
assertThat
(
this
.
resolver
.
getGroupId
(
"spring-boot-something"
)
,
equalTo
(
"org.springframework.boot"
)
);
assertThat
(
this
.
resolver
.
getGroupId
(
"spring-boot-something"
)
)
.
isEqualTo
(
"org.springframework.boot"
);
verify
(
this
.
dependencyManagement
,
never
()).
find
(
anyString
());
}
@Test
public
void
getGroupIdFound
()
throws
Exception
{
assertThat
(
this
.
resolver
.
getGroupId
(
"a1"
)
,
equalTo
(
"g1"
)
);
assertThat
(
this
.
resolver
.
getGroupId
(
"a1"
)
).
isEqualTo
(
"g1"
);
}
@Test
public
void
getGroupIdNotFound
()
throws
Exception
{
assertThat
(
this
.
resolver
.
getGroupId
(
"a2"
)
,
nullValue
()
);
assertThat
(
this
.
resolver
.
getGroupId
(
"a2"
)
).
isNull
(
);
}
}
spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/dependencies/SpringBootDependenciesDependencyManagementTests.java
View file @
962a5985
...
...
@@ -18,12 +18,8 @@ package org.springframework.boot.cli.compiler.dependencies;
import
org.junit.Test
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
hamcrest
.
Matchers
.
empty
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
not
;
import
static
org
.
hamcrest
.
Matchers
.
notNullValue
;
import
static
org
.
junit
.
Assert
.
assertThat
;
/**
* Tests for {@link SpringBootDependenciesDependencyManagement}
...
...
@@ -36,20 +32,20 @@ public class SpringBootDependenciesDependencyManagementTests {
@Test
public
void
springBootVersion
()
{
assertThat
(
this
.
dependencyManagement
.
getSpringBootVersion
()
,
is
(
notNullValue
())
);
assertThat
(
this
.
dependencyManagement
.
getSpringBootVersion
()
).
isNotNull
(
);
}
@Test
public
void
find
()
{
Dependency
dependency
=
this
.
dependencyManagement
.
find
(
"spring-boot"
);
assertThat
(
dependency
,
is
(
notNullValue
())
);
assertThat
(
dependency
.
getGroupId
()
,
is
(
equalTo
(
"org.springframework.boot"
))
);
assertThat
(
dependency
.
getArtifactId
()
,
is
(
equalTo
(
"spring-boot"
))
);
assertThat
(
dependency
).
isNotNull
(
);
assertThat
(
dependency
.
getGroupId
()
).
isEqualTo
(
"org.springframework.boot"
);
assertThat
(
dependency
.
getArtifactId
()
).
isEqualTo
(
"spring-boot"
);
}
@Test
public
void
getDependencies
()
{
assertThat
(
this
.
dependencyManagement
.
getDependencies
()
,
is
(
not
(
empty
())
));
assertThat
(
this
.
dependencyManagement
.
getDependencies
()
).
isNotEqualTo
(
empty
(
));
}
}
spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java
View file @
962a5985
...
...
@@ -34,9 +34,7 @@ import org.junit.Test;
import
org.springframework.test.util.ReflectionTestUtils
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link AetherGrapeEngine}.
...
...
@@ -63,11 +61,9 @@ public class AetherGrapeEngineTests {
@Test
public
void
dependencyResolution
()
{
Map
<
String
,
Object
>
args
=
new
HashMap
<
String
,
Object
>();
createGrapeEngine
(
this
.
springMilestones
).
grab
(
args
,
createDependency
(
"org.springframework"
,
"spring-jdbc"
,
"3.2.4.RELEASE"
));
assertEquals
(
5
,
this
.
groovyClassLoader
.
getURLs
().
length
);
assertThat
(
this
.
groovyClassLoader
.
getURLs
()).
hasSize
(
5
);
}
@Test
...
...
@@ -81,8 +77,10 @@ public class AetherGrapeEngineTests {
DefaultRepositorySystemSession
session
=
(
DefaultRepositorySystemSession
)
ReflectionTestUtils
.
getField
(
grapeEngine
,
"session"
);
assertTrue
(
session
.
getProxySelector
()
instanceof
CompositeProxySelector
);
assertThat
(
session
.
getProxySelector
()
instanceof
CompositeProxySelector
)
.
isTrue
();
}
});
}
...
...
@@ -97,8 +95,8 @@ public class AetherGrapeEngineTests {
List
<
RemoteRepository
>
repositories
=
(
List
<
RemoteRepository
>)
ReflectionTestUtils
.
getField
(
grapeEngine
,
"repositories"
);
assert
Equals
(
1
,
repositories
.
size
()
);
assert
Equals
(
"central-mirror"
,
repositories
.
get
(
0
).
getId
()
);
assert
That
(
repositories
).
hasSize
(
1
);
assert
That
(
repositories
.
get
(
0
).
getId
()).
isEqualTo
(
"central-mirror"
);
}
});
}
...
...
@@ -114,9 +112,9 @@ public class AetherGrapeEngineTests {
List
<
RemoteRepository
>
repositories
=
(
List
<
RemoteRepository
>)
ReflectionTestUtils
.
getField
(
grapeEngine
,
"repositories"
);
assert
Equals
(
1
,
repositories
.
size
()
);
assert
That
(
repositories
).
hasSize
(
1
);
Authentication
authentication
=
repositories
.
get
(
0
).
getAuthentication
();
assert
NotNull
(
authentication
);
assert
That
(
authentication
).
isNotNull
(
);
}
});
}
...
...
@@ -131,7 +129,7 @@ public class AetherGrapeEngineTests {
createDependency
(
"org.springframework"
,
"spring-jdbc"
,
"3.2.4.RELEASE"
),
createDependency
(
"org.springframework"
,
"spring-beans"
,
"3.2.4.RELEASE"
));
assert
Equals
(
3
,
this
.
groovyClassLoader
.
getURLs
().
length
);
assert
That
(
this
.
groovyClassLoader
.
getURLs
().
length
).
isEqualTo
(
3
);
}
@Test
...
...
@@ -141,7 +139,7 @@ public class AetherGrapeEngineTests {
createGrapeEngine
().
grab
(
args
,
createDependency
(
"org.springframework"
,
"spring-jdbc"
,
"3.2.4.RELEASE"
,
false
));
assert
Equals
(
1
,
this
.
groovyClassLoader
.
getURLs
().
length
);
assert
That
(
this
.
groovyClassLoader
.
getURLs
().
length
).
isEqualTo
(
1
);
}
@Test
...
...
@@ -153,8 +151,8 @@ public class AetherGrapeEngineTests {
createGrapeEngine
(
this
.
springMilestones
).
grab
(
args
,
createDependency
(
"org.springframework"
,
"spring-jdbc"
,
"3.2.4.RELEASE"
));
assert
Equals
(
0
,
this
.
groovyClassLoader
.
getURLs
().
length
);
assert
Equals
(
5
,
customClassLoader
.
getURLs
().
length
);
assert
That
(
this
.
groovyClassLoader
.
getURLs
().
length
).
isEqualTo
(
0
);
assert
That
(
customClassLoader
.
getURLs
().
length
).
isEqualTo
(
5
);
}
@Test
...
...
@@ -164,7 +162,7 @@ public class AetherGrapeEngineTests {
grapeEngine
.
addResolver
(
createResolver
(
"restlet.org"
,
"http://maven.restlet.org"
));
grapeEngine
.
grab
(
args
,
createDependency
(
"org.restlet"
,
"org.restlet"
,
"1.1.6"
));
assert
Equals
(
1
,
this
.
groovyClassLoader
.
getURLs
().
length
);
assert
That
(
this
.
groovyClassLoader
.
getURLs
().
length
).
isEqualTo
(
1
);
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
...
...
@@ -184,8 +182,8 @@ public class AetherGrapeEngineTests {
dependency
.
put
(
"type"
,
"pom"
);
createGrapeEngine
().
grab
(
args
,
dependency
);
URL
[]
urls
=
this
.
groovyClassLoader
.
getURLs
();
assert
Equals
(
1
,
urls
.
length
);
assertT
rue
(
urls
[
0
].
toExternalForm
().
endsWith
(
".pom"
)
);
assert
That
(
urls
.
length
).
isEqualTo
(
1
);
assertT
hat
(
urls
[
0
].
toExternalForm
().
endsWith
(
".pom"
)).
isTrue
(
);
}
@Test
...
...
@@ -196,8 +194,8 @@ public class AetherGrapeEngineTests {
dependency
.
put
(
"ext"
,
"pom"
);
createGrapeEngine
().
grab
(
args
,
dependency
);
URL
[]
urls
=
this
.
groovyClassLoader
.
getURLs
();
assert
Equals
(
1
,
urls
.
length
);
assertT
rue
(
urls
[
0
].
toExternalForm
().
endsWith
(
".pom"
)
);
assert
That
(
urls
.
length
).
isEqualTo
(
1
);
assertT
hat
(
urls
[
0
].
toExternalForm
().
endsWith
(
".pom"
)).
isTrue
(
);
}
@Test
...
...
@@ -210,8 +208,8 @@ public class AetherGrapeEngineTests {
createGrapeEngine
().
grab
(
args
,
dependency
);
URL
[]
urls
=
this
.
groovyClassLoader
.
getURLs
();
assert
Equals
(
1
,
urls
.
length
);
assertT
rue
(
urls
[
0
].
toExternalForm
().
endsWith
(
"-sources.jar"
)
);
assert
That
(
urls
.
length
).
isEqualTo
(
1
);
assertT
hat
(
urls
[
0
].
toExternalForm
().
endsWith
(
"-sources.jar"
)).
isTrue
(
);
}
private
Map
<
String
,
Object
>
createDependency
(
String
group
,
String
module
,
...
...
spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/DetailedProgressReporterTests.java
View file @
962a5985
...
...
@@ -26,11 +26,7 @@ import org.eclipse.aether.transfer.TransferResource;
import
org.junit.Before
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
hamcrest
.
Matchers
.
endsWith
;
import
static
org
.
hamcrest
.
Matchers
.
startsWith
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link DetailedProgressReporter}.
...
...
@@ -62,9 +58,8 @@ public final class DetailedProgressReporterTests {
TransferEvent
startedEvent
=
new
TransferEvent
.
Builder
(
this
.
session
,
this
.
resource
).
build
();
this
.
session
.
getTransferListener
().
transferStarted
(
startedEvent
);
assertEquals
(
String
.
format
(
"Downloading: %s%s%n"
,
REPOSITORY
,
ARTIFACT
),
new
String
(
this
.
baos
.
toByteArray
()));
assertThat
(
new
String
(
this
.
baos
.
toByteArray
()))
.
isEqualTo
(
String
.
format
(
"Downloading: %s%s%n"
,
REPOSITORY
,
ARTIFACT
));
}
@Test
...
...
@@ -75,9 +70,10 @@ public final class DetailedProgressReporterTests {
this
.
resource
).
addTransferredBytes
(
4096
).
build
();
this
.
session
.
getTransferListener
().
transferSucceeded
(
completedEvent
);
String
message
=
new
String
(
this
.
baos
.
toByteArray
()).
replace
(
"\\"
,
"/"
);
assertThat
(
message
,
startsWith
(
"Downloaded: "
+
REPOSITORY
+
ARTIFACT
)
);
assertThat
(
message
,
containsString
(
"4KB at"
)
);
assertThat
(
message
,
containsString
(
"KB/sec"
)
);
assertThat
(
message
,
endsWith
(
"\n"
)
);
assertThat
(
message
).
startsWith
(
"Downloaded: "
+
REPOSITORY
+
ARTIFACT
);
assertThat
(
message
).
contains
(
"4KB at"
);
assertThat
(
message
).
contains
(
"KB/sec"
);
assertThat
(
message
).
endsWith
(
"\n"
);
}
}
spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/GrapeRootRepositorySystemSessionAutoConfigurationTests.java
View file @
962a5985
...
...
@@ -31,11 +31,7 @@ import org.mockito.invocation.InvocationOnMock;
import
org.mockito.runners.MockitoJUnitRunner
;
import
org.mockito.stubbing.Answer
;
import
static
org
.
hamcrest
.
Matchers
.
endsWith
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
notNullValue
;
import
static
org
.
hamcrest
.
Matchers
.
nullValue
;
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
.
any
;
import
static
org
.
mockito
.
Matchers
.
eq
;
...
...
@@ -72,15 +68,13 @@ public class GrapeRootRepositorySystemSessionAutoConfigurationTests {
GrapeRootRepositorySystemSessionAutoConfigurationTests
.
this
.
session
,
localRepository
);
}
});
});
new
GrapeRootRepositorySystemSessionAutoConfiguration
().
apply
(
this
.
session
,
this
.
repositorySystem
);
verify
(
this
.
repositorySystem
,
times
(
0
))
.
newLocalRepositoryManager
(
eq
(
this
.
session
),
any
(
LocalRepository
.
class
));
assertThat
(
this
.
session
.
getLocalRepository
(),
is
(
nullValue
()));
assertThat
(
this
.
session
.
getLocalRepository
()).
isNull
();
}
@Test
...
...
@@ -101,9 +95,9 @@ public class GrapeRootRepositorySystemSessionAutoConfigurationTests {
verify
(
this
.
repositorySystem
,
times
(
1
))
.
newLocalRepositoryManager
(
eq
(
this
.
session
),
any
(
LocalRepository
.
class
));
assertThat
(
this
.
session
.
getLocalRepository
()
,
is
(
notNullValue
())
);
assertThat
(
this
.
session
.
getLocalRepository
().
getBasedir
().
getAbsolutePath
()
,
endsWith
(
File
.
separatorChar
+
"foo"
+
File
.
separatorChar
+
"repository"
)
);
assertThat
(
this
.
session
.
getLocalRepository
()
).
isNotNull
(
);
assertThat
(
this
.
session
.
getLocalRepository
().
getBasedir
().
getAbsolutePath
()
)
.
endsWith
(
File
.
separatorChar
+
"foo"
+
File
.
separatorChar
+
"repository"
);
}
private
class
LocalRepositoryManagerAnswer
implements
Answer
<
LocalRepositoryManager
>
{
...
...
spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/SettingsXmlRepositorySystemSessionAutoConfigurationTests.java
View file @
962a5985
...
...
@@ -40,10 +40,7 @@ import org.mockito.stubbing.Answer;
import
org.springframework.boot.cli.util.SystemProperties
;
import
static
org
.
hamcrest
.
Matchers
.
endsWith
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
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
.
any
;
import
static
org
.
mockito
.
Matchers
.
eq
;
...
...
@@ -99,14 +96,13 @@ public class SettingsXmlRepositorySystemSessionAutoConfigurationTests {
},
"user.home:src/test/resources/maven-settings/property-interpolation"
,
"foo:bar"
);
assertThat
(
session
.
getLocalRepository
().
getBasedir
().
getAbsolutePath
()
,
endsWith
(
File
.
separatorChar
+
"bar"
+
File
.
separatorChar
+
"repository"
)
);
assertThat
(
session
.
getLocalRepository
().
getBasedir
().
getAbsolutePath
()
)
.
endsWith
(
File
.
separatorChar
+
"bar"
+
File
.
separatorChar
+
"repository"
);
}
private
void
assertSessionCustomization
(
String
userHome
)
{
final
DefaultRepositorySystemSession
session
=
MavenRepositorySystemUtils
.
newSession
();
SystemProperties
.
doWithSystemProperties
(
new
Runnable
()
{
@Override
public
void
run
()
{
...
...
@@ -117,7 +113,6 @@ public class SettingsXmlRepositorySystemSessionAutoConfigurationTests {
RemoteRepository
repository
=
new
RemoteRepository
.
Builder
(
"my-server"
,
"default"
,
"http://maven.example.com"
).
build
();
assertMirrorSelectorConfiguration
(
session
,
repository
);
assertProxySelectorConfiguration
(
session
,
repository
);
assertAuthenticationSelectorConfiguration
(
session
,
repository
);
...
...
@@ -129,34 +124,33 @@ public class SettingsXmlRepositorySystemSessionAutoConfigurationTests {
repository
=
new
RemoteRepository
.
Builder
(
repository
).
setProxy
(
proxy
).
build
();
AuthenticationContext
authenticationContext
=
AuthenticationContext
.
forProxy
(
session
,
repository
);
assert
Equals
(
"proxy.example.com"
,
proxy
.
getHost
()
);
assert
Equals
(
"proxyuser"
,
authenticationContext
.
get
(
AuthenticationContext
.
USERNAME
)
);
assert
Equals
(
"somepassword"
,
authenticationContext
.
get
(
AuthenticationContext
.
PASSWORD
)
);
assert
That
(
proxy
.
getHost
()).
isEqualTo
(
"proxy.example.com"
);
assert
That
(
authenticationContext
.
get
(
AuthenticationContext
.
USERNAME
))
.
isEqualTo
(
"proxyuser"
);
assert
That
(
authenticationContext
.
get
(
AuthenticationContext
.
PASSWORD
))
.
isEqualTo
(
"somepassword"
);
}
private
void
assertMirrorSelectorConfiguration
(
DefaultRepositorySystemSession
session
,
RemoteRepository
repository
)
{
RemoteRepository
mirror
=
session
.
getMirrorSelector
().
getMirror
(
repository
);
assert
NotNull
(
"No mirror configured for repository "
+
repository
.
getId
(),
mirror
);
assert
Equals
(
"maven.example.com"
,
mirror
.
getHost
()
);
assert
That
(
mirror
).
as
(
"Mirror configured for repository "
+
repository
.
getId
())
.
isNotNull
(
);
assert
That
(
mirror
.
getHost
()).
isEqualTo
(
"maven.example.com"
);
}
private
void
assertAuthenticationSelectorConfiguration
(
DefaultRepositorySystemSession
session
,
RemoteRepository
repository
)
{
Authentication
authentication
=
session
.
getAuthenticationSelector
()
.
getAuthentication
(
repository
);
repository
=
new
RemoteRepository
.
Builder
(
repository
)
.
setAuthentication
(
authentication
).
build
();
AuthenticationContext
authenticationContext
=
AuthenticationContext
.
forRepository
(
session
,
repository
);
assertEquals
(
"tester"
,
authenticationContext
.
get
(
AuthenticationContext
.
USERNAME
));
assertEquals
(
"secret"
,
authenticationContext
.
get
(
AuthenticationContext
.
PASSWORD
));
assertThat
(
authenticationContext
.
get
(
AuthenticationContext
.
USERNAME
))
.
isEqualTo
(
"tester"
);
assertThat
(
authenticationContext
.
get
(
AuthenticationContext
.
PASSWORD
))
.
isEqualTo
(
"secret"
);
}
}
spring-boot-cli/src/test/java/org/springframework/boot/cli/util/ResourceUtilsTests.java
View file @
962a5985
...
...
@@ -25,8 +25,7 @@ import org.junit.Test;
import
org.springframework.util.ClassUtils
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link ResourceUtils}.
...
...
@@ -39,8 +38,8 @@ public class ResourceUtilsTests {
public
void
explicitClasspathResource
()
{
List
<
String
>
urls
=
ResourceUtils
.
getUrls
(
"classpath:init.groovy"
,
ClassUtils
.
getDefaultClassLoader
());
assert
Equals
(
1
,
urls
.
size
()
);
assertT
rue
(
urls
.
get
(
0
).
startsWith
(
"file:"
)
);
assert
That
(
urls
).
hasSize
(
1
);
assertT
hat
(
urls
.
get
(
0
).
startsWith
(
"file:"
)).
isTrue
(
);
}
@Test
...
...
@@ -49,68 +48,68 @@ public class ResourceUtilsTests {
new
URL
(
"file:./src/test/resources/"
),
new
File
(
"src/test/resources/"
).
getAbsoluteFile
().
toURI
().
toURL
()
});
List
<
String
>
urls
=
ResourceUtils
.
getUrls
(
"classpath:init.groovy"
,
loader
);
assert
Equals
(
1
,
urls
.
size
()
);
assertT
rue
(
urls
.
get
(
0
).
startsWith
(
"file:"
)
);
assert
That
(
urls
).
hasSize
(
1
);
assertT
hat
(
urls
.
get
(
0
).
startsWith
(
"file:"
)).
isTrue
(
);
}
@Test
public
void
explicitClasspathResourceWithSlash
()
{
List
<
String
>
urls
=
ResourceUtils
.
getUrls
(
"classpath:/init.groovy"
,
ClassUtils
.
getDefaultClassLoader
());
assert
Equals
(
1
,
urls
.
size
()
);
assertT
rue
(
urls
.
get
(
0
).
startsWith
(
"file:"
)
);
assert
That
(
urls
).
hasSize
(
1
);
assertT
hat
(
urls
.
get
(
0
).
startsWith
(
"file:"
)).
isTrue
(
);
}
@Test
public
void
implicitClasspathResource
()
{
List
<
String
>
urls
=
ResourceUtils
.
getUrls
(
"init.groovy"
,
ClassUtils
.
getDefaultClassLoader
());
assert
Equals
(
1
,
urls
.
size
()
);
assertT
rue
(
urls
.
get
(
0
).
startsWith
(
"file:"
)
);
assert
That
(
urls
).
hasSize
(
1
);
assertT
hat
(
urls
.
get
(
0
).
startsWith
(
"file:"
)).
isTrue
(
);
}
@Test
public
void
implicitClasspathResourceWithSlash
()
{
List
<
String
>
urls
=
ResourceUtils
.
getUrls
(
"/init.groovy"
,
ClassUtils
.
getDefaultClassLoader
());
assert
Equals
(
1
,
urls
.
size
()
);
assertT
rue
(
urls
.
get
(
0
).
startsWith
(
"file:"
)
);
assert
That
(
urls
).
hasSize
(
1
);
assertT
hat
(
urls
.
get
(
0
).
startsWith
(
"file:"
)).
isTrue
(
);
}
@Test
public
void
nonexistentClasspathResource
()
{
List
<
String
>
urls
=
ResourceUtils
.
getUrls
(
"classpath:nonexistent.groovy"
,
null
);
assert
Equals
(
0
,
urls
.
size
()
);
assert
That
(
urls
).
isEmpty
(
);
}
@Test
public
void
explicitFile
()
{
List
<
String
>
urls
=
ResourceUtils
.
getUrls
(
"file:src/test/resources/init.groovy"
,
ClassUtils
.
getDefaultClassLoader
());
assert
Equals
(
1
,
urls
.
size
()
);
assertT
rue
(
urls
.
get
(
0
).
startsWith
(
"file:"
)
);
assert
That
(
urls
).
hasSize
(
1
);
assertT
hat
(
urls
.
get
(
0
).
startsWith
(
"file:"
)).
isTrue
(
);
}
@Test
public
void
implicitFile
()
{
List
<
String
>
urls
=
ResourceUtils
.
getUrls
(
"src/test/resources/init.groovy"
,
ClassUtils
.
getDefaultClassLoader
());
assert
Equals
(
1
,
urls
.
size
()
);
assertT
rue
(
urls
.
get
(
0
).
startsWith
(
"file:"
)
);
assert
That
(
urls
).
hasSize
(
1
);
assertT
hat
(
urls
.
get
(
0
).
startsWith
(
"file:"
)).
isTrue
(
);
}
@Test
public
void
nonexistentFile
()
{
List
<
String
>
urls
=
ResourceUtils
.
getUrls
(
"file:nonexistent.groovy"
,
null
);
assert
Equals
(
0
,
urls
.
size
()
);
assert
That
(
urls
).
isEmpty
(
);
}
@Test
public
void
recursiveFiles
()
{
List
<
String
>
urls
=
ResourceUtils
.
getUrls
(
"src/test/resources/dir-sample"
,
ClassUtils
.
getDefaultClassLoader
());
assert
Equals
(
1
,
urls
.
size
()
);
assertT
rue
(
urls
.
get
(
0
).
startsWith
(
"file:"
)
);
assert
That
(
urls
).
hasSize
(
1
);
assertT
hat
(
urls
.
get
(
0
).
startsWith
(
"file:"
)).
isTrue
(
);
}
@Test
...
...
@@ -118,8 +117,8 @@ public class ResourceUtilsTests {
List
<
String
>
urls
=
ResourceUtils
.
getUrls
(
"file:src/test/resources/dir-sample/**/*.groovy"
,
ClassUtils
.
getDefaultClassLoader
());
assert
Equals
(
1
,
urls
.
size
()
);
assertT
rue
(
urls
.
get
(
0
).
startsWith
(
"file:"
)
);
assert
That
(
urls
).
hasSize
(
1
);
assertT
hat
(
urls
.
get
(
0
).
startsWith
(
"file:"
)).
isTrue
(
);
}
@Test
...
...
@@ -127,8 +126,8 @@ public class ResourceUtilsTests {
List
<
String
>
urls
=
ResourceUtils
.
getUrls
(
"src/test/resources/dir-sample/**/*.groovy"
,
ClassUtils
.
getDefaultClassLoader
());
assert
Equals
(
1
,
urls
.
size
()
);
assertT
rue
(
urls
.
get
(
0
).
startsWith
(
"file:"
)
);
assert
That
(
urls
).
hasSize
(
1
);
assertT
hat
(
urls
.
get
(
0
).
startsWith
(
"file:"
)).
isTrue
(
);
}
@Test
...
...
@@ -136,16 +135,16 @@ public class ResourceUtilsTests {
List
<
String
>
urls
=
ResourceUtils
.
getUrls
(
"file:src/test/resources/dir-sample/code/*"
,
ClassUtils
.
getDefaultClassLoader
());
assert
Equals
(
1
,
urls
.
size
()
);
assertT
rue
(
urls
.
get
(
0
).
startsWith
(
"file:"
)
);
assert
That
(
urls
).
hasSize
(
1
);
assertT
hat
(
urls
.
get
(
0
).
startsWith
(
"file:"
)).
isTrue
(
);
}
@Test
public
void
directoryOfFiles
()
{
List
<
String
>
urls
=
ResourceUtils
.
getUrls
(
"src/test/resources/dir-sample/code/*"
,
ClassUtils
.
getDefaultClassLoader
());
assert
Equals
(
1
,
urls
.
size
()
);
assertT
rue
(
urls
.
get
(
0
).
startsWith
(
"file:"
)
);
assert
That
(
urls
).
hasSize
(
1
);
assertT
hat
(
urls
.
get
(
0
).
startsWith
(
"file:"
)).
isTrue
(
);
}
}
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