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
1aa7010c
Commit
1aa7010c
authored
Aug 24, 2020
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #23052 from dreis2211
* pr/23052: Simplify InputStream assertions Closes gh-23052
parents
5b1c484e
33cd875c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
24 deletions
+15
-24
ZipFileTarArchiveTests.java
...rk/boot/buildpack/platform/io/ZipFileTarArchiveTests.java
+1
-4
JarFileTests.java
...ava/org/springframework/boot/loader/jar/JarFileTests.java
+2
-4
JarURLConnectionTests.java
...pringframework/boot/loader/jar/JarURLConnectionTests.java
+10
-11
ServletWebServerMvcIntegrationTests.java
.../servlet/context/ServletWebServerMvcIntegrationTests.java
+2
-5
No files found.
spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/io/ZipFileTarArchiveTests.java
View file @
1aa7010c
...
@@ -29,8 +29,6 @@ import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
...
@@ -29,8 +29,6 @@ import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.io.TempDir
;
import
org.junit.jupiter.api.io.TempDir
;
import
org.springframework.util.StreamUtils
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatIllegalArgumentException
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatIllegalArgumentException
;
...
@@ -77,8 +75,7 @@ class ZipFileTarArchiveTests {
...
@@ -77,8 +75,7 @@ class ZipFileTarArchiveTests {
assertThat
(
fileEntry
.
getLongUserId
()).
isEqualTo
(
123
);
assertThat
(
fileEntry
.
getLongUserId
()).
isEqualTo
(
123
);
assertThat
(
fileEntry
.
getLongGroupId
()).
isEqualTo
(
456
);
assertThat
(
fileEntry
.
getLongGroupId
()).
isEqualTo
(
456
);
assertThat
(
fileEntry
.
getSize
()).
isEqualTo
(
4
);
assertThat
(
fileEntry
.
getSize
()).
isEqualTo
(
4
);
String
fileContent
=
StreamUtils
.
copyToString
(
tarStream
,
StandardCharsets
.
UTF_8
);
assertThat
(
tarStream
).
hasContent
(
"test"
);
assertThat
(
fileContent
).
isEqualTo
(
"test"
);
}
}
}
}
...
...
spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/JarFileTests.java
View file @
1aa7010c
...
@@ -564,8 +564,7 @@ class JarFileTests {
...
@@ -564,8 +564,7 @@ class JarFileTests {
for
(
int
i
=
0
;
i
<
entries
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
entries
.
size
();
i
++)
{
JarEntry
entry
=
entries
.
get
(
i
);
JarEntry
entry
=
entries
.
get
(
i
);
InputStream
entryInput
=
zip64JarFile
.
getInputStream
(
entry
);
InputStream
entryInput
=
zip64JarFile
.
getInputStream
(
entry
);
String
contents
=
StreamUtils
.
copyToString
(
entryInput
,
StandardCharsets
.
UTF_8
);
assertThat
(
entryInput
).
hasContent
(
"Entry "
+
(
i
+
1
));
assertThat
(
contents
).
isEqualTo
(
"Entry "
+
(
i
+
1
));
}
}
}
}
}
}
...
@@ -594,8 +593,7 @@ class JarFileTests {
...
@@ -594,8 +593,7 @@ class JarFileTests {
for
(
int
i
=
0
;
i
<
entries
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
entries
.
size
();
i
++)
{
JarEntry
entry
=
entries
.
get
(
i
);
JarEntry
entry
=
entries
.
get
(
i
);
InputStream
entryInput
=
nestedZip64JarFile
.
getInputStream
(
entry
);
InputStream
entryInput
=
nestedZip64JarFile
.
getInputStream
(
entry
);
String
contents
=
StreamUtils
.
copyToString
(
entryInput
,
StandardCharsets
.
UTF_8
);
assertThat
(
entryInput
).
hasContent
(
"Entry "
+
(
i
+
1
));
assertThat
(
contents
).
isEqualTo
(
"Entry "
+
(
i
+
1
));
}
}
}
}
}
}
...
...
spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/JarURLConnectionTests.java
View file @
1aa7010c
...
@@ -16,7 +16,6 @@
...
@@ -16,7 +16,6 @@
package
org
.
springframework
.
boot
.
loader
.
jar
;
package
org
.
springframework
.
boot
.
loader
.
jar
;
import
java.io.ByteArrayInputStream
;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.FileNotFoundException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
...
@@ -76,7 +75,7 @@ class JarURLConnectionTests {
...
@@ -76,7 +75,7 @@ class JarURLConnectionTests {
void
connectionToEntryUsingAbsoluteUrl
()
throws
Exception
{
void
connectionToEntryUsingAbsoluteUrl
()
throws
Exception
{
URL
url
=
new
URL
(
"jar:"
+
this
.
rootJarFile
.
toURI
().
toURL
()
+
"!/1.dat"
);
URL
url
=
new
URL
(
"jar:"
+
this
.
rootJarFile
.
toURI
().
toURL
()
+
"!/1.dat"
);
try
(
InputStream
input
=
JarURLConnection
.
get
(
url
,
this
.
jarFile
).
getInputStream
())
{
try
(
InputStream
input
=
JarURLConnection
.
get
(
url
,
this
.
jarFile
).
getInputStream
())
{
assertThat
(
input
).
has
SameContentAs
(
new
ByteArrayInputStream
(
new
byte
[]
{
1
})
);
assertThat
(
input
).
has
BinaryContent
(
new
byte
[]
{
1
}
);
}
}
}
}
...
@@ -84,7 +83,7 @@ class JarURLConnectionTests {
...
@@ -84,7 +83,7 @@ class JarURLConnectionTests {
void
connectionToEntryUsingRelativeUrl
()
throws
Exception
{
void
connectionToEntryUsingRelativeUrl
()
throws
Exception
{
URL
url
=
new
URL
(
"jar:file:"
+
getRelativePath
()
+
"!/1.dat"
);
URL
url
=
new
URL
(
"jar:file:"
+
getRelativePath
()
+
"!/1.dat"
);
try
(
InputStream
input
=
JarURLConnection
.
get
(
url
,
this
.
jarFile
).
getInputStream
())
{
try
(
InputStream
input
=
JarURLConnection
.
get
(
url
,
this
.
jarFile
).
getInputStream
())
{
assertThat
(
input
).
has
SameContentAs
(
new
ByteArrayInputStream
(
new
byte
[]
{
1
})
);
assertThat
(
input
).
has
BinaryContent
(
new
byte
[]
{
1
}
);
}
}
}
}
...
@@ -92,7 +91,7 @@ class JarURLConnectionTests {
...
@@ -92,7 +91,7 @@ class JarURLConnectionTests {
void
connectionToEntryUsingAbsoluteUrlWithFileColonSlashSlashPrefix
()
throws
Exception
{
void
connectionToEntryUsingAbsoluteUrlWithFileColonSlashSlashPrefix
()
throws
Exception
{
URL
url
=
new
URL
(
"jar:"
+
this
.
rootJarFile
.
toURI
().
toURL
()
+
"!/1.dat"
);
URL
url
=
new
URL
(
"jar:"
+
this
.
rootJarFile
.
toURI
().
toURL
()
+
"!/1.dat"
);
try
(
InputStream
input
=
JarURLConnection
.
get
(
url
,
this
.
jarFile
).
getInputStream
())
{
try
(
InputStream
input
=
JarURLConnection
.
get
(
url
,
this
.
jarFile
).
getInputStream
())
{
assertThat
(
input
).
has
SameContentAs
(
new
ByteArrayInputStream
(
new
byte
[]
{
1
})
);
assertThat
(
input
).
has
BinaryContent
(
new
byte
[]
{
1
}
);
}
}
}
}
...
@@ -101,7 +100,7 @@ class JarURLConnectionTests {
...
@@ -101,7 +100,7 @@ class JarURLConnectionTests {
URL
url
=
new
URL
(
"jar:"
+
this
.
rootJarFile
.
toURI
().
toURL
()
+
"!/nested.jar!/3.dat"
);
URL
url
=
new
URL
(
"jar:"
+
this
.
rootJarFile
.
toURI
().
toURL
()
+
"!/nested.jar!/3.dat"
);
JarURLConnection
connection
=
JarURLConnection
.
get
(
url
,
this
.
jarFile
);
JarURLConnection
connection
=
JarURLConnection
.
get
(
url
,
this
.
jarFile
);
try
(
InputStream
input
=
connection
.
getInputStream
())
{
try
(
InputStream
input
=
connection
.
getInputStream
())
{
assertThat
(
input
).
has
SameContentAs
(
new
ByteArrayInputStream
(
new
byte
[]
{
3
})
);
assertThat
(
input
).
has
BinaryContent
(
new
byte
[]
{
3
}
);
}
}
connection
.
getJarFile
().
close
();
connection
.
getJarFile
().
close
();
}
}
...
@@ -111,7 +110,7 @@ class JarURLConnectionTests {
...
@@ -111,7 +110,7 @@ class JarURLConnectionTests {
URL
url
=
new
URL
(
"jar:file:"
+
getRelativePath
()
+
"!/nested.jar!/3.dat"
);
URL
url
=
new
URL
(
"jar:file:"
+
getRelativePath
()
+
"!/nested.jar!/3.dat"
);
JarURLConnection
connection
=
JarURLConnection
.
get
(
url
,
this
.
jarFile
);
JarURLConnection
connection
=
JarURLConnection
.
get
(
url
,
this
.
jarFile
);
try
(
InputStream
input
=
connection
.
getInputStream
())
{
try
(
InputStream
input
=
connection
.
getInputStream
())
{
assertThat
(
input
).
has
SameContentAs
(
new
ByteArrayInputStream
(
new
byte
[]
{
3
})
);
assertThat
(
input
).
has
BinaryContent
(
new
byte
[]
{
3
}
);
}
}
connection
.
getJarFile
().
close
();
connection
.
getJarFile
().
close
();
}
}
...
@@ -121,7 +120,7 @@ class JarURLConnectionTests {
...
@@ -121,7 +120,7 @@ class JarURLConnectionTests {
URL
url
=
new
URL
(
"jar:"
+
this
.
rootJarFile
.
toURI
().
toURL
()
+
"!/nested.jar!/3.dat"
);
URL
url
=
new
URL
(
"jar:"
+
this
.
rootJarFile
.
toURI
().
toURL
()
+
"!/nested.jar!/3.dat"
);
try
(
JarFile
nested
=
this
.
jarFile
.
getNestedJarFile
(
this
.
jarFile
.
getEntry
(
"nested.jar"
)))
{
try
(
JarFile
nested
=
this
.
jarFile
.
getNestedJarFile
(
this
.
jarFile
.
getEntry
(
"nested.jar"
)))
{
try
(
InputStream
input
=
JarURLConnection
.
get
(
url
,
nested
).
getInputStream
())
{
try
(
InputStream
input
=
JarURLConnection
.
get
(
url
,
nested
).
getInputStream
())
{
assertThat
(
input
).
has
SameContentAs
(
new
ByteArrayInputStream
(
new
byte
[]
{
3
})
);
assertThat
(
input
).
has
BinaryContent
(
new
byte
[]
{
3
}
);
}
}
}
}
}
}
...
@@ -131,7 +130,7 @@ class JarURLConnectionTests {
...
@@ -131,7 +130,7 @@ class JarURLConnectionTests {
URL
url
=
new
URL
(
"jar:file:"
+
getRelativePath
()
+
"!/nested.jar!/3.dat"
);
URL
url
=
new
URL
(
"jar:file:"
+
getRelativePath
()
+
"!/nested.jar!/3.dat"
);
try
(
JarFile
nested
=
this
.
jarFile
.
getNestedJarFile
(
this
.
jarFile
.
getEntry
(
"nested.jar"
)))
{
try
(
JarFile
nested
=
this
.
jarFile
.
getNestedJarFile
(
this
.
jarFile
.
getEntry
(
"nested.jar"
)))
{
try
(
InputStream
input
=
JarURLConnection
.
get
(
url
,
nested
).
getInputStream
())
{
try
(
InputStream
input
=
JarURLConnection
.
get
(
url
,
nested
).
getInputStream
())
{
assertThat
(
input
).
has
SameContentAs
(
new
ByteArrayInputStream
(
new
byte
[]
{
3
})
);
assertThat
(
input
).
has
BinaryContent
(
new
byte
[]
{
3
}
);
}
}
}
}
}
}
...
@@ -142,7 +141,7 @@ class JarURLConnectionTests {
...
@@ -142,7 +141,7 @@ class JarURLConnectionTests {
"/3.dat"
);
"/3.dat"
);
try
(
JarFile
nested
=
this
.
jarFile
.
getNestedJarFile
(
this
.
jarFile
.
getEntry
(
"nested.jar"
)))
{
try
(
JarFile
nested
=
this
.
jarFile
.
getNestedJarFile
(
this
.
jarFile
.
getEntry
(
"nested.jar"
)))
{
try
(
InputStream
input
=
JarURLConnection
.
get
(
url
,
nested
).
getInputStream
())
{
try
(
InputStream
input
=
JarURLConnection
.
get
(
url
,
nested
).
getInputStream
())
{
assertThat
(
input
).
has
SameContentAs
(
new
ByteArrayInputStream
(
new
byte
[]
{
3
})
);
assertThat
(
input
).
has
BinaryContent
(
new
byte
[]
{
3
}
);
}
}
}
}
}
}
...
@@ -152,7 +151,7 @@ class JarURLConnectionTests {
...
@@ -152,7 +151,7 @@ class JarURLConnectionTests {
URL
url
=
new
URL
(
"jar:file:"
+
getRelativePath
()
+
"!/space nested.jar!/3.dat"
);
URL
url
=
new
URL
(
"jar:file:"
+
getRelativePath
()
+
"!/space nested.jar!/3.dat"
);
JarURLConnection
connection
=
JarURLConnection
.
get
(
url
,
this
.
jarFile
);
JarURLConnection
connection
=
JarURLConnection
.
get
(
url
,
this
.
jarFile
);
try
(
InputStream
input
=
connection
.
getInputStream
())
{
try
(
InputStream
input
=
connection
.
getInputStream
())
{
assertThat
(
input
).
has
SameContentAs
(
new
ByteArrayInputStream
(
new
byte
[]
{
3
})
);
assertThat
(
input
).
has
BinaryContent
(
new
byte
[]
{
3
}
);
}
}
connection
.
getJarFile
().
close
();
connection
.
getJarFile
().
close
();
}
}
...
@@ -162,7 +161,7 @@ class JarURLConnectionTests {
...
@@ -162,7 +161,7 @@ class JarURLConnectionTests {
URL
url
=
new
URL
(
"jar:file:"
+
getRelativePath
()
+
"!/space%20nested.jar!/3.dat"
);
URL
url
=
new
URL
(
"jar:file:"
+
getRelativePath
()
+
"!/space%20nested.jar!/3.dat"
);
JarURLConnection
connection
=
JarURLConnection
.
get
(
url
,
this
.
jarFile
);
JarURLConnection
connection
=
JarURLConnection
.
get
(
url
,
this
.
jarFile
);
try
(
InputStream
input
=
connection
.
getInputStream
())
{
try
(
InputStream
input
=
connection
.
getInputStream
())
{
assertThat
(
input
).
has
SameContentAs
(
new
ByteArrayInputStream
(
new
byte
[]
{
3
})
);
assertThat
(
input
).
has
BinaryContent
(
new
byte
[]
{
3
}
);
}
}
connection
.
getJarFile
().
close
();
connection
.
getJarFile
().
close
();
}
}
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/ServletWebServerMvcIntegrationTests.java
View file @
1aa7010c
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -17,7 +17,6 @@
...
@@ -17,7 +17,6 @@
package
org
.
springframework
.
boot
.
web
.
servlet
.
context
;
package
org
.
springframework
.
boot
.
web
.
servlet
.
context
;
import
java.net.URI
;
import
java.net.URI
;
import
java.nio.charset.StandardCharsets
;
import
org.junit.jupiter.api.AfterEach
;
import
org.junit.jupiter.api.AfterEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
...
@@ -38,7 +37,6 @@ import org.springframework.http.client.ClientHttpRequest;
...
@@ -38,7 +37,6 @@ import org.springframework.http.client.ClientHttpRequest;
import
org.springframework.http.client.ClientHttpResponse
;
import
org.springframework.http.client.ClientHttpResponse
;
import
org.springframework.http.client.SimpleClientHttpRequestFactory
;
import
org.springframework.http.client.SimpleClientHttpRequestFactory
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.util.StreamUtils
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.servlet.DispatcherServlet
;
import
org.springframework.web.servlet.DispatcherServlet
;
...
@@ -97,8 +95,7 @@ class ServletWebServerMvcIntegrationTests {
...
@@ -97,8 +95,7 @@ class ServletWebServerMvcIntegrationTests {
ClientHttpRequest
request
=
clientHttpRequestFactory
.
createRequest
(
ClientHttpRequest
request
=
clientHttpRequestFactory
.
createRequest
(
new
URI
(
"http://localhost:"
+
context
.
getWebServer
().
getPort
()
+
resourcePath
),
HttpMethod
.
GET
);
new
URI
(
"http://localhost:"
+
context
.
getWebServer
().
getPort
()
+
resourcePath
),
HttpMethod
.
GET
);
try
(
ClientHttpResponse
response
=
request
.
execute
())
{
try
(
ClientHttpResponse
response
=
request
.
execute
())
{
String
actual
=
StreamUtils
.
copyToString
(
response
.
getBody
(),
StandardCharsets
.
UTF_8
);
assertThat
(
response
.
getBody
()).
hasContent
(
"Hello World"
);
assertThat
(
actual
).
isEqualTo
(
"Hello World"
);
}
}
}
}
...
...
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