> input =
ImmutableSortedMap.of(
"/var/job-result-data", ImmutableMap.of(), "/var/log/my-app-logs", ImmutableMap.of());
@@ -164,7 +164,7 @@ public void testVolumeMapToList() throws BadContainerConfigurationFormatExceptio
}
@Test
- public void testJsonToImageTranslatorRegex() {
+ void testJsonToImageTranslatorRegex() {
assertGoodEnvironmentPattern("NAME=VALUE", "NAME", "VALUE");
assertGoodEnvironmentPattern("A1203921=www=ww", "A1203921", "www=ww");
assertGoodEnvironmentPattern("&*%($(*@(%&@$*$(=", "&*%($(*@(%&@$*$(", "");
diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/ManifestListGeneratorTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/ManifestListGeneratorTest.java
index 3c7a15e2ac2..957c06a70ad 100644
--- a/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/ManifestListGeneratorTest.java
+++ b/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/ManifestListGeneratorTest.java
@@ -21,18 +21,18 @@
import java.util.Arrays;
import java.util.Collections;
import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/** Tests for {@link ManifestListGenerator}. */
-public class ManifestListGeneratorTest {
+class ManifestListGeneratorTest {
private Image image1;
private Image image2;
private ManifestListGenerator manifestListGenerator;
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
image1 =
Image.builder(V22ManifestTemplate.class).setArchitecture("amd64").setOs("linux").build();
image2 =
@@ -41,7 +41,7 @@ public void setUp() {
}
@Test
- public void testGetManifestListTemplate() throws IOException {
+ void testGetManifestListTemplate() throws IOException {
// Expected Manifest List JSON
// {
@@ -83,7 +83,7 @@ public void testGetManifestListTemplate() throws IOException {
}
@Test
- public void testGetManifestListTemplate_emptyImagesList() throws IOException {
+ void testGetManifestListTemplate_emptyImagesList() throws IOException {
try {
new ManifestListGenerator(Collections.emptyList())
.getManifestListTemplate(V22ManifestTemplate.class);
@@ -94,7 +94,7 @@ public void testGetManifestListTemplate_emptyImagesList() throws IOException {
}
@Test
- public void testGetManifestListTemplate_unsupportedImageFormat() throws IOException {
+ void testGetManifestListTemplate_unsupportedImageFormat() throws IOException {
try {
new ManifestListGenerator(Arrays.asList(image1, image2))
.getManifestListTemplate(OciManifestTemplate.class);
diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/OciIndexTemplateTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/OciIndexTemplateTest.java
index f95a0643064..1033e9d5d8d 100644
--- a/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/OciIndexTemplateTest.java
+++ b/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/OciIndexTemplateTest.java
@@ -28,13 +28,13 @@
import java.nio.file.Paths;
import java.security.DigestException;
import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/** Tests for {@link OciIndexTemplate}. */
-public class OciIndexTemplateTest {
+class OciIndexTemplateTest {
@Test
- public void testToJson() throws DigestException, IOException, URISyntaxException {
+ void testToJson() throws DigestException, IOException, URISyntaxException {
// Loads the expected JSON string.
Path jsonFile = Paths.get(Resources.getResource("core/json/ociindex.json").toURI());
String expectedJson = new String(Files.readAllBytes(jsonFile), StandardCharsets.UTF_8);
@@ -54,7 +54,7 @@ public void testToJson() throws DigestException, IOException, URISyntaxException
}
@Test
- public void testFromJson() throws IOException, URISyntaxException, DigestException {
+ void testFromJson() throws IOException, URISyntaxException, DigestException {
// Loads the JSON string.
Path jsonFile = Paths.get(Resources.getResource("core/json/ociindex.json").toURI());
@@ -76,7 +76,7 @@ public void testFromJson() throws IOException, URISyntaxException, DigestExcepti
}
@Test
- public void testToJsonWithPlatform() throws DigestException, IOException, URISyntaxException {
+ void testToJsonWithPlatform() throws DigestException, IOException, URISyntaxException {
// Loads the expected JSON string.
Path jsonFile = Paths.get(Resources.getResource("core/json/ociindex_platforms.json").toURI());
String expectedJson = new String(Files.readAllBytes(jsonFile), StandardCharsets.UTF_8);
@@ -108,7 +108,7 @@ public void testToJsonWithPlatform() throws DigestException, IOException, URISyn
}
@Test
- public void testFromJsonWithPlatform() throws IOException, URISyntaxException, DigestException {
+ void testFromJsonWithPlatform() throws IOException, URISyntaxException, DigestException {
// Loads the JSON string.
Path jsonFile = Paths.get(Resources.getResource("core/json/ociindex_platforms.json").toURI());
diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/OciManifestTemplateTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/OciManifestTemplateTest.java
index 6eaac9c4bf4..8c8712824ca 100644
--- a/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/OciManifestTemplateTest.java
+++ b/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/OciManifestTemplateTest.java
@@ -27,13 +27,13 @@
import java.nio.file.Paths;
import java.security.DigestException;
import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/** Tests for {@link OciManifestTemplate}. */
-public class OciManifestTemplateTest {
+class OciManifestTemplateTest {
@Test
- public void testToJson() throws DigestException, IOException, URISyntaxException {
+ void testToJson() throws DigestException, IOException, URISyntaxException {
// Loads the expected JSON string.
Path jsonFile = Paths.get(Resources.getResource("core/json/ocimanifest.json").toURI());
String expectedJson = new String(Files.readAllBytes(jsonFile), StandardCharsets.UTF_8);
@@ -56,7 +56,7 @@ public void testToJson() throws DigestException, IOException, URISyntaxException
}
@Test
- public void testFromJson() throws IOException, URISyntaxException, DigestException {
+ void testFromJson() throws IOException, URISyntaxException, DigestException {
// Loads the JSON string.
Path jsonFile = Paths.get(Resources.getResource("core/json/ocimanifest.json").toURI());
diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/V21ManifestTemplateTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/V21ManifestTemplateTest.java
index a2f33c1b5cd..14598cc4d52 100644
--- a/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/V21ManifestTemplateTest.java
+++ b/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/V21ManifestTemplateTest.java
@@ -26,13 +26,13 @@
import java.security.DigestException;
import java.util.Arrays;
import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/** Tests for {@link V21ManifestTemplate}. */
-public class V21ManifestTemplateTest {
+class V21ManifestTemplateTest {
@Test
- public void testFromJson() throws URISyntaxException, IOException, DigestException {
+ void testFromJson() throws URISyntaxException, IOException, DigestException {
// Loads the JSON string.
Path jsonFile = Paths.get(Resources.getResource("core/json/v21manifest.json").toURI());
diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/V22ManifestListTemplateTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/V22ManifestListTemplateTest.java
index c04ab5f2912..af2f0e69cd6 100644
--- a/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/V22ManifestListTemplateTest.java
+++ b/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/V22ManifestListTemplateTest.java
@@ -25,12 +25,12 @@
import java.nio.file.Paths;
import java.util.List;
import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class V22ManifestListTemplateTest {
+class V22ManifestListTemplateTest {
@Test
- public void testFromJson() throws IOException, URISyntaxException {
+ void testFromJson() throws IOException, URISyntaxException {
Path jsonFile = Paths.get(Resources.getResource("core/json/v22manifest_list.json").toURI());
V22ManifestListTemplate manifestListJson =
diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/V22ManifestTemplateTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/V22ManifestTemplateTest.java
index 91955bc9019..d2e9dd8a3f5 100644
--- a/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/V22ManifestTemplateTest.java
+++ b/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/V22ManifestTemplateTest.java
@@ -31,13 +31,13 @@
import java.util.Arrays;
import java.util.List;
import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/** Tests for {@link V22ManifestTemplate}. */
-public class V22ManifestTemplateTest {
+class V22ManifestTemplateTest {
@Test
- public void testToJson() throws DigestException, IOException, URISyntaxException {
+ void testToJson() throws DigestException, IOException, URISyntaxException {
// Loads the expected JSON string.
Path jsonFile = Paths.get(Resources.getResource("core/json/v22manifest.json").toURI());
String expectedJson = new String(Files.readAllBytes(jsonFile), StandardCharsets.UTF_8);
@@ -60,7 +60,7 @@ public void testToJson() throws DigestException, IOException, URISyntaxException
}
@Test
- public void testFromJson() throws IOException, URISyntaxException, DigestException {
+ void testFromJson() throws IOException, URISyntaxException, DigestException {
// Loads the JSON string.
Path jsonFile = Paths.get(Resources.getResource("core/json/v22manifest.json").toURI());
@@ -84,7 +84,7 @@ public void testFromJson() throws IOException, URISyntaxException, DigestExcepti
}
@Test
- public void testFromJson_optionalProperties() throws IOException, URISyntaxException {
+ void testFromJson_optionalProperties() throws IOException, URISyntaxException {
Path jsonFile =
Paths.get(Resources.getResource("core/json/v22manifest_optional_properties.json").toURI());
diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/json/JsonTemplateMapperTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/json/JsonTemplateMapperTest.java
index 6723a84c0b5..112ae3fccb3 100644
--- a/jib-core/src/test/java/com/google/cloud/tools/jib/json/JsonTemplateMapperTest.java
+++ b/jib-core/src/test/java/com/google/cloud/tools/jib/json/JsonTemplateMapperTest.java
@@ -32,10 +32,10 @@
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/** Tests for {@link JsonTemplateMapper}. */
-public class JsonTemplateMapperTest {
+class JsonTemplateMapperTest {
private static class TestJson implements JsonTemplate {
private int number;
@@ -54,7 +54,7 @@ private static class InnerObject implements JsonTemplate {
}
@Test
- public void testWriteJson() throws DigestException, IOException, URISyntaxException {
+ void testWriteJson() throws DigestException, IOException, URISyntaxException {
Path jsonFile = Paths.get(Resources.getResource("core/json/basic.json").toURI());
String expectedJson = new String(Files.readAllBytes(jsonFile), StandardCharsets.UTF_8);
@@ -90,7 +90,7 @@ public void testWriteJson() throws DigestException, IOException, URISyntaxExcept
}
@Test
- public void testReadJsonWithLock() throws IOException, URISyntaxException, DigestException {
+ void testReadJsonWithLock() throws IOException, URISyntaxException, DigestException {
Path jsonFile = Paths.get(Resources.getResource("core/json/basic.json").toURI());
// Deserializes into a metadata JSON object.
@@ -120,7 +120,7 @@ public void testReadJsonWithLock() throws IOException, URISyntaxException, Diges
}
@Test
- public void testReadListOfJson() throws IOException, URISyntaxException, DigestException {
+ void testReadListOfJson() throws IOException, URISyntaxException, DigestException {
Path jsonFile = Paths.get(Resources.getResource("core/json/basic_list.json").toURI());
String jsonString = new String(Files.readAllBytes(jsonFile), StandardCharsets.UTF_8);
@@ -148,7 +148,7 @@ public void testReadListOfJson() throws IOException, URISyntaxException, DigestE
}
@Test
- public void testToBlob_listOfJson() throws IOException, URISyntaxException {
+ void testToBlob_listOfJson() throws IOException, URISyntaxException {
Path jsonFile = Paths.get(Resources.getResource("core/json/basic_list.json").toURI());
String jsonString = new String(Files.readAllBytes(jsonFile), StandardCharsets.UTF_8);
@@ -158,7 +158,7 @@ public void testToBlob_listOfJson() throws IOException, URISyntaxException {
}
@Test
- public void testReadJson_inputStream() throws IOException {
+ void testReadJson_inputStream() throws IOException {
String testJson = "{\"number\":3, \"text\":\"cool\"}";
ByteArrayInputStream in = new ByteArrayInputStream(testJson.getBytes(StandardCharsets.UTF_8));
TestJson json = JsonTemplateMapper.readJson(in, TestJson.class);
diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/AuthenticationMethodRetrieverTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/AuthenticationMethodRetrieverTest.java
index 44d3fd7c9f6..363b8a206c8 100644
--- a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/AuthenticationMethodRetrieverTest.java
+++ b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/AuthenticationMethodRetrieverTest.java
@@ -28,15 +28,18 @@
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.Assert;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
/** Tests for {@link AuthenticationMethodRetriever}. */
-@RunWith(MockitoJUnitRunner.class)
-public class AuthenticationMethodRetrieverTest {
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class AuthenticationMethodRetrieverTest {
@Mock private ResponseException mockResponseException;
@Mock private HttpHeaders mockHeaders;
@@ -49,42 +52,42 @@ public class AuthenticationMethodRetrieverTest {
fakeRegistryEndpointRequestProperties, "user-agent", httpClient);
@Test
- public void testGetContent() {
+ void testGetContent() {
Assert.assertNull(testAuthenticationMethodRetriever.getContent());
}
@Test
- public void testGetAccept() {
+ void testGetAccept() {
Assert.assertEquals(0, testAuthenticationMethodRetriever.getAccept().size());
}
@Test
- public void testHandleResponse() {
+ void testHandleResponse() {
Assert.assertFalse(
testAuthenticationMethodRetriever.handleResponse(Mockito.mock(Response.class)).isPresent());
}
@Test
- public void testGetApiRoute() throws MalformedURLException {
+ void testGetApiRoute() throws MalformedURLException {
Assert.assertEquals(
new URL("http://someApiBase/"),
testAuthenticationMethodRetriever.getApiRoute("http://someApiBase/"));
}
@Test
- public void testGetHttpMethod() {
+ void testGetHttpMethod() {
Assert.assertEquals(HttpMethods.GET, testAuthenticationMethodRetriever.getHttpMethod());
}
@Test
- public void testGetActionDescription() {
+ void testGetActionDescription() {
Assert.assertEquals(
"retrieve authentication method for someServerUrl",
testAuthenticationMethodRetriever.getActionDescription());
}
@Test
- public void testHandleHttpResponseException_invalidStatusCode() throws RegistryErrorException {
+ void testHandleHttpResponseException_invalidStatusCode() throws RegistryErrorException {
Mockito.when(mockResponseException.getStatusCode()).thenReturn(-1);
try {
@@ -98,7 +101,7 @@ public void testHandleHttpResponseException_invalidStatusCode() throws RegistryE
}
@Test
- public void testHandleHttpResponseException_noHeader() throws ResponseException {
+ void testHandleHttpResponseException_noHeader() throws ResponseException {
Mockito.when(mockResponseException.getStatusCode())
.thenReturn(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
Mockito.when(mockResponseException.getHeaders()).thenReturn(mockHeaders);
@@ -116,7 +119,7 @@ public void testHandleHttpResponseException_noHeader() throws ResponseException
}
@Test
- public void testHandleHttpResponseException_badAuthenticationMethod() throws ResponseException {
+ void testHandleHttpResponseException_badAuthenticationMethod() throws ResponseException {
String authenticationMethod = "bad authentication method";
Mockito.when(mockResponseException.getStatusCode())
@@ -138,7 +141,7 @@ public void testHandleHttpResponseException_badAuthenticationMethod() throws Res
}
@Test
- public void testHandleHttpResponseException_pass()
+ void testHandleHttpResponseException_pass()
throws RegistryErrorException, ResponseException, MalformedURLException {
String authenticationMethod =
"Bearer realm=\"https://somerealm\",service=\"someservice\",scope=\"somescope\"";
diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/BlobCheckerTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/BlobCheckerTest.java
index 49cb7fa31db..99bee373f54 100644
--- a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/BlobCheckerTest.java
+++ b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/BlobCheckerTest.java
@@ -31,16 +31,19 @@
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
/** Tests for {@link BlobChecker}. */
-@RunWith(MockitoJUnitRunner.class)
-public class BlobCheckerTest {
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class BlobCheckerTest {
@Mock private Response mockResponse;
@@ -50,8 +53,8 @@ public class BlobCheckerTest {
private BlobChecker testBlobChecker;
private DescriptorDigest fakeDigest;
- @Before
- public void setUpFakes() throws DigestException {
+ @BeforeEach
+ void setUpFakes() throws DigestException {
fakeDigest =
DescriptorDigest.fromHash(
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
@@ -59,7 +62,7 @@ public void setUpFakes() throws DigestException {
}
@Test
- public void testHandleResponse() throws RegistryErrorException {
+ void testHandleResponse() throws RegistryErrorException {
Mockito.when(mockResponse.getContentLength()).thenReturn(0L);
BlobDescriptor expectedBlobDescriptor = new BlobDescriptor(0, fakeDigest);
@@ -69,7 +72,7 @@ public void testHandleResponse() throws RegistryErrorException {
}
@Test
- public void testHandleResponse_noContentLength() {
+ void testHandleResponse_noContentLength() {
Mockito.when(mockResponse.getContentLength()).thenReturn(-1L);
try {
@@ -83,7 +86,7 @@ public void testHandleResponse_noContentLength() {
}
@Test
- public void testHandleHttpResponseException() throws IOException {
+ void testHandleHttpResponseException() throws IOException {
ResponseException mockResponseException = Mockito.mock(ResponseException.class);
Mockito.when(mockResponseException.getStatusCode())
.thenReturn(HttpStatusCodes.STATUS_CODE_NOT_FOUND);
@@ -99,7 +102,7 @@ public void testHandleHttpResponseException() throws IOException {
}
@Test
- public void testHandleHttpResponseException_hasOtherErrors() throws IOException {
+ void testHandleHttpResponseException_hasOtherErrors() throws IOException {
ResponseException mockResponseException = Mockito.mock(ResponseException.class);
Mockito.when(mockResponseException.getStatusCode())
.thenReturn(HttpStatusCodes.STATUS_CODE_NOT_FOUND);
@@ -121,7 +124,7 @@ public void testHandleHttpResponseException_hasOtherErrors() throws IOException
}
@Test
- public void testHandleHttpResponseException_notBlobUnknown() throws IOException {
+ void testHandleHttpResponseException_notBlobUnknown() throws IOException {
ResponseException mockResponseException = Mockito.mock(ResponseException.class);
Mockito.when(mockResponseException.getStatusCode())
.thenReturn(HttpStatusCodes.STATUS_CODE_NOT_FOUND);
@@ -140,7 +143,7 @@ public void testHandleHttpResponseException_notBlobUnknown() throws IOException
}
@Test
- public void testHandleHttpResponseException_invalidStatusCode() {
+ void testHandleHttpResponseException_invalidStatusCode() {
ResponseException mockResponseException = Mockito.mock(ResponseException.class);
Mockito.when(mockResponseException.getStatusCode()).thenReturn(-1);
@@ -154,31 +157,31 @@ public void testHandleHttpResponseException_invalidStatusCode() {
}
@Test
- public void testGetApiRoute() throws MalformedURLException {
+ void testGetApiRoute() throws MalformedURLException {
Assert.assertEquals(
new URL("http://someApiBase/someImageName/blobs/" + fakeDigest),
testBlobChecker.getApiRoute("http://someApiBase/"));
}
@Test
- public void testGetContent() {
+ void testGetContent() {
Assert.assertNull(testBlobChecker.getContent());
}
@Test
- public void testGetAccept() {
+ void testGetAccept() {
Assert.assertEquals(0, testBlobChecker.getAccept().size());
}
@Test
- public void testGetActionDescription() {
+ void testGetActionDescription() {
Assert.assertEquals(
"check BLOB exists for someServerUrl/someImageName with digest " + fakeDigest,
testBlobChecker.getActionDescription());
}
@Test
- public void testGetHttpMethod() {
+ void testGetHttpMethod() {
Assert.assertEquals("HEAD", testBlobChecker.getHttpMethod());
}
}
diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/BlobPullerTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/BlobPullerTest.java
index 09d9f09e39a..4b2e980b68f 100644
--- a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/BlobPullerTest.java
+++ b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/BlobPullerTest.java
@@ -30,15 +30,18 @@
import java.security.DigestException;
import java.util.concurrent.atomic.LongAdder;
import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
/** Tests for {@link BlobPuller}. */
-@RunWith(MockitoJUnitRunner.class)
-public class BlobPullerTest {
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class BlobPullerTest {
private final RegistryEndpointRequestProperties fakeRegistryEndpointRequestProperties =
new RegistryEndpointRequestProperties("someServerUrl", "someImageName");
@@ -50,8 +53,8 @@ public class BlobPullerTest {
private BlobPuller testBlobPuller;
- @Before
- public void setUpFakes() throws DigestException {
+ @BeforeEach
+ void setUpFakes() throws DigestException {
fakeDigest =
DescriptorDigest.fromHash(
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
@@ -66,7 +69,7 @@ public void setUpFakes() throws DigestException {
}
@Test
- public void testHandleResponse() throws IOException, UnexpectedBlobDigestException {
+ void testHandleResponse() throws IOException, UnexpectedBlobDigestException {
InputStream blobContent =
new ByteArrayInputStream("some BLOB content".getBytes(StandardCharsets.UTF_8));
DescriptorDigest testBlobDigest = Digests.computeDigest(blobContent).getDigest();
@@ -93,7 +96,7 @@ public void testHandleResponse() throws IOException, UnexpectedBlobDigestExcepti
}
@Test
- public void testHandleResponse_unexpectedDigest() throws IOException {
+ void testHandleResponse_unexpectedDigest() throws IOException {
InputStream blobContent =
new ByteArrayInputStream("some BLOB content".getBytes(StandardCharsets.UTF_8));
DescriptorDigest testBlobDigest = Digests.computeDigest(blobContent).getDigest();
@@ -118,31 +121,31 @@ public void testHandleResponse_unexpectedDigest() throws IOException {
}
@Test
- public void testGetApiRoute() throws MalformedURLException {
+ void testGetApiRoute() throws MalformedURLException {
Assert.assertEquals(
new URL("http://someApiBase/someImageName/blobs/" + fakeDigest),
testBlobPuller.getApiRoute("http://someApiBase/"));
}
@Test
- public void testGetActionDescription() {
+ void testGetActionDescription() {
Assert.assertEquals(
"pull BLOB for someServerUrl/someImageName with digest " + fakeDigest,
testBlobPuller.getActionDescription());
}
@Test
- public void testGetHttpMethod() {
+ void testGetHttpMethod() {
Assert.assertEquals("GET", testBlobPuller.getHttpMethod());
}
@Test
- public void testGetContent() {
+ void testGetContent() {
Assert.assertNull(testBlobPuller.getContent());
}
@Test
- public void testGetAccept() {
+ void testGetAccept() {
Assert.assertEquals(0, testBlobPuller.getAccept().size());
}
}
diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/BlobPusherTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/BlobPusherTest.java
index 7950a5f822b..7666667dd34 100644
--- a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/BlobPusherTest.java
+++ b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/BlobPusherTest.java
@@ -35,16 +35,19 @@
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
/** Tests for {@link BlobPusher}. */
-@RunWith(MockitoJUnitRunner.class)
-public class BlobPusherTest {
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class BlobPusherTest {
private static final String TEST_BLOB_CONTENT = "some BLOB content";
private static final Blob TEST_BLOB = Blobs.from(TEST_BLOB_CONTENT);
@@ -55,8 +58,8 @@ public class BlobPusherTest {
private DescriptorDigest fakeDescriptorDigest;
private BlobPusher testBlobPusher;
- @Before
- public void setUpFakes() throws DigestException {
+ @BeforeEach
+ void setUpFakes() throws DigestException {
fakeDescriptorDigest =
DescriptorDigest.fromHash(
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
@@ -69,23 +72,23 @@ public void setUpFakes() throws DigestException {
}
@Test
- public void testInitializer_getContent() {
+ void testInitializer_getContent() {
Assert.assertNull(testBlobPusher.initializer().getContent());
}
@Test
- public void testGetAccept() {
+ void testGetAccept() {
Assert.assertEquals(0, testBlobPusher.initializer().getAccept().size());
}
@Test
- public void testInitializer_handleResponse_created() throws IOException, RegistryException {
+ void testInitializer_handleResponse_created() throws IOException, RegistryException {
Mockito.when(mockResponse.getStatusCode()).thenReturn(201); // Created
Assert.assertFalse(testBlobPusher.initializer().handleResponse(mockResponse).isPresent());
}
@Test
- public void testInitializer_handleResponse_accepted() throws IOException, RegistryException {
+ void testInitializer_handleResponse_accepted() throws IOException, RegistryException {
Mockito.when(mockResponse.getStatusCode()).thenReturn(202); // Accepted
Mockito.when(mockResponse.getHeader("Location"))
.thenReturn(Collections.singletonList("location"));
@@ -97,7 +100,7 @@ public void testInitializer_handleResponse_accepted() throws IOException, Regist
}
@Test
- public void testInitializer_handleResponse_accepted_multipleLocations()
+ void testInitializer_handleResponse_accepted_multipleLocations()
throws IOException, RegistryException {
Mockito.when(mockResponse.getStatusCode()).thenReturn(202); // Accepted
Mockito.when(mockResponse.getHeader("Location"))
@@ -114,7 +117,7 @@ public void testInitializer_handleResponse_accepted_multipleLocations()
}
@Test
- public void testInitializer_handleResponse_unrecognized() throws IOException, RegistryException {
+ void testInitializer_handleResponse_unrecognized() throws IOException, RegistryException {
Mockito.when(mockResponse.getStatusCode()).thenReturn(-1); // Unrecognized
try {
testBlobPusher.initializer().handleResponse(mockResponse);
@@ -127,14 +130,14 @@ public void testInitializer_handleResponse_unrecognized() throws IOException, Re
}
@Test
- public void testInitializer_getApiRoute_nullSource() throws MalformedURLException {
+ void testInitializer_getApiRoute_nullSource() throws MalformedURLException {
Assert.assertEquals(
new URL("http://someApiBase/someImageName/blobs/uploads/"),
testBlobPusher.initializer().getApiRoute("http://someApiBase/"));
}
@Test
- public void testInitializer_getApiRoute_sameSource() throws MalformedURLException {
+ void testInitializer_getApiRoute_sameSource() throws MalformedURLException {
testBlobPusher =
new BlobPusher(
new RegistryEndpointRequestProperties("someServerUrl", "someImageName"),
@@ -151,19 +154,19 @@ public void testInitializer_getApiRoute_sameSource() throws MalformedURLExceptio
}
@Test
- public void testInitializer_getHttpMethod() {
+ void testInitializer_getHttpMethod() {
Assert.assertEquals("POST", testBlobPusher.initializer().getHttpMethod());
}
@Test
- public void testInitializer_getActionDescription() {
+ void testInitializer_getActionDescription() {
Assert.assertEquals(
"push BLOB for someServerUrl/someImageName with digest " + fakeDescriptorDigest,
testBlobPusher.initializer().getActionDescription());
}
@Test
- public void testWriter_getContent() throws IOException {
+ void testWriter_getContent() throws IOException {
LongAdder byteCount = new LongAdder();
BlobHttpContent body = testBlobPusher.writer(mockUrl, byteCount::add).getContent();
@@ -179,12 +182,12 @@ public void testWriter_getContent() throws IOException {
}
@Test
- public void testWriter_GetAccept() {
+ void testWriter_GetAccept() {
Assert.assertEquals(0, testBlobPusher.writer(mockUrl, ignored -> {}).getAccept().size());
}
@Test
- public void testWriter_handleResponse() throws IOException, RegistryException {
+ void testWriter_handleResponse() throws IOException, RegistryException {
Mockito.when(mockResponse.getHeader("Location"))
.thenReturn(Collections.singletonList("https://somenewurl/location"));
GenericUrl requestUrl = new GenericUrl("https://someurl");
@@ -195,53 +198,53 @@ public void testWriter_handleResponse() throws IOException, RegistryException {
}
@Test
- public void testWriter_getApiRoute() throws MalformedURLException {
+ void testWriter_getApiRoute() throws MalformedURLException {
URL fakeUrl = new URL("http://someurl");
Assert.assertEquals(fakeUrl, testBlobPusher.writer(fakeUrl, ignored -> {}).getApiRoute(""));
}
@Test
- public void testWriter_getHttpMethod() {
+ void testWriter_getHttpMethod() {
Assert.assertEquals("PATCH", testBlobPusher.writer(mockUrl, ignored -> {}).getHttpMethod());
}
@Test
- public void testWriter_getActionDescription() {
+ void testWriter_getActionDescription() {
Assert.assertEquals(
"push BLOB for someServerUrl/someImageName with digest " + fakeDescriptorDigest,
testBlobPusher.writer(mockUrl, ignored -> {}).getActionDescription());
}
@Test
- public void testCommitter_getContent() {
+ void testCommitter_getContent() {
Assert.assertNull(testBlobPusher.committer(mockUrl).getContent());
}
@Test
- public void testCommitter_GetAccept() {
+ void testCommitter_GetAccept() {
Assert.assertEquals(0, testBlobPusher.committer(mockUrl).getAccept().size());
}
@Test
- public void testCommitter_handleResponse() throws IOException, RegistryException {
+ void testCommitter_handleResponse() throws IOException, RegistryException {
Assert.assertNull(
testBlobPusher.committer(mockUrl).handleResponse(Mockito.mock(Response.class)));
}
@Test
- public void testCommitter_getApiRoute() throws MalformedURLException {
+ void testCommitter_getApiRoute() throws MalformedURLException {
Assert.assertEquals(
new URL("https://someurl?somequery=somevalue&digest=" + fakeDescriptorDigest),
testBlobPusher.committer(new URL("https://someurl?somequery=somevalue")).getApiRoute(""));
}
@Test
- public void testCommitter_getHttpMethod() {
+ void testCommitter_getHttpMethod() {
Assert.assertEquals("PUT", testBlobPusher.committer(mockUrl).getHttpMethod());
}
@Test
- public void testCommitter_getActionDescription() {
+ void testCommitter_getActionDescription() {
Assert.assertEquals(
"push BLOB for someServerUrl/someImageName with digest " + fakeDescriptorDigest,
testBlobPusher.committer(mockUrl).getActionDescription());
diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/DockerRegistryBearerTokenTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/DockerRegistryBearerTokenTest.java
index 06558ed94ed..b20551d2861 100644
--- a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/DockerRegistryBearerTokenTest.java
+++ b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/DockerRegistryBearerTokenTest.java
@@ -21,8 +21,8 @@
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import org.junit.Assert;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link RegistryClient} around handling of Docker Registry Bearer Tokens.
@@ -30,9 +30,9 @@
* JWTs were generated from jwt.io's JWT Debugger. Set the
* algorithm to HS256, and paste the JSON shown as the Payload.
*/
-public class DockerRegistryBearerTokenTest {
+class DockerRegistryBearerTokenTest {
@Test
- public void testDecode_dockerToken() {
+ void testDecode_dockerToken() {
// A genuine token from accessing docker.io's openjdk:
// {"access":[{"type":"repository","name":"library/openjdk","actions":["pull"]}]
// Generated by
@@ -51,7 +51,7 @@ public void testDecode_dockerToken() {
}
@Test
- public void testDecode_nonToken() {
+ void testDecode_nonToken() {
String base64Text =
Base64.getEncoder()
.encodeToString("something other than a JWT token".getBytes(StandardCharsets.UTF_8));
@@ -60,7 +60,7 @@ public void testDecode_nonToken() {
}
@Test
- public void testDecode_invalidToken_accessString() {
+ void testDecode_invalidToken_accessString() {
// a JWT with an "access" field that is not an array: {"access": "string"}
String jwt =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2Nlc3MiOiJzdHJpbmcifQ.12ODBkkfh6J79qEejxwlD5AfOa9mjObPCzOnUL75NSQ";
@@ -69,7 +69,7 @@ public void testDecode_invalidToken_accessString() {
}
@Test
- public void testDecode_invalidToken_accessArray() {
+ void testDecode_invalidToken_accessArray() {
// a JWT with an "access" field that is an array of non-claim objects: {"access":["string"]}
String jwt =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2Nlc3MiOlsic3RyaW5nIl19.gWZ9J4sO_w0hIVVxrfuuUC2lNhqkU3P0_z46xMCXfwU";
@@ -78,8 +78,8 @@ public void testDecode_invalidToken_accessArray() {
}
@Test
- @Ignore("Annotate AccessClaim.actions to disallow coercion of integers to strings")
- public void testDecode_invalidToken_actionsArray() {
+ @Disabled("Annotate AccessClaim.actions to disallow coercion of integers to strings")
+ void testDecode_invalidToken_actionsArray() {
// a JWT with an "access" field that is an action array of non-strings:
// {"access":[{"type": "repository","name": "library/openjdk","actions":[1]}]}
String jwt =
@@ -89,7 +89,7 @@ public void testDecode_invalidToken_actionsArray() {
}
@Test
- public void testDecode_invalidToken_randoJwt() {
+ void testDecode_invalidToken_randoJwt() {
// the JWT example token from jwt.io
String jwt =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c";
@@ -99,14 +99,14 @@ public void testDecode_invalidToken_randoJwt() {
/** Basic credential should allow access to all. */
@Test
- public void testCanAttemptBlobMount_basicCredential() {
+ void testCanAttemptBlobMount_basicCredential() {
Authorization fixture = Authorization.fromBasicCredentials("foo", "bar");
Assert.assertTrue(RegistryClient.canAttemptBlobMount(fixture, "random"));
Assert.assertTrue(RegistryClient.canAttemptBlobMount(fixture, "library/openjdk"));
}
@Test
- public void testCanAttemptBlobMount_bearer_withToken() {
+ void testCanAttemptBlobMount_bearer_withToken() {
// a synthetic token for accessing docker.io's openjdk with push and pull
// {"access":[{"type":"repository","name":"library/openjdk","actions":["pull","push"]}]}
String token =
@@ -118,7 +118,7 @@ public void testCanAttemptBlobMount_bearer_withToken() {
}
@Test
- public void testCanAttemptBlobMount_bearer_withNonToken() {
+ void testCanAttemptBlobMount_bearer_withNonToken() {
// non-Docker Registry Bearer Tokens are assumed to allow access to all
// the JWT example token from jwt.io
String jwt =
diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/ErrorResponseUtilTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/ErrorResponseUtilTest.java
index d5dd5ae0078..a2fff6f0648 100644
--- a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/ErrorResponseUtilTest.java
+++ b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/ErrorResponseUtilTest.java
@@ -18,20 +18,23 @@
import com.google.cloud.tools.jib.http.ResponseException;
import org.junit.Assert;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
/** Test for {@link ErrorReponseUtil}. */
-@RunWith(MockitoJUnitRunner.class)
-public class ErrorResponseUtilTest {
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class ErrorResponseUtilTest {
@Mock private ResponseException responseException;
@Test
- public void testGetErrorCode_knownErrorCode() throws ResponseException {
+ void testGetErrorCode_knownErrorCode() throws ResponseException {
Mockito.when(responseException.getContent())
.thenReturn(
"{\"errors\":[{\"code\":\"MANIFEST_INVALID\",\"message\":\"manifest invalid\",\"detail\":{}}]}");
@@ -42,7 +45,7 @@ public void testGetErrorCode_knownErrorCode() throws ResponseException {
/** An unknown {@link ErrorCodes} should cause original exception to be rethrown. */
@Test
- public void testGetErrorCode_unknownErrorCode() {
+ void testGetErrorCode_unknownErrorCode() {
Mockito.when(responseException.getContent())
.thenReturn(
"{\"errors\":[{\"code\":\"INVALID_ERROR_CODE\",\"message\":\"invalid code\",\"detail\":{}}]}");
@@ -56,7 +59,7 @@ public void testGetErrorCode_unknownErrorCode() {
/** Multiple error objects should cause original exception to be rethrown. */
@Test
- public void testGetErrorCode_multipleErrors() {
+ void testGetErrorCode_multipleErrors() {
Mockito.when(responseException.getContent())
.thenReturn(
"{\"errors\":["
@@ -73,7 +76,7 @@ public void testGetErrorCode_multipleErrors() {
/** An non-error object should cause original exception to be rethrown. */
@Test
- public void testGetErrorCode_invalidErrorObject() {
+ void testGetErrorCode_invalidErrorObject() {
Mockito.when(responseException.getContent())
.thenReturn("{\"type\":\"other\",\"message\":\"some other object\"}");
try {
diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/ManifestPullerTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/ManifestPullerTest.java
index e168ae0239d..526c87e80c0 100644
--- a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/ManifestPullerTest.java
+++ b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/ManifestPullerTest.java
@@ -42,15 +42,18 @@
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.Assert;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
/** Tests for {@link ManifestPuller}. */
-@RunWith(MockitoJUnitRunner.class)
-public class ManifestPullerTest {
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class ManifestPullerTest {
private static InputStream stringToInputStreamUtf8(String string) {
return new ByteArrayInputStream(string.getBytes(StandardCharsets.UTF_8));
@@ -65,7 +68,7 @@ private static InputStream stringToInputStreamUtf8(String string) {
@Mock private Response mockResponse;
@Test
- public void testHandleResponse_v21()
+ void testHandleResponse_v21()
throws URISyntaxException, IOException, UnknownManifestFormatException {
Path v21ManifestFile = Paths.get(Resources.getResource("core/json/v21manifest.json").toURI());
InputStream v21Manifest = new ByteArrayInputStream(Files.readAllBytes(v21ManifestFile));
@@ -85,7 +88,7 @@ public void testHandleResponse_v21()
}
@Test
- public void testHandleResponse_v22()
+ void testHandleResponse_v22()
throws URISyntaxException, IOException, UnknownManifestFormatException {
Path v22ManifestFile = Paths.get(Resources.getResource("core/json/v22manifest.json").toURI());
InputStream v22Manifest = new ByteArrayInputStream(Files.readAllBytes(v22ManifestFile));
@@ -105,7 +108,7 @@ public void testHandleResponse_v22()
}
@Test
- public void testHandleResponse_ociManifest()
+ void testHandleResponse_ociManifest()
throws URISyntaxException, IOException, UnknownManifestFormatException {
Path ociManifestFile = Paths.get(Resources.getResource("core/json/ocimanifest.json").toURI());
InputStream ociManifest = new ByteArrayInputStream(Files.readAllBytes(ociManifestFile));
@@ -125,7 +128,7 @@ public void testHandleResponse_ociManifest()
}
@Test
- public void testHandleResponse_v22ManifestListFailsWhenParsedAsV22Manifest()
+ void testHandleResponse_v22ManifestListFailsWhenParsedAsV22Manifest()
throws URISyntaxException, IOException, UnknownManifestFormatException {
Path v22ManifestListFile =
Paths.get(Resources.getResource("core/json/v22manifest_list.json").toURI());
@@ -143,7 +146,7 @@ public void testHandleResponse_v22ManifestListFailsWhenParsedAsV22Manifest()
}
@Test
- public void testHandleResponse_v22ManifestListFromParentType()
+ void testHandleResponse_v22ManifestListFromParentType()
throws URISyntaxException, IOException, UnknownManifestFormatException {
Path v22ManifestListFile =
Paths.get(Resources.getResource("core/json/v22manifest_list.json").toURI());
@@ -165,7 +168,7 @@ public void testHandleResponse_v22ManifestListFromParentType()
}
@Test
- public void testHandleResponse_v22ManifestList()
+ void testHandleResponse_v22ManifestList()
throws URISyntaxException, IOException, UnknownManifestFormatException {
Path v22ManifestListFile =
Paths.get(Resources.getResource("core/json/v22manifest_list.json").toURI());
@@ -190,7 +193,7 @@ public void testHandleResponse_v22ManifestList()
}
@Test
- public void testHandleResponse_OciIndex()
+ void testHandleResponse_OciIndex()
throws URISyntaxException, IOException, UnknownManifestFormatException {
Path ociIndexFile =
Paths.get(Resources.getResource("core/json/ociindex_platforms.json").toURI());
@@ -212,7 +215,7 @@ public void testHandleResponse_OciIndex()
}
@Test
- public void testHandleResponse_noSchemaVersion() throws IOException {
+ void testHandleResponse_noSchemaVersion() throws IOException {
Mockito.when(mockResponse.getBody()).thenReturn(stringToInputStreamUtf8("{}"));
try {
testManifestPuller.handleResponse(mockResponse);
@@ -224,7 +227,7 @@ public void testHandleResponse_noSchemaVersion() throws IOException {
}
@Test
- public void testHandleResponse_invalidSchemaVersion() throws IOException {
+ void testHandleResponse_invalidSchemaVersion() throws IOException {
Mockito.when(mockResponse.getBody())
.thenReturn(stringToInputStreamUtf8("{\"schemaVersion\":\"not valid\"}"));
try {
@@ -237,7 +240,7 @@ public void testHandleResponse_invalidSchemaVersion() throws IOException {
}
@Test
- public void testHandleResponse_unknownSchemaVersion() throws IOException {
+ void testHandleResponse_unknownSchemaVersion() throws IOException {
Mockito.when(mockResponse.getBody())
.thenReturn(stringToInputStreamUtf8("{\"schemaVersion\":0}"));
try {
@@ -250,7 +253,7 @@ public void testHandleResponse_unknownSchemaVersion() throws IOException {
}
@Test
- public void testHandleResponse_ociIndexWithNoMediaType()
+ void testHandleResponse_ociIndexWithNoMediaType()
throws IOException, UnknownManifestFormatException {
String ociManifestJson =
"{\n"
@@ -282,7 +285,7 @@ public void testHandleResponse_ociIndexWithNoMediaType()
}
@Test
- public void testHandleResponse_ociManfiestWithNoMediaType()
+ void testHandleResponse_ociManfiestWithNoMediaType()
throws IOException, UnknownManifestFormatException {
String ociManifestJson =
"{\n"
@@ -313,7 +316,7 @@ public void testHandleResponse_ociManfiestWithNoMediaType()
}
@Test
- public void testHandleResponse_invalidOciManfiest() throws IOException {
+ void testHandleResponse_invalidOciManfiest() throws IOException {
Mockito.when(mockResponse.getBody())
.thenReturn(stringToInputStreamUtf8("{\"schemaVersion\": 2}"));
@@ -330,31 +333,31 @@ public void testHandleResponse_invalidOciManfiest() throws IOException {
}
@Test
- public void testGetApiRoute() throws MalformedURLException {
+ void testGetApiRoute() throws MalformedURLException {
Assert.assertEquals(
new URL("http://someApiBase/someImageName/manifests/test-image-tag"),
testManifestPuller.getApiRoute("http://someApiBase/"));
}
@Test
- public void testGetHttpMethod() {
+ void testGetHttpMethod() {
Assert.assertEquals("GET", testManifestPuller.getHttpMethod());
}
@Test
- public void testGetActionDescription() {
+ void testGetActionDescription() {
Assert.assertEquals(
"pull image manifest for someServerUrl/someImageName:test-image-tag",
testManifestPuller.getActionDescription());
}
@Test
- public void testGetContent() {
+ void testGetContent() {
Assert.assertNull(testManifestPuller.getContent());
}
@Test
- public void testGetAccept() {
+ void testGetAccept() {
Assert.assertEquals(
Arrays.asList(
OciManifestTemplate.MANIFEST_MEDIA_TYPE,
diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/ManifestPusherTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/ManifestPusherTest.java
index e5bd833c459..5c3a335f441 100644
--- a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/ManifestPusherTest.java
+++ b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/ManifestPusherTest.java
@@ -41,16 +41,19 @@
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
/** Tests for {@link ManifestPusher}. */
-@RunWith(MockitoJUnitRunner.class)
-public class ManifestPusherTest {
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class ManifestPusherTest {
@Mock private Response mockResponse;
@Mock private EventHandlers mockEventHandlers;
@@ -59,8 +62,8 @@ public class ManifestPusherTest {
private V22ManifestTemplate fakeManifestTemplate;
private ManifestPusher testManifestPusher;
- @Before
- public void setUp() throws URISyntaxException, IOException {
+ @BeforeEach
+ void setUp() throws URISyntaxException, IOException {
v22manifestJsonFile = Paths.get(Resources.getResource("core/json/v22manifest.json").toURI());
fakeManifestTemplate =
JsonTemplateMapper.readJsonFromFile(v22manifestJsonFile, V22ManifestTemplate.class);
@@ -74,7 +77,7 @@ public void setUp() throws URISyntaxException, IOException {
}
@Test
- public void testGetContent() throws IOException {
+ void testGetContent() throws IOException {
BlobHttpContent body = testManifestPusher.getContent();
Assert.assertNotNull(body);
@@ -89,7 +92,7 @@ public void testGetContent() throws IOException {
}
@Test
- public void testHandleResponse_valid() throws IOException {
+ void testHandleResponse_valid() throws IOException {
DescriptorDigest expectedDigest = Digests.computeJsonDigest(fakeManifestTemplate);
Mockito.when(mockResponse.getHeader("Docker-Content-Digest"))
.thenReturn(Collections.singletonList(expectedDigest.toString()));
@@ -97,7 +100,7 @@ public void testHandleResponse_valid() throws IOException {
}
@Test
- public void testHandleResponse_noDigest() throws IOException {
+ void testHandleResponse_noDigest() throws IOException {
DescriptorDigest expectedDigest = Digests.computeJsonDigest(fakeManifestTemplate);
Mockito.when(mockResponse.getHeader("Docker-Content-Digest"))
.thenReturn(Collections.emptyList());
@@ -108,7 +111,7 @@ public void testHandleResponse_noDigest() throws IOException {
}
@Test
- public void testHandleResponse_multipleDigests() throws IOException {
+ void testHandleResponse_multipleDigests() throws IOException {
DescriptorDigest expectedDigest = Digests.computeJsonDigest(fakeManifestTemplate);
Mockito.when(mockResponse.getHeader("Docker-Content-Digest"))
.thenReturn(Arrays.asList("too", "many"));
@@ -120,7 +123,7 @@ public void testHandleResponse_multipleDigests() throws IOException {
}
@Test
- public void testHandleResponse_invalidDigest() throws IOException {
+ void testHandleResponse_invalidDigest() throws IOException {
DescriptorDigest expectedDigest = Digests.computeJsonDigest(fakeManifestTemplate);
Mockito.when(mockResponse.getHeader("Docker-Content-Digest"))
.thenReturn(Collections.singletonList("not valid"));
@@ -132,32 +135,32 @@ public void testHandleResponse_invalidDigest() throws IOException {
}
@Test
- public void testApiRoute() throws MalformedURLException {
+ void testApiRoute() throws MalformedURLException {
Assert.assertEquals(
new URL("http://someApiBase/someImageName/manifests/test-image-tag"),
testManifestPusher.getApiRoute("http://someApiBase/"));
}
@Test
- public void testGetHttpMethod() {
+ void testGetHttpMethod() {
Assert.assertEquals("PUT", testManifestPusher.getHttpMethod());
}
@Test
- public void testGetActionDescription() {
+ void testGetActionDescription() {
Assert.assertEquals(
"push image manifest for someServerUrl/someImageName:test-image-tag",
testManifestPusher.getActionDescription());
}
@Test
- public void testGetAccept() {
+ void testGetAccept() {
Assert.assertEquals(0, testManifestPusher.getAccept().size());
}
/** Docker Registry 2.0 and 2.1 return 400 / TAG_INVALID. */
@Test
- public void testHandleHttpResponseException_dockerRegistry_tagInvalid() throws ResponseException {
+ void testHandleHttpResponseException_dockerRegistry_tagInvalid() throws ResponseException {
ResponseException exception = Mockito.mock(ResponseException.class);
Mockito.when(exception.getStatusCode()).thenReturn(HttpStatus.SC_BAD_REQUEST);
Mockito.when(exception.getContent())
@@ -179,8 +182,7 @@ public void testHandleHttpResponseException_dockerRegistry_tagInvalid() throws R
/** Docker Registry 2.2 returns a 400 / MANIFEST_INVALID. */
@Test
- public void testHandleHttpResponseException_dockerRegistry_manifestInvalid()
- throws ResponseException {
+ void testHandleHttpResponseException_dockerRegistry_manifestInvalid() throws ResponseException {
ResponseException exception = Mockito.mock(ResponseException.class);
Mockito.when(exception.getStatusCode()).thenReturn(HttpStatus.SC_BAD_REQUEST);
Mockito.when(exception.getContent())
@@ -202,7 +204,7 @@ public void testHandleHttpResponseException_dockerRegistry_manifestInvalid()
/** Quay.io returns an undocumented 415 / MANIFEST_INVALID. */
@Test
- public void testHandleHttpResponseException_quayIo() throws ResponseException {
+ void testHandleHttpResponseException_quayIo() throws ResponseException {
ResponseException exception = Mockito.mock(ResponseException.class);
Mockito.when(exception.getStatusCode()).thenReturn(HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE);
Mockito.when(exception.getContent())
@@ -224,7 +226,7 @@ public void testHandleHttpResponseException_quayIo() throws ResponseException {
}
@Test
- public void testHandleHttpResponseException_otherError() throws RegistryErrorException {
+ void testHandleHttpResponseException_otherError() throws RegistryErrorException {
ResponseException exception = Mockito.mock(ResponseException.class);
Mockito.when(exception.getStatusCode()).thenReturn(HttpStatus.SC_UNAUTHORIZED);
try {
diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryAliasGroupTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryAliasGroupTest.java
index 4c78c26f8ba..36bc817482b 100644
--- a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryAliasGroupTest.java
+++ b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryAliasGroupTest.java
@@ -21,20 +21,20 @@
import java.util.List;
import java.util.Set;
import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/** Tests for {@link RegistryAliasGroup}. */
-public class RegistryAliasGroupTest {
+class RegistryAliasGroupTest {
@Test
- public void testGetAliasesGroup_noKnownAliases() {
+ void testGetAliasesGroup_noKnownAliases() {
List singleton = RegistryAliasGroup.getAliasesGroup("something.gcr.io");
Assert.assertEquals(1, singleton.size());
Assert.assertEquals("something.gcr.io", singleton.get(0));
}
@Test
- public void testGetAliasesGroup_dockerHub() {
+ void testGetAliasesGroup_dockerHub() {
Set aliases =
Sets.newHashSet(
"registry.hub.docker.com", "index.docker.io", "registry-1.docker.io", "docker.io");
@@ -44,13 +44,13 @@ public void testGetAliasesGroup_dockerHub() {
}
@Test
- public void testGetHost_noAlias() {
+ void testGetHost_noAlias() {
String host = RegistryAliasGroup.getHost("something.gcr.io");
Assert.assertEquals("something.gcr.io", host);
}
@Test
- public void testGetHost_dockerIo() {
+ void testGetHost_dockerIo() {
String host = RegistryAliasGroup.getHost("docker.io");
Assert.assertEquals("registry-1.docker.io", host);
}
diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryAuthenticationFailedExceptionTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryAuthenticationFailedExceptionTest.java
index cba6cd769ac..5a797b487e4 100644
--- a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryAuthenticationFailedExceptionTest.java
+++ b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryAuthenticationFailedExceptionTest.java
@@ -18,13 +18,13 @@
import com.google.cloud.tools.jib.api.RegistryAuthenticationFailedException;
import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/** Tests for {@link RegistryAuthenticationFailedException}. */
-public class RegistryAuthenticationFailedExceptionTest {
+class RegistryAuthenticationFailedExceptionTest {
@Test
- public void testRegistryAuthenticationFailedException_message() {
+ void testRegistryAuthenticationFailedException_message() {
RegistryAuthenticationFailedException exception =
new RegistryAuthenticationFailedException("serverUrl", "imageName", "message");
Assert.assertEquals("serverUrl", exception.getServerUrl());
@@ -35,7 +35,7 @@ public void testRegistryAuthenticationFailedException_message() {
}
@Test
- public void testRegistryAuthenticationFailedException_exception() {
+ void testRegistryAuthenticationFailedException_exception() {
Throwable cause = new Throwable("message");
RegistryAuthenticationFailedException exception =
new RegistryAuthenticationFailedException("serverUrl", "imageName", cause);
diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryAuthenticatorTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryAuthenticatorTest.java
index 0ce5be3dba7..8ee1f090057 100644
--- a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryAuthenticatorTest.java
+++ b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryAuthenticatorTest.java
@@ -37,18 +37,23 @@
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
/** Tests for {@link RegistryAuthenticator}. */
-@RunWith(MockitoJUnitRunner.class)
-public class RegistryAuthenticatorTest {
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class RegistryAuthenticatorTest {
private final RegistryEndpointRequestProperties registryEndpointRequestProperties =
new RegistryEndpointRequestProperties("someserver", "someimage");
@@ -59,8 +64,8 @@ public class RegistryAuthenticatorTest {
private RegistryAuthenticator registryAuthenticator;
- @Before
- public void setUp() throws RegistryAuthenticationFailedException, IOException {
+ @BeforeEach
+ void setUp() throws RegistryAuthenticationFailedException, IOException {
registryAuthenticator =
RegistryAuthenticator.fromAuthenticationMethod(
"Bearer realm=\"https://somerealm\",service=\"someservice\",scope=\"somescope\"",
@@ -77,7 +82,7 @@ public void setUp() throws RegistryAuthenticationFailedException, IOException {
}
@Test
- public void testFromAuthenticationMethod_bearer()
+ void testFromAuthenticationMethod_bearer()
throws MalformedURLException, RegistryAuthenticationFailedException {
RegistryAuthenticator registryAuthenticator =
RegistryAuthenticator.fromAuthenticationMethod(
@@ -107,7 +112,7 @@ public void testFromAuthenticationMethod_bearer()
}
@Test
- public void testAuthRequestParameters_basicAuth() {
+ void testAuthRequestParameters_basicAuth() {
Assert.assertEquals(
"service=someservice&scope=repository:someimage:scope",
registryAuthenticator.getAuthRequestParameters(
@@ -115,7 +120,7 @@ public void testAuthRequestParameters_basicAuth() {
}
@Test
- public void testAuthRequestParameters_oauth2() {
+ void testAuthRequestParameters_oauth2() {
Credential credential = Credential.from("", "oauth2_access_token");
Assert.assertEquals(
"service=someservice&scope=repository:someimage:scope"
@@ -126,24 +131,24 @@ public void testAuthRequestParameters_oauth2() {
}
@Test
- public void isOAuth2Auth_nullCredential() {
+ void isOAuth2Auth_nullCredential() {
Assert.assertFalse(registryAuthenticator.isOAuth2Auth(null));
}
@Test
- public void isOAuth2Auth_basicAuth() {
+ void isOAuth2Auth_basicAuth() {
Credential credential = Credential.from("name", "password");
Assert.assertFalse(registryAuthenticator.isOAuth2Auth(credential));
}
@Test
- public void isOAuth2Auth_oauth2() {
+ void isOAuth2Auth_oauth2() {
Credential credential = Credential.from("", "oauth2_token");
Assert.assertTrue(registryAuthenticator.isOAuth2Auth(credential));
}
@Test
- public void getAuthenticationUrl_basicAuth() throws MalformedURLException {
+ void getAuthenticationUrl_basicAuth() throws MalformedURLException {
Assert.assertEquals(
new URL("https://somerealm?service=someservice&scope=repository:someimage:scope"),
registryAuthenticator.getAuthenticationUrl(
@@ -151,7 +156,7 @@ public void getAuthenticationUrl_basicAuth() throws MalformedURLException {
}
@Test
- public void istAuthenticationUrl_oauth2() throws MalformedURLException {
+ void istAuthenticationUrl_oauth2() throws MalformedURLException {
Credential credential = Credential.from("", "oauth2_token");
Assert.assertEquals(
new URL("https://somerealm"),
@@ -159,7 +164,7 @@ public void istAuthenticationUrl_oauth2() throws MalformedURLException {
}
@Test
- public void testFromAuthenticationMethod_basic() throws RegistryAuthenticationFailedException {
+ void testFromAuthenticationMethod_basic() throws RegistryAuthenticationFailedException {
assertThat(
RegistryAuthenticator.fromAuthenticationMethod(
"Basic", registryEndpointRequestProperties, "user-agent", httpClient))
@@ -191,7 +196,7 @@ public void testFromAuthenticationMethod_basic() throws RegistryAuthenticationFa
}
@Test
- public void testFromAuthenticationMethod_noBearer() {
+ void testFromAuthenticationMethod_noBearer() {
try {
RegistryAuthenticator.fromAuthenticationMethod(
"realm=\"https://somerealm\",service=\"someservice\",scope=\"somescope\"",
@@ -208,7 +213,7 @@ public void testFromAuthenticationMethod_noBearer() {
}
@Test
- public void testFromAuthenticationMethod_noRealm() {
+ void testFromAuthenticationMethod_noRealm() {
try {
RegistryAuthenticator.fromAuthenticationMethod(
"Bearer scope=\"somescope\"",
@@ -225,7 +230,7 @@ public void testFromAuthenticationMethod_noRealm() {
}
@Test
- public void testFromAuthenticationMethod_noService()
+ void testFromAuthenticationMethod_noService()
throws MalformedURLException, RegistryAuthenticationFailedException {
RegistryAuthenticator registryAuthenticator =
RegistryAuthenticator.fromAuthenticationMethod(
@@ -242,7 +247,7 @@ public void testFromAuthenticationMethod_noService()
}
@Test
- public void testUserAgent()
+ void testUserAgent()
throws IOException, InterruptedException, GeneralSecurityException, URISyntaxException,
RegistryCredentialsNotSentException {
try (TestWebServer server = new TestWebServer(false)) {
@@ -264,7 +269,7 @@ public void testUserAgent()
}
@Test
- public void testSourceImage_differentSourceRepository()
+ void testSourceImage_differentSourceRepository()
throws RegistryCredentialsNotSentException, RegistryAuthenticationFailedException {
RegistryAuthenticator authenticator =
RegistryAuthenticator.fromAuthenticationMethod(
@@ -281,7 +286,7 @@ public void testSourceImage_differentSourceRepository()
}
@Test
- public void testSourceImage_sameSourceRepository()
+ void testSourceImage_sameSourceRepository()
throws RegistryCredentialsNotSentException, RegistryAuthenticationFailedException {
RegistryAuthenticator authenticator =
RegistryAuthenticator.fromAuthenticationMethod(
@@ -297,7 +302,7 @@ public void testSourceImage_sameSourceRepository()
}
@Test
- public void testAuthorizationCleared() throws RegistryAuthenticationFailedException, IOException {
+ void testAuthorizationCleared() throws RegistryAuthenticationFailedException, IOException {
ResponseException responseException = Mockito.mock(ResponseException.class);
Mockito.when(responseException.getStatusCode()).thenReturn(401);
Mockito.when(responseException.requestAuthorizationCleared()).thenReturn(true);
@@ -315,27 +320,15 @@ public void testAuthorizationCleared() throws RegistryAuthenticationFailedExcept
}
}
- @Test
- public void testAuthenticationResponseTemplate_readsToken() throws IOException {
- String input = "{\"token\":\"test_value\"}";
- RegistryAuthenticator.AuthenticationResponseTemplate template =
- JsonTemplateMapper.readJson(
- input, RegistryAuthenticator.AuthenticationResponseTemplate.class);
- Assert.assertEquals("test_value", template.getToken());
- }
-
- @Test
- public void testAuthenticationResponseTemplate_readsAccessToken() throws IOException {
- String input = "{\"access_token\":\"test_value\"}";
- RegistryAuthenticator.AuthenticationResponseTemplate template =
- JsonTemplateMapper.readJson(
- input, RegistryAuthenticator.AuthenticationResponseTemplate.class);
- Assert.assertEquals("test_value", template.getToken());
- }
-
- @Test
- public void testAuthenticationResponseTemplate_prefersToken() throws IOException {
- String input = "{\"token\":\"test_value\",\"access_token\":\"wrong_value\"}";
+ @ParameterizedTest
+ @CsvSource(
+ value = {
+ "{\"token\":\"test_value\"}",
+ "{\"access_token\":\"test_value\"}",
+ "{\"token\":\"test_value\",\"access_token\":\"wrong_value\"}"
+ },
+ delimiter = '|')
+ void testAuthenticationResponseTemplate_readsToken(String input) throws IOException {
RegistryAuthenticator.AuthenticationResponseTemplate template =
JsonTemplateMapper.readJson(
input, RegistryAuthenticator.AuthenticationResponseTemplate.class);
@@ -343,7 +336,7 @@ public void testAuthenticationResponseTemplate_prefersToken() throws IOException
}
@Test
- public void testAuthenticationResponseTemplate_acceptsNull() throws IOException {
+ void testAuthenticationResponseTemplate_acceptsNull() throws IOException {
String input = "{}";
RegistryAuthenticator.AuthenticationResponseTemplate template =
JsonTemplateMapper.readJson(
diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryClientTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryClientTest.java
index 97f72cda048..34f1a6c9cd4 100644
--- a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryClientTest.java
+++ b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryClientTest.java
@@ -38,22 +38,25 @@
import javax.annotation.Nullable;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
-import org.junit.After;
import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentMatcher;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
/**
* Tests for {@link RegistryClient}. More comprehensive tests can be found in the integration tests.
*/
-@RunWith(MockitoJUnitRunner.class)
-public class RegistryClientTest {
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class RegistryClientTest {
@Mock private EventHandlers eventHandlers;
@@ -62,15 +65,15 @@ public class RegistryClientTest {
private TestWebServer registry;
private TestWebServer authServer;
- @Before
- public void setUp() throws DigestException {
+ @BeforeEach
+ void setUp() throws DigestException {
digest =
DescriptorDigest.fromHash(
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
}
- @After
- public void tearDown() throws IOException {
+ @AfterEach
+ void tearDown() throws IOException {
if (registry != null) {
registry.close();
}
@@ -80,7 +83,7 @@ public void tearDown() throws IOException {
}
@Test
- public void testDoBearerAuth_returnsFalseOnBasicAuth()
+ void testDoBearerAuth_returnsFalseOnBasicAuth()
throws IOException, InterruptedException, GeneralSecurityException, URISyntaxException,
RegistryException {
String basicAuth =
@@ -95,7 +98,7 @@ public void testDoBearerAuth_returnsFalseOnBasicAuth()
}
@Test
- public void testDoBearerAuth()
+ void testDoBearerAuth()
throws IOException, InterruptedException, GeneralSecurityException, URISyntaxException,
RegistryException {
setUpAuthServerAndRegistry(1, "HTTP/1.1 200 OK\nContent-Length: 1234\n\n");
@@ -111,7 +114,7 @@ public void testDoBearerAuth()
}
@Test
- public void testAutomaticTokenRefresh()
+ void testAutomaticTokenRefresh()
throws IOException, InterruptedException, GeneralSecurityException, URISyntaxException,
RegistryException {
setUpAuthServerAndRegistry(3, "HTTP/1.1 200 OK\nContent-Length: 5678\n\n");
@@ -133,7 +136,7 @@ public void testAutomaticTokenRefresh()
}
@Test
- public void testAutomaticTokenRefresh_badWwwAuthenticateResponse()
+ void testAutomaticTokenRefresh_badWwwAuthenticateResponse()
throws IOException, InterruptedException, GeneralSecurityException, URISyntaxException,
RegistryException {
String tokenResponse = "HTTP/1.1 200 OK\nContent-Length: 26\n\n{\"token\":\"awesome-token!\"}";
@@ -168,7 +171,7 @@ public void testAutomaticTokenRefresh_badWwwAuthenticateResponse()
}
@Test
- public void testAutomaticTokenRefresh_refreshLimit()
+ void testAutomaticTokenRefresh_refreshLimit()
throws IOException, InterruptedException, GeneralSecurityException, URISyntaxException,
RegistryException {
String tokenResponse = "HTTP/1.1 200 OK\nContent-Length: 26\n\n{\"token\":\"awesome-token!\"}";
@@ -200,7 +203,7 @@ public void testAutomaticTokenRefresh_refreshLimit()
}
@Test
- public void testConfigureBasicAuth()
+ void testConfigureBasicAuth()
throws IOException, InterruptedException, GeneralSecurityException, URISyntaxException,
RegistryException {
String basicAuth = "HTTP/1.1 200 OK\nContent-Length: 56789\n\n";
@@ -215,7 +218,7 @@ public void testConfigureBasicAuth()
}
@Test
- public void testAuthPullByWwwAuthenticate_bearerAuth()
+ void testAuthPullByWwwAuthenticate_bearerAuth()
throws IOException, InterruptedException, GeneralSecurityException, URISyntaxException,
RegistryException {
String tokenResponse = "HTTP/1.1 200 OK\nContent-Length: 26\n\n{\"token\":\"awesome-token!\"}";
@@ -234,7 +237,7 @@ public void testAuthPullByWwwAuthenticate_bearerAuth()
}
@Test
- public void testAuthPullByWwwAuthenticate_basicAuth()
+ void testAuthPullByWwwAuthenticate_basicAuth()
throws IOException, InterruptedException, GeneralSecurityException, URISyntaxException,
RegistryException {
String blobResponse = "HTTP/1.1 200 OK\nContent-Length: 5678\n\n";
@@ -251,7 +254,7 @@ public void testAuthPullByWwwAuthenticate_basicAuth()
}
@Test
- public void testAuthPullByWwwAuthenticate_basicAuthRequestedButNullCredential()
+ void testAuthPullByWwwAuthenticate_basicAuthRequestedButNullCredential()
throws IOException, InterruptedException, GeneralSecurityException, URISyntaxException,
RegistryException {
String blobResponse = "HTTP/1.1 200 OK\nContent-Length: 5678\n\n";
@@ -268,7 +271,7 @@ public void testAuthPullByWwwAuthenticate_basicAuthRequestedButNullCredential()
}
@Test
- public void testAuthPullByWwwAuthenticate_basicAuthRequestedButOAuth2Credential()
+ void testAuthPullByWwwAuthenticate_basicAuthRequestedButOAuth2Credential()
throws IOException, InterruptedException, GeneralSecurityException, URISyntaxException,
RegistryException {
String blobResponse = "HTTP/1.1 200 OK\nContent-Length: 5678\n\n";
@@ -287,7 +290,7 @@ public void testAuthPullByWwwAuthenticate_basicAuthRequestedButOAuth2Credential(
}
@Test
- public void testAuthPullByWwwAuthenticate_invalidAuthMethod() {
+ void testAuthPullByWwwAuthenticate_invalidAuthMethod() {
RegistryClient registryClient =
RegistryClient.factory(eventHandlers, "server", "foo/bar", null).newRegistryClient();
try {
@@ -302,7 +305,7 @@ public void testAuthPullByWwwAuthenticate_invalidAuthMethod() {
}
@Test
- public void testPullManifest()
+ void testPullManifest()
throws IOException, InterruptedException, GeneralSecurityException, URISyntaxException,
RegistryException {
String manifestResponse =
@@ -340,7 +343,7 @@ public void testPullManifest()
}
@Test
- public void testPullManifest_manifestList()
+ void testPullManifest_manifestList()
throws IOException, InterruptedException, GeneralSecurityException, URISyntaxException,
RegistryException {
String manifestResponse =
diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryEndpointCallerTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryEndpointCallerTest.java
index d9b85bc9208..8de6f964315 100644
--- a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryEndpointCallerTest.java
+++ b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryEndpointCallerTest.java
@@ -47,19 +47,24 @@
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.Assert;
-import org.junit.Before;
import org.junit.Rule;
-import org.junit.Test;
import org.junit.contrib.java.lang.system.RestoreSystemProperties;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
/** Tests for {@link RegistryEndpointCaller}. */
-@RunWith(MockitoJUnitRunner.class)
-public class RegistryEndpointCallerTest {
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class RegistryEndpointCallerTest {
/** Implementation of {@link RegistryEndpointProvider} for testing. */
private static class TestRegistryEndpointProvider implements RegistryEndpointProvider {
@@ -118,8 +123,8 @@ private static ResponseException mockResponseException(int statusCode) {
private RegistryEndpointCaller endpointCaller;
- @Before
- public void setUp() throws IOException {
+ @BeforeEach
+ void setUp() throws IOException {
endpointCaller =
new RegistryEndpointCaller<>(
mockEventHandlers,
@@ -134,7 +139,7 @@ public void setUp() throws IOException {
}
@Test
- public void testCall_secureCallerOnUnverifiableServer() throws IOException, RegistryException {
+ void testCall_secureCallerOnUnverifiableServer() throws IOException, RegistryException {
Mockito.when(mockHttpClient.call(Mockito.any(), Mockito.any(), Mockito.any()))
.thenThrow(Mockito.mock(SSLPeerUnverifiedException.class));
@@ -150,7 +155,7 @@ public void testCall_secureCallerOnUnverifiableServer() throws IOException, Regi
}
@Test
- public void testCall_noHttpResponse() throws IOException, RegistryException {
+ void testCall_noHttpResponse() throws IOException, RegistryException {
NoHttpResponseException mockNoResponseException = Mockito.mock(NoHttpResponseException.class);
setUpRegistryResponse(mockNoResponseException);
@@ -164,12 +169,12 @@ public void testCall_noHttpResponse() throws IOException, RegistryException {
}
@Test
- public void testCall_unauthorized() throws IOException, RegistryException {
+ void testCall_unauthorized() throws IOException, RegistryException {
verifyThrowsRegistryUnauthorizedException(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
}
@Test
- public void testCall_credentialsNotSentOverHttp() throws IOException, RegistryException {
+ void testCall_credentialsNotSentOverHttp() throws IOException, RegistryException {
ResponseException unauthorizedException =
mockResponseException(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
Mockito.when(unauthorizedException.requestAuthorizationCleared()).thenReturn(true);
@@ -187,7 +192,7 @@ public void testCall_credentialsNotSentOverHttp() throws IOException, RegistryEx
}
@Test
- public void testCall_credentialsForcedOverHttp() throws IOException, RegistryException {
+ void testCall_credentialsForcedOverHttp() throws IOException, RegistryException {
ResponseException unauthorizedException =
mockResponseException(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
setUpRegistryResponse(unauthorizedException);
@@ -205,27 +210,27 @@ public void testCall_credentialsForcedOverHttp() throws IOException, RegistryExc
}
@Test
- public void testCall_forbidden() throws IOException, RegistryException {
+ void testCall_forbidden() throws IOException, RegistryException {
verifyThrowsRegistryUnauthorizedException(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
}
@Test
- public void testCall_badRequest() throws IOException, RegistryException {
+ void testCall_badRequest() throws IOException, RegistryException {
verifyThrowsRegistryErrorException(HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
}
@Test
- public void testCall_notFound() throws IOException, RegistryException {
+ void testCall_notFound() throws IOException, RegistryException {
verifyThrowsRegistryErrorException(HttpStatusCodes.STATUS_CODE_NOT_FOUND);
}
@Test
- public void testCall_methodNotAllowed() throws IOException, RegistryException {
+ void testCall_methodNotAllowed() throws IOException, RegistryException {
verifyThrowsRegistryErrorException(HttpStatusCodes.STATUS_CODE_METHOD_NOT_ALLOWED);
}
@Test
- public void testCall_unknown() throws IOException, RegistryException {
+ void testCall_unknown() throws IOException, RegistryException {
ResponseException responseException =
mockResponseException(HttpStatusCodes.STATUS_CODE_SERVER_ERROR);
setUpRegistryResponse(responseException);
@@ -240,7 +245,7 @@ public void testCall_unknown() throws IOException, RegistryException {
}
@Test
- public void testCall_logErrorOnIoExceptions() throws IOException, RegistryException {
+ void testCall_logErrorOnIoExceptions() throws IOException, RegistryException {
IOException ioException = new IOException("detailed exception message");
setUpRegistryResponse(ioException);
@@ -262,7 +267,7 @@ public void testCall_logErrorOnIoExceptions() throws IOException, RegistryExcept
}
@Test
- public void testCall_logErrorOnBrokenPipe() throws IOException, RegistryException {
+ void testCall_logErrorOnBrokenPipe() throws IOException, RegistryException {
IOException ioException = new IOException("this is due to broken pipe");
setUpRegistryResponse(ioException);
@@ -290,7 +295,7 @@ public void testCall_logErrorOnBrokenPipe() throws IOException, RegistryExceptio
}
@Test
- public void testCall_logNullExceptionMessage() throws IOException, RegistryException {
+ void testCall_logNullExceptionMessage() throws IOException, RegistryException {
setUpRegistryResponse(new IOException());
try {
@@ -310,7 +315,7 @@ public void testCall_logNullExceptionMessage() throws IOException, RegistryExcep
}
@Test
- public void testHttpTimeout_propertyNotSet() throws IOException, RegistryException {
+ void testHttpTimeout_propertyNotSet() throws IOException, RegistryException {
ArgumentCaptor requestCaptor = ArgumentCaptor.forClass(Request.class);
Mockito.when(mockHttpClient.call(Mockito.any(), Mockito.any(), requestCaptor.capture()))
.thenReturn(mockResponse);
@@ -323,20 +328,21 @@ public void testHttpTimeout_propertyNotSet() throws IOException, RegistryExcepti
Assert.assertEquals(20000, new RequestWrapper(requestCaptor.getValue()).getHttpTimeout());
}
- @Test
- public void testHttpTimeout_stringValue() throws IOException, RegistryException {
+ @ParameterizedTest
+ @CsvSource({"random string, 20000", "0, 0", "7593, 7593"})
+ void testHttpTimeout_stringValue(String prop, long val) throws IOException, RegistryException {
ArgumentCaptor requestCaptor = ArgumentCaptor.forClass(Request.class);
Mockito.when(mockHttpClient.call(Mockito.any(), Mockito.any(), requestCaptor.capture()))
.thenReturn(mockResponse);
- System.setProperty(JibSystemProperties.HTTP_TIMEOUT, "random string");
+ System.setProperty(JibSystemProperties.HTTP_TIMEOUT, prop);
endpointCaller.call();
- Assert.assertEquals(20000, new RequestWrapper(requestCaptor.getValue()).getHttpTimeout());
+ Assert.assertEquals(val, new RequestWrapper(requestCaptor.getValue()).getHttpTimeout());
}
@Test
- public void testHttpTimeout_negativeValue() throws IOException, RegistryException {
+ void testHttpTimeout_negativeValue() throws IOException, RegistryException {
ArgumentCaptor requestCaptor = ArgumentCaptor.forClass(Request.class);
Mockito.when(mockHttpClient.call(Mockito.any(), Mockito.any(), requestCaptor.capture()))
.thenReturn(mockResponse);
@@ -350,51 +356,27 @@ public void testHttpTimeout_negativeValue() throws IOException, RegistryExceptio
}
@Test
- public void testHttpTimeout_0accepted() throws IOException, RegistryException {
- ArgumentCaptor requestCaptor = ArgumentCaptor.forClass(Request.class);
- Mockito.when(mockHttpClient.call(Mockito.any(), Mockito.any(), requestCaptor.capture()))
- .thenReturn(mockResponse);
-
- System.setProperty(JibSystemProperties.HTTP_TIMEOUT, "0");
- endpointCaller.call();
-
- Assert.assertEquals(0, new RequestWrapper(requestCaptor.getValue()).getHttpTimeout());
- }
-
- @Test
- public void testHttpTimeout() throws IOException, RegistryException {
- ArgumentCaptor requestCaptor = ArgumentCaptor.forClass(Request.class);
- Mockito.when(mockHttpClient.call(Mockito.any(), Mockito.any(), requestCaptor.capture()))
- .thenReturn(mockResponse);
-
- System.setProperty(JibSystemProperties.HTTP_TIMEOUT, "7593");
- endpointCaller.call();
-
- Assert.assertEquals(7593, new RequestWrapper(requestCaptor.getValue()).getHttpTimeout());
- }
-
- @Test
- public void testIsBrokenPipe_notBrokenPipe() {
+ void testIsBrokenPipe_notBrokenPipe() {
Assert.assertFalse(RegistryEndpointCaller.isBrokenPipe(new IOException()));
Assert.assertFalse(RegistryEndpointCaller.isBrokenPipe(new SocketException()));
Assert.assertFalse(RegistryEndpointCaller.isBrokenPipe(new SSLException("mock")));
}
@Test
- public void testIsBrokenPipe_brokenPipe() {
+ void testIsBrokenPipe_brokenPipe() {
Assert.assertTrue(RegistryEndpointCaller.isBrokenPipe(new IOException("cool broken pipe !")));
Assert.assertTrue(RegistryEndpointCaller.isBrokenPipe(new SocketException("BROKEN PIPE")));
Assert.assertTrue(RegistryEndpointCaller.isBrokenPipe(new SSLException("calm BrOkEn PiPe")));
}
@Test
- public void testIsBrokenPipe_nestedBrokenPipe() {
+ void testIsBrokenPipe_nestedBrokenPipe() {
IOException exception = new IOException(new SSLException(new SocketException("Broken pipe")));
Assert.assertTrue(RegistryEndpointCaller.isBrokenPipe(exception));
}
@Test
- public void testIsBrokenPipe_terminatesWhenCauseIsOriginal() {
+ void testIsBrokenPipe_terminatesWhenCauseIsOriginal() {
IOException exception = Mockito.mock(IOException.class);
Mockito.when(exception.getCause()).thenReturn(exception);
@@ -402,7 +384,7 @@ public void testIsBrokenPipe_terminatesWhenCauseIsOriginal() {
}
@Test
- public void testNewRegistryErrorException_jsonErrorOutput() {
+ void testNewRegistryErrorException_jsonErrorOutput() {
ResponseException httpException = Mockito.mock(ResponseException.class);
Mockito.when(httpException.getContent())
.thenReturn(
@@ -417,7 +399,7 @@ public void testNewRegistryErrorException_jsonErrorOutput() {
}
@Test
- public void testNewRegistryErrorException_nonJsonErrorOutput() {
+ void testNewRegistryErrorException_nonJsonErrorOutput() {
ResponseException httpException = Mockito.mock(ResponseException.class);
// Registry returning non-structured error output
Mockito.when(httpException.getContent()).thenReturn(">>>>> (404) page not found <<<<<");
@@ -434,7 +416,7 @@ public void testNewRegistryErrorException_nonJsonErrorOutput() {
}
@Test
- public void testNewRegistryErrorException_noOutputFromRegistry() {
+ void testNewRegistryErrorException_noOutputFromRegistry() {
ResponseException httpException = Mockito.mock(ResponseException.class);
// Registry returning null error output
Mockito.when(httpException.getContent()).thenReturn(null);
diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryErrorExceptionBuilderTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryErrorExceptionBuilderTest.java
index 17d8895be26..5b37490fa02 100644
--- a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryErrorExceptionBuilderTest.java
+++ b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryErrorExceptionBuilderTest.java
@@ -19,19 +19,22 @@
import com.google.api.client.http.HttpResponseException;
import com.google.cloud.tools.jib.registry.json.ErrorEntryTemplate;
import org.junit.Assert;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
/** Tests for {@link RegistryErrorExceptionBuilder}. */
-@RunWith(MockitoJUnitRunner.class)
-public class RegistryErrorExceptionBuilderTest {
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class RegistryErrorExceptionBuilderTest {
@Mock private HttpResponseException mockHttpResponseException;
@Test
- public void testAddErrorEntry() {
+ void testAddErrorEntry() {
RegistryErrorExceptionBuilder builder =
new RegistryErrorExceptionBuilder("do something", mockHttpResponseException)
.addReason(
diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/credentials/DockerConfigCredentialRetrieverTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/credentials/DockerConfigCredentialRetrieverTest.java
index 509ed28ed4e..d6e441d0db9 100644
--- a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/credentials/DockerConfigCredentialRetrieverTest.java
+++ b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/credentials/DockerConfigCredentialRetrieverTest.java
@@ -26,16 +26,19 @@
import java.util.Optional;
import java.util.function.Consumer;
import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
/** Tests for {@link DockerConfigCredentialRetriever}. */
-@RunWith(MockitoJUnitRunner.class)
-public class DockerConfigCredentialRetrieverTest {
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class DockerConfigCredentialRetrieverTest {
private static final Credential FAKE_CREDENTIAL = Credential.from("username", "password");
@@ -45,8 +48,8 @@ public class DockerConfigCredentialRetrieverTest {
private Path dockerConfigFile;
- @Before
- public void setUp()
+ @BeforeEach
+ void setUp()
throws URISyntaxException, CredentialHelperUnhandledServerUrlException,
CredentialHelperNotFoundException, IOException {
dockerConfigFile = Paths.get(Resources.getResource("core/json/dockerconfig.json").toURI());
@@ -54,7 +57,7 @@ public void setUp()
}
@Test
- public void testRetrieve_nonExistentDockerConfigFile() throws IOException {
+ void testRetrieve_nonExistentDockerConfigFile() throws IOException {
DockerConfigCredentialRetriever dockerConfigCredentialRetriever =
DockerConfigCredentialRetriever.create("some registry", Paths.get("fake/path"));
@@ -62,7 +65,7 @@ public void testRetrieve_nonExistentDockerConfigFile() throws IOException {
}
@Test
- public void testRetrieve_hasAuth() throws IOException {
+ void testRetrieve_hasAuth() throws IOException {
DockerConfigCredentialRetriever dockerConfigCredentialRetriever =
DockerConfigCredentialRetriever.create("some other registry", dockerConfigFile);
@@ -77,7 +80,7 @@ public void testRetrieve_hasAuth() throws IOException {
}
@Test
- public void testRetrieve_authTakesPrecedenceOverUsernameAndPassword() throws IOException {
+ void testRetrieve_authTakesPrecedenceOverUsernameAndPassword() throws IOException {
DockerConfigCredentialRetriever dockerConfigCredentialRetriever =
DockerConfigCredentialRetriever.create("auth and userpw registry", dockerConfigFile);
@@ -92,7 +95,7 @@ public void testRetrieve_authTakesPrecedenceOverUsernameAndPassword() throws IOE
}
@Test
- public void testRetrieve_hasAuthWithUsernameAndPassword() throws IOException {
+ void testRetrieve_hasAuthWithUsernameAndPassword() throws IOException {
DockerConfigCredentialRetriever dockerConfigCredentialRetriever =
DockerConfigCredentialRetriever.create("userpw registry", dockerConfigFile);
@@ -107,7 +110,7 @@ public void testRetrieve_hasAuthWithUsernameAndPassword() throws IOException {
}
@Test
- public void testRetrieve_hasAuth_legacyConfigFormat() throws IOException, URISyntaxException {
+ void testRetrieve_hasAuth_legacyConfigFormat() throws IOException, URISyntaxException {
dockerConfigFile = Paths.get(Resources.getResource("core/json/legacy_dockercfg").toURI());
DockerConfigCredentialRetriever retriever1 =
@@ -129,7 +132,7 @@ public void testRetrieve_hasAuth_legacyConfigFormat() throws IOException, URISyn
}
@Test
- public void testRetrieve_credentialHelperTakesPrecedenceOverAuth() {
+ void testRetrieve_credentialHelperTakesPrecedenceOverAuth() {
Mockito.when(mockDockerConfig.getCredentialHelperFor("some registry"))
.thenReturn(mockDockerCredentialHelper);
Mockito.when(mockDockerCredentialHelper.getCredentialHelper())
@@ -145,7 +148,7 @@ public void testRetrieve_credentialHelperTakesPrecedenceOverAuth() {
}
@Test
- public void testRetrieve_credentialHelper_warn()
+ void testRetrieve_credentialHelper_warn()
throws CredentialHelperUnhandledServerUrlException, CredentialHelperNotFoundException,
IOException {
Mockito.when(mockDockerConfig.getCredentialHelperFor("another registry"))
@@ -164,7 +167,7 @@ public void testRetrieve_credentialHelper_warn()
}
@Test
- public void testRetrieve_none() throws IOException {
+ void testRetrieve_none() throws IOException {
DockerConfigCredentialRetriever dockerConfigCredentialRetriever =
DockerConfigCredentialRetriever.create("unknown registry", dockerConfigFile);
@@ -172,7 +175,7 @@ public void testRetrieve_none() throws IOException {
}
@Test
- public void testRetrieve_credentialFromAlias() {
+ void testRetrieve_credentialFromAlias() {
Mockito.when(mockDockerConfig.getCredentialHelperFor("registry.hub.docker.com"))
.thenReturn(mockDockerCredentialHelper);
DockerConfigCredentialRetriever dockerConfigCredentialRetriever =
@@ -184,7 +187,7 @@ public void testRetrieve_credentialFromAlias() {
}
@Test
- public void testRetrieve_suffixMatching() throws IOException, URISyntaxException {
+ void testRetrieve_suffixMatching() throws IOException, URISyntaxException {
Path dockerConfigFile =
Paths.get(Resources.getResource("core/json/dockerconfig_index_docker_io_v1.json").toURI());
@@ -198,7 +201,7 @@ public void testRetrieve_suffixMatching() throws IOException, URISyntaxException
}
@Test
- public void testRetrieve_suffixMatchingFromAlias() throws IOException, URISyntaxException {
+ void testRetrieve_suffixMatchingFromAlias() throws IOException, URISyntaxException {
Path dockerConfigFile =
Paths.get(Resources.getResource("core/json/dockerconfig_index_docker_io_v1.json").toURI());
@@ -212,7 +215,7 @@ public void testRetrieve_suffixMatchingFromAlias() throws IOException, URISyntax
}
@Test
- public void testRetrieve_azureIdentityToken() throws IOException, URISyntaxException {
+ void testRetrieve_azureIdentityToken() throws IOException, URISyntaxException {
Path dockerConfigFile =
Paths.get(Resources.getResource("core/json/dockerconfig_identity_token.json").toURI());
@@ -226,7 +229,7 @@ public void testRetrieve_azureIdentityToken() throws IOException, URISyntaxExcep
}
@Test
- public void testRetrieve_noErrorWhenMissingAuthField() throws IOException, URISyntaxException {
+ void testRetrieve_noErrorWhenMissingAuthField() throws IOException, URISyntaxException {
Path dockerConfigFile = Paths.get(Resources.getResource("core/json/dockerconfig.json").toURI());
DockerConfigCredentialRetriever dockerConfigCredentialRetriever =
diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/credentials/DockerConfigTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/credentials/DockerConfigTest.java
index 3bd62ac404d..58197a57618 100644
--- a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/credentials/DockerConfigTest.java
+++ b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/credentials/DockerConfigTest.java
@@ -26,17 +26,17 @@
import java.nio.file.Paths;
import java.util.Base64;
import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/** Tests for {@link DockerConfig}. */
-public class DockerConfigTest {
+class DockerConfigTest {
private static String decodeBase64(String base64String) {
return new String(Base64.getDecoder().decode(base64String), StandardCharsets.UTF_8);
}
@Test
- public void test_fromJson() throws URISyntaxException, IOException {
+ void test_fromJson() throws URISyntaxException, IOException {
// Loads the JSON string.
Path jsonFile = Paths.get(Resources.getResource("core/json/dockerconfig.json").toURI());
@@ -65,7 +65,7 @@ public void test_fromJson() throws URISyntaxException, IOException {
}
@Test
- public void testGetAuthFor_orderOfMatchPreference() throws URISyntaxException, IOException {
+ void testGetAuthFor_orderOfMatchPreference() throws URISyntaxException, IOException {
Path json =
Paths.get(Resources.getResource("core/json/dockerconfig_extra_matches.json").toURI());
@@ -85,7 +85,7 @@ public void testGetAuthFor_orderOfMatchPreference() throws URISyntaxException, I
}
@Test
- public void testGetAuthFor_correctSuffixMatching() throws URISyntaxException, IOException {
+ void testGetAuthFor_correctSuffixMatching() throws URISyntaxException, IOException {
Path json =
Paths.get(Resources.getResource("core/json/dockerconfig_extra_matches.json").toURI());
@@ -96,8 +96,7 @@ public void testGetAuthFor_correctSuffixMatching() throws URISyntaxException, IO
}
@Test
- public void testGetCredentialHelperFor_exactMatchInCredHelpers()
- throws URISyntaxException, IOException {
+ void testGetCredentialHelperFor_exactMatchInCredHelpers() throws URISyntaxException, IOException {
Path json = Paths.get(Resources.getResource("core/json/dockerconfig.json").toURI());
DockerConfig dockerConfig =
@@ -109,7 +108,7 @@ public void testGetCredentialHelperFor_exactMatchInCredHelpers()
}
@Test
- public void testGetCredentialHelperFor_withHttps() throws URISyntaxException, IOException {
+ void testGetCredentialHelperFor_withHttps() throws URISyntaxException, IOException {
Path json = Paths.get(Resources.getResource("core/json/dockerconfig.json").toURI());
DockerConfig dockerConfig =
@@ -121,7 +120,7 @@ public void testGetCredentialHelperFor_withHttps() throws URISyntaxException, IO
}
@Test
- public void testGetCredentialHelperFor_withSuffix() throws URISyntaxException, IOException {
+ void testGetCredentialHelperFor_withSuffix() throws URISyntaxException, IOException {
Path json = Paths.get(Resources.getResource("core/json/dockerconfig.json").toURI());
DockerConfig dockerConfig =
@@ -133,8 +132,7 @@ public void testGetCredentialHelperFor_withSuffix() throws URISyntaxException, I
}
@Test
- public void testGetCredentialHelperFor_withProtocolAndSuffix()
- throws URISyntaxException, IOException {
+ void testGetCredentialHelperFor_withProtocolAndSuffix() throws URISyntaxException, IOException {
Path json = Paths.get(Resources.getResource("core/json/dockerconfig.json").toURI());
DockerConfig dockerConfig =
@@ -149,8 +147,7 @@ public void testGetCredentialHelperFor_withProtocolAndSuffix()
}
@Test
- public void testGetCredentialHelperFor_correctSuffixMatching()
- throws URISyntaxException, IOException {
+ void testGetCredentialHelperFor_correctSuffixMatching() throws URISyntaxException, IOException {
Path json = Paths.get(Resources.getResource("core/json/dockerconfig.json").toURI());
DockerConfig dockerConfig =
diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/credentials/DockerCredentialHelperTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/credentials/DockerCredentialHelperTest.java
index 1f17aca613b..b1e7602a855 100644
--- a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/credentials/DockerCredentialHelperTest.java
+++ b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/credentials/DockerCredentialHelperTest.java
@@ -33,15 +33,20 @@
import java.util.Properties;
import java.util.function.Function;
import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
-@RunWith(MockitoJUnitRunner.class)
-public class DockerCredentialHelperTest {
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class DockerCredentialHelperTest {
private static final String CREDENTIAL_JSON =
"{\"Username\":\"myusername\",\"Secret\":\"mysecret\"}";
@@ -53,8 +58,8 @@ public class DockerCredentialHelperTest {
private final Properties systemProperties = new Properties();
- @Before
- public void setUp() throws IOException {
+ @BeforeEach
+ void setUp() throws IOException {
systemProperties.put("os.name", "unknown");
Mockito.when(process.getInputStream())
@@ -66,7 +71,7 @@ public void setUp() throws IOException {
}
@Test
- public void testDockerCredentialsTemplate_read() throws IOException {
+ void testDockerCredentialsTemplate_read() throws IOException {
DockerCredentialHelper.DockerCredentialsTemplate template =
JsonTemplateMapper.readJson(
CREDENTIAL_JSON, DockerCredentialHelper.DockerCredentialsTemplate.class);
@@ -75,7 +80,7 @@ public void testDockerCredentialsTemplate_read() throws IOException {
}
@Test
- public void testDockerCredentialsTemplate_canReadNull() throws IOException {
+ void testDockerCredentialsTemplate_canReadNull() throws IOException {
String input = "{}";
DockerCredentialHelper.DockerCredentialsTemplate template =
JsonTemplateMapper.readJson(input, DockerCredentialHelper.DockerCredentialsTemplate.class);
@@ -84,7 +89,7 @@ public void testDockerCredentialsTemplate_canReadNull() throws IOException {
}
@Test
- public void testRetrieve()
+ void testRetrieve()
throws CredentialHelperUnhandledServerUrlException, CredentialHelperNotFoundException,
IOException {
List command = Arrays.asList(Paths.get("/foo/bar").toString(), "get");
@@ -101,7 +106,7 @@ public void testRetrieve()
}
@Test
- public void testRetrieveWithEnvironment()
+ void testRetrieveWithEnvironment()
throws CredentialHelperUnhandledServerUrlException, CredentialHelperNotFoundException,
IOException {
List command = Arrays.asList(Paths.get("/foo/bar").toString(), "get");
@@ -127,53 +132,22 @@ public void testRetrieveWithEnvironment()
Assert.assertEquals("Value", processBuilderEnvironment.get("ENV_VARIABLE"));
}
- @Test
- public void testRetrieve_cmdSuffixAddedOnWindows()
- throws CredentialHelperUnhandledServerUrlException, CredentialHelperNotFoundException,
- IOException {
- systemProperties.setProperty("os.name", "WINdows");
- List command = Arrays.asList(Paths.get("/foo/bar.cmd").toString(), "get");
- Mockito.when(processBuilderFactory.apply(command)).thenReturn(processBuilder);
-
- DockerCredentialHelper credentialHelper =
- dockerCredentialHelper(
- "serverUrl", Paths.get("/foo/bar"), systemProperties, processBuilderFactory);
- Credential credential = credentialHelper.retrieve();
- Assert.assertEquals("myusername", credential.getUsername());
- Assert.assertEquals("mysecret", credential.getPassword());
-
- Mockito.verify(processBuilderFactory).apply(command);
- }
-
- @Test
- public void testRetrieve_cmdSuffixAlreadyGivenOnWindows()
- throws CredentialHelperUnhandledServerUrlException, CredentialHelperNotFoundException,
- IOException {
- systemProperties.setProperty("os.name", "WINdows");
- List command = Arrays.asList(Paths.get("/foo/bar.CmD").toString(), "get");
- Mockito.when(processBuilderFactory.apply(command)).thenReturn(processBuilder);
-
- DockerCredentialHelper credentialHelper =
- dockerCredentialHelper(
- "serverUrl", Paths.get("/foo/bar.CmD"), systemProperties, processBuilderFactory);
- Credential credential = credentialHelper.retrieve();
- Assert.assertEquals("myusername", credential.getUsername());
- Assert.assertEquals("mysecret", credential.getPassword());
-
- Mockito.verify(processBuilderFactory).apply(command);
- }
-
- @Test
- public void testRetrieve_exeSuffixAlreadyGivenOnWindows()
+ @ParameterizedTest
+ @CsvSource({
+ "/foo/bar.cmd, /foo/bar", // suffix added on windows
+ "/foo/bar.CmD, /foo/bar.CmD", // suffix already given on Windows
+ "/foo/bar.eXE, /foo/bar.eXE" // exe suffix already given
+ })
+ void testRetrieve_cmdSuffixAddedOnWindows(String cmd, String path)
throws CredentialHelperUnhandledServerUrlException, CredentialHelperNotFoundException,
IOException {
systemProperties.setProperty("os.name", "WINdows");
- List command = Arrays.asList(Paths.get("/foo/bar.eXE").toString(), "get");
+ List command = Arrays.asList(Paths.get(cmd).toString(), "get");
Mockito.when(processBuilderFactory.apply(command)).thenReturn(processBuilder);
DockerCredentialHelper credentialHelper =
dockerCredentialHelper(
- "serverUrl", Paths.get("/foo/bar.eXE"), systemProperties, processBuilderFactory);
+ "serverUrl", Paths.get(path), systemProperties, processBuilderFactory);
Credential credential = credentialHelper.retrieve();
Assert.assertEquals("myusername", credential.getUsername());
Assert.assertEquals("mysecret", credential.getPassword());
@@ -182,7 +156,7 @@ public void testRetrieve_exeSuffixAlreadyGivenOnWindows()
}
@Test
- public void testRetrieve_cmdSuffixNotFoundOnWindows()
+ void testRetrieve_cmdSuffixNotFoundOnWindows()
throws CredentialHelperUnhandledServerUrlException, CredentialHelperNotFoundException,
IOException {
systemProperties.setProperty("os.name", "WINdows");
@@ -206,7 +180,7 @@ public void testRetrieve_cmdSuffixNotFoundOnWindows()
}
@Test
- public void testRetrieve_fileNotFoundExceptionMessage()
+ void testRetrieve_fileNotFoundExceptionMessage()
throws CredentialHelperUnhandledServerUrlException, IOException {
Mockito.when(processBuilderFactory.apply(Mockito.any())).thenReturn(processBuilder);
Mockito.when(processBuilder.start())
diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarExtractorTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarExtractorTest.java
index 9f82420b398..87935e2f708 100644
--- a/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarExtractorTest.java
+++ b/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarExtractorTest.java
@@ -30,19 +30,18 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
/** Tests for {@link TarExtractor}. */
-public class TarExtractorTest {
+class TarExtractorTest {
- @Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder();
+ @TempDir public Path temporaryFolder;
@Test
- public void testExtract() throws URISyntaxException, IOException {
+ void testExtract() throws URISyntaxException, IOException {
Path source = Paths.get(Resources.getResource("core/extract.tar").toURI());
- Path destination = temporaryFolder.getRoot().toPath();
+ Path destination = temporaryFolder;
TarExtractor.extract(source, destination);
Assert.assertTrue(Files.exists(destination.resolve("file A")));
@@ -57,9 +56,9 @@ public void testExtract() throws URISyntaxException, IOException {
}
@Test
- public void testExtract_missingDirectoryEntries() throws URISyntaxException, IOException {
+ void testExtract_missingDirectoryEntries() throws URISyntaxException, IOException {
Path source = Paths.get(Resources.getResource("core/extract-missing-dirs.tar").toURI());
- Path destination = temporaryFolder.getRoot().toPath();
+ Path destination = temporaryFolder;
TarExtractor.extract(source, destination);
Assert.assertTrue(Files.exists(destination.resolve("world")));
@@ -73,9 +72,9 @@ public void testExtract_missingDirectoryEntries() throws URISyntaxException, IOE
}
@Test
- public void testExtract_symlinks() throws URISyntaxException, IOException {
+ void testExtract_symlinks() throws URISyntaxException, IOException {
Path source = Paths.get(Resources.getResource("core/symlinks.tar").toURI());
- Path destination = temporaryFolder.getRoot().toPath();
+ Path destination = temporaryFolder;
TarExtractor.extract(source, destination);
Assert.assertTrue(Files.isDirectory(destination.resolve("directory1")));
@@ -86,9 +85,9 @@ public void testExtract_symlinks() throws URISyntaxException, IOException {
}
@Test
- public void testExtract_modificationTimePreserved() throws URISyntaxException, IOException {
+ void testExtract_modificationTimePreserved() throws URISyntaxException, IOException {
Path source = Paths.get(Resources.getResource("core/extract.tar").toURI());
- Path destination = temporaryFolder.getRoot().toPath();
+ Path destination = temporaryFolder;
TarExtractor.extract(source, destination);
@@ -105,11 +104,11 @@ public void testExtract_modificationTimePreserved() throws URISyntaxException, I
}
@Test
- public void testExtract_reproducibleTimestampsEnabled() throws URISyntaxException, IOException {
+ void testExtract_reproducibleTimestampsEnabled() throws URISyntaxException, IOException {
// The tarfile has only level1/level2/level3/file.txt packaged
Path source = Paths.get(Resources.getResource("core/tarfile-only-file-packaged.tar").toURI());
- Path destination = temporaryFolder.getRoot().toPath();
+ Path destination = temporaryFolder;
TarExtractor.extract(source, destination, true);
@@ -124,9 +123,9 @@ public void testExtract_reproducibleTimestampsEnabled() throws URISyntaxExceptio
}
@Test
- public void testExtract_reproducibleTimestampsEnabled_destinationNotEmpty() throws IOException {
- Path destination = temporaryFolder.getRoot().toPath();
- temporaryFolder.newFile();
+ void testExtract_reproducibleTimestampsEnabled_destinationNotEmpty() throws IOException {
+ Path destination = temporaryFolder;
+ Files.createTempFile(temporaryFolder, "jib", "test");
IllegalStateException exception =
assertThrows(
diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java
index 19066e29973..5fe76acb8e2 100644
--- a/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java
+++ b/jib-core/src/test/java/com/google/cloud/tools/jib/tar/TarStreamBuilderTest.java
@@ -37,11 +37,11 @@
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/** Tests for {@link TarStreamBuilder}. */
-public class TarStreamBuilderTest {
+class TarStreamBuilderTest {
private Path fileA;
private Path fileB;
@@ -50,8 +50,8 @@ public class TarStreamBuilderTest {
private byte[] fileBContents;
private final TarStreamBuilder testTarStreamBuilder = new TarStreamBuilder();
- @Before
- public void setup() throws URISyntaxException, IOException {
+ @BeforeEach
+ void setup() throws URISyntaxException, IOException {
// Gets the test resource files.
fileA = Paths.get(Resources.getResource("core/fileA").toURI());
fileB = Paths.get(Resources.getResource("core/fileB").toURI());
@@ -62,43 +62,43 @@ public void setup() throws URISyntaxException, IOException {
}
@Test
- public void testToBlob_tarArchiveEntries() throws IOException {
+ void testToBlob_tarArchiveEntries() throws IOException {
setUpWithTarEntries();
verifyBlobWithoutCompression();
}
@Test
- public void testToBlob_strings() throws IOException {
+ void testToBlob_strings() throws IOException {
setUpWithStrings();
verifyBlobWithoutCompression();
}
@Test
- public void testToBlob_stringsAndTarArchiveEntries() throws IOException {
+ void testToBlob_stringsAndTarArchiveEntries() throws IOException {
setUpWithStringsAndTarEntries();
verifyBlobWithoutCompression();
}
@Test
- public void testToBlob_tarArchiveEntriesWithCompression() throws IOException {
+ void testToBlob_tarArchiveEntriesWithCompression() throws IOException {
setUpWithTarEntries();
verifyBlobWithCompression();
}
@Test
- public void testToBlob_stringsWithCompression() throws IOException {
+ void testToBlob_stringsWithCompression() throws IOException {
setUpWithStrings();
verifyBlobWithCompression();
}
@Test
- public void testToBlob_stringsAndTarArchiveEntriesWithCompression() throws IOException {
+ void testToBlob_stringsAndTarArchiveEntriesWithCompression() throws IOException {
setUpWithStringsAndTarEntries();
verifyBlobWithCompression();
}
@Test
- public void testToBlob_multiByte() throws IOException {
+ void testToBlob_multiByte() throws IOException {
testTarStreamBuilder.addByteEntry(
"日本語".getBytes(StandardCharsets.UTF_8), "test", Instant.EPOCH);
testTarStreamBuilder.addByteEntry(
@@ -137,7 +137,7 @@ public void testToBlob_multiByte() throws IOException {
}
@Test
- public void testToBlob_modificationTime() throws IOException {
+ void testToBlob_modificationTime() throws IOException {
testTarStreamBuilder.addByteEntry(
"foo".getBytes(StandardCharsets.UTF_8), "foo", Instant.ofEpochSecond(1234));
testTarStreamBuilder.addBlobEntry(
diff --git a/jib-gradle-plugin-extension-api/build.gradle b/jib-gradle-plugin-extension-api/build.gradle
index 1478f301273..977be52bf14 100644
--- a/jib-gradle-plugin-extension-api/build.gradle
+++ b/jib-gradle-plugin-extension-api/build.gradle
@@ -44,7 +44,7 @@ publishing {
release {
tagTemplate = 'v$version-gradle-extension'
git {
- requireBranch = /^gradle-extension-release-v\d+.*$/ //regex
+ requireBranch.set(/^gradle-extension-release-v\d+.*$/) //regex
}
}
/* RELEASE */
diff --git a/jib-gradle-plugin/build.gradle b/jib-gradle-plugin/build.gradle
index 46f416ab1ed..4fca76e2658 100644
--- a/jib-gradle-plugin/build.gradle
+++ b/jib-gradle-plugin/build.gradle
@@ -32,20 +32,21 @@ dependencies {
implementation dependencyStrings.GRADLE_EXTENSION
- testImplementation dependencyStrings.JUNIT
+ testImplementation dependencyStrings.JUNIT_API
+ testRuntimeOnly dependencyStrings.JUNIT_ENGINE
testImplementation dependencyStrings.TRUTH
testImplementation dependencyStrings.TRUTH8
testImplementation dependencyStrings.MOCKITO_CORE
testImplementation dependencyStrings.SLF4J_API
testImplementation dependencyStrings.SYSTEM_RULES
-
+ testImplementation dependencyStrings.SYSTEM_RULES_STUB
testImplementation project(path:':jib-plugins-common', configuration:'tests')
integrationTestImplementation project(path:':jib-core', configuration:'integrationTests')
integrationTestImplementation dependencyStrings.JBCRYPT
// only for testing a concrete Spring Boot example in a test (not for test infrastructure)
- testImplementation 'org.springframework.boot:spring-boot-gradle-plugin:2.2.11.RELEASE'
+ testImplementation 'org.springframework.boot:spring-boot-gradle-plugin:2.7.13'
}
/* RELEASE */
@@ -57,17 +58,13 @@ release {
'com.google.cloud.tools:jib-plugins-common',
]
git {
- requireBranch = /^gradle-release-v\d+.*$/ //regex
+ requireBranch.set(/^gradle-release-v\d+.*$/) //regex
}
}
// Gradle Plugin Portal releases
-pluginBundle {
+gradlePlugin {
website = 'https://github.com/GoogleContainerTools/jib/'
vcsUrl = 'https://github.com/GoogleContainerTools/jib/'
- tags = ['google', 'java', 'containers', 'docker', 'kubernetes', 'microservices']
-}
-
-gradlePlugin {
testSourceSets sourceSets.integrationTest, sourceSets.test
plugins {
jibPlugin {
@@ -75,6 +72,7 @@ gradlePlugin {
displayName = 'Jib'
description = 'Containerize your Java application'
implementationClass = 'com.google.cloud.tools.jib.gradle.JibPlugin'
+ tags.set(['google', 'java', 'containers', 'docker', 'kubernetes', 'microservices'])
}
}
}
diff --git a/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/DefaultTargetProjectIntegrationTest.java b/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/DefaultTargetProjectIntegrationTest.java
index 8d78986bc9b..588b7ed75a1 100644
--- a/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/DefaultTargetProjectIntegrationTest.java
+++ b/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/DefaultTargetProjectIntegrationTest.java
@@ -18,19 +18,23 @@
import com.google.cloud.tools.jib.Command;
import java.io.IOException;
+import java.nio.file.Path;
import java.security.DigestException;
import org.gradle.testkit.runner.UnexpectedBuildFailure;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.Assert;
import org.junit.ClassRule;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
/** Integration tests for building "default-target" project images. */
-public class DefaultTargetProjectIntegrationTest {
+class DefaultTargetProjectIntegrationTest {
+
+ @TempDir Path tempDir;
@ClassRule
- public static final TestProject defaultTargetTestProject = new TestProject("default-target");
+ public final TestProject defaultTargetTestProject = new TestProject("default-target", tempDir);
/**
* Asserts that the test project has the required exposed ports, labels and volumes.
@@ -57,7 +61,7 @@ private static void assertDockerInspect(String imageReference)
}
@Test
- public void testBuild_defaultTarget() {
+ void testBuild_defaultTarget() {
// Test error when 'to' is missing
try {
defaultTargetTestProject.build(
@@ -74,8 +78,7 @@ public void testBuild_defaultTarget() {
}
@Test
- public void testDockerDaemon_defaultTarget()
- throws IOException, InterruptedException, DigestException {
+ void testDockerDaemon_defaultTarget() throws IOException, InterruptedException, DigestException {
Assert.assertEquals(
"Hello, world. An argument.\n",
JibRunHelper.buildToDockerDaemonAndRun(
diff --git a/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/EmptyProjectIntegrationTest.java b/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/EmptyProjectIntegrationTest.java
index b6398856056..6e983b3534d 100644
--- a/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/EmptyProjectIntegrationTest.java
+++ b/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/EmptyProjectIntegrationTest.java
@@ -22,18 +22,22 @@
import com.google.cloud.tools.jib.IntegrationTestingConfiguration;
import com.google.cloud.tools.jib.api.InvalidImageReferenceException;
import java.io.IOException;
+import java.nio.file.Path;
import java.security.DigestException;
import java.time.Instant;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.Assert;
import org.junit.ClassRule;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
/** Integration tests for building empty project images. */
-public class EmptyProjectIntegrationTest {
+class EmptyProjectIntegrationTest {
- @ClassRule public static final TestProject emptyTestProject = new TestProject("empty");
+ @TempDir Path tempDir;
+
+ @ClassRule public final TestProject emptyTestProject = new TestProject("empty", tempDir);
/**
* Asserts that the test project has the required exposed ports and labels.
@@ -59,7 +63,7 @@ private static void assertDockerInspect(String imageReference)
}
@Test
- public void testBuild_empty() throws IOException, InterruptedException, DigestException {
+ void testBuild_empty() throws IOException, InterruptedException, DigestException {
String targetImage =
IntegrationTestingConfiguration.getTestRepositoryLocation()
+ "/emptyimage:gradle"
@@ -70,7 +74,7 @@ public void testBuild_empty() throws IOException, InterruptedException, DigestEx
}
@Test
- public void testBuild_multipleTags()
+ void testBuild_multipleTags()
throws IOException, InterruptedException, InvalidImageReferenceException, DigestException {
String targetImage =
IntegrationTestingConfiguration.getTestRepositoryLocation()
@@ -82,7 +86,7 @@ public void testBuild_multipleTags()
}
@Test
- public void testDockerDaemon_empty() throws IOException, InterruptedException, DigestException {
+ void testDockerDaemon_empty() throws IOException, InterruptedException, DigestException {
String targetImage = "emptyimage:gradle" + System.nanoTime();
Assert.assertEquals(
"", JibRunHelper.buildToDockerDaemonAndRun(emptyTestProject, targetImage, "build.gradle"));
@@ -91,8 +95,7 @@ public void testDockerDaemon_empty() throws IOException, InterruptedException, D
}
@Test
- public void testDockerDaemon_userNumeric()
- throws IOException, InterruptedException, DigestException {
+ void testDockerDaemon_userNumeric() throws IOException, InterruptedException, DigestException {
String targetImage = "emptyimage:gradle" + System.nanoTime();
JibRunHelper.buildToDockerDaemon(emptyTestProject, targetImage, "build.gradle");
Assert.assertEquals(
@@ -101,8 +104,7 @@ public void testDockerDaemon_userNumeric()
}
@Test
- public void testDockerDaemon_userNames()
- throws IOException, InterruptedException, DigestException {
+ void testDockerDaemon_userNames() throws IOException, InterruptedException, DigestException {
String targetImage = "brokenuserimage:gradle" + System.nanoTime();
JibRunHelper.buildToDockerDaemon(emptyTestProject, targetImage, "build-broken-user.gradle");
Assert.assertEquals(
diff --git a/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/GradleLayerConfigurationIntegrationTest.java b/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/GradleLayerConfigurationIntegrationTest.java
index 8595883af52..92acee03185 100644
--- a/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/GradleLayerConfigurationIntegrationTest.java
+++ b/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/GradleLayerConfigurationIntegrationTest.java
@@ -27,17 +27,22 @@
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.junit.ClassRule;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
-public class GradleLayerConfigurationIntegrationTest {
+class GradleLayerConfigurationIntegrationTest {
+
+ @TempDir Path tempDir;
+
+ @TempDir Path tempDirSimple;
@ClassRule
- public static final TestProject multiTestProject = new TestProject("all-local-multi-service");
+ public final TestProject multiTestProject = new TestProject("all-local-multi-service", tempDir);
- @ClassRule public static final TestProject configTestProject = new TestProject("simple");
+ @ClassRule public final TestProject configTestProject = new TestProject("simple", tempDirSimple);
@Test
- public void testGradleLayerConfiguration_configurationName() throws IOException {
+ void testGradleLayerConfiguration_configurationName() throws IOException {
configTestProject.build("jibBuildTar", "-b=build-configuration.gradle");
Path jibTar = configTestProject.getProjectRoot().resolve("build/jib-image.tar");
List> layers = getLayers(jibTar);
@@ -54,7 +59,7 @@ public void testGradleLayerConfiguration_configurationName() throws IOException
}
@Test
- public void testGradleLayerConfiguration_configurationName_prioritizeSystemProperty()
+ void testGradleLayerConfiguration_configurationName_prioritizeSystemProperty()
throws IOException {
configTestProject.build(
"jibBuildTar",
@@ -76,7 +81,7 @@ public void testGradleLayerConfiguration_configurationName_prioritizeSystemPrope
}
@Test
- public void testGradleLayerConfiguration_multiModule() throws IOException {
+ void testGradleLayerConfiguration_multiModule() throws IOException {
multiTestProject.build(":complex-service:jibBuildTar");
Path jibTar = multiTestProject.getProjectRoot().resolve("complex-service/build/jib-image.tar");
@@ -133,7 +138,7 @@ public void testGradleLayerConfiguration_multiModule() throws IOException {
}
@Test
- public void testGradleLayerConfiguration_simpleModule() throws IOException {
+ void testGradleLayerConfiguration_simpleModule() throws IOException {
multiTestProject.build(":simple-service:jibBuildTar");
Path jibTar = multiTestProject.getProjectRoot().resolve("simple-service/build/jib-image.tar");
diff --git a/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/JibRunHelper.java b/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/JibRunHelper.java
index 70119236ed4..64f01f6a9be 100644
--- a/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/JibRunHelper.java
+++ b/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/JibRunHelper.java
@@ -39,7 +39,7 @@
import org.junit.Assert;
/** Helper class to run integration tests. */
-public class JibRunHelper {
+class JibRunHelper {
static String buildAndRun(TestProject testProject, String imageReference)
throws IOException, InterruptedException, DigestException {
@@ -70,8 +70,10 @@ static String buildAndRun(
static String buildAndRunFromLocalBase(String target, String base)
throws IOException, InterruptedException, DigestException {
+ SingleProjectIntegrationTest spi = new SingleProjectIntegrationTest();
+
BuildResult buildResult =
- SingleProjectIntegrationTest.simpleTestProject.build(
+ spi.simpleTestProject.build(
"clean",
"jib",
"-Djib.useOnlyProjectCache=true",
@@ -81,8 +83,7 @@ static String buildAndRunFromLocalBase(String target, String base)
"-Djib.allowInsecureRegistries=" + target.startsWith("localhost"),
"-b=" + "build-local-base.gradle");
assertBuildSuccess(buildResult, "jib", "Built and pushed image as ");
- assertThatExpectedImageDigestAndIdReturned(
- SingleProjectIntegrationTest.simpleTestProject.getProjectRoot());
+ assertThatExpectedImageDigestAndIdReturned(spi.simpleTestProject.getProjectRoot());
MatcherAssert.assertThat(buildResult.getOutput(), CoreMatchers.containsString(target));
return pullAndRunBuiltImage(target);
}
diff --git a/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/SingleProjectIntegrationTest.java b/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/SingleProjectIntegrationTest.java
index 7c53878dc50..2b85e582d87 100644
--- a/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/SingleProjectIntegrationTest.java
+++ b/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/SingleProjectIntegrationTest.java
@@ -41,12 +41,11 @@
import org.hamcrest.MatcherAssert;
import org.junit.Before;
import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
/** Integration tests for building single project images. */
-public class SingleProjectIntegrationTest {
+class SingleProjectIntegrationTest {
@ClassRule
public static final LocalRegistry localRegistry1 =
@@ -56,9 +55,9 @@ public class SingleProjectIntegrationTest {
public static final LocalRegistry localRegistry2 =
new LocalRegistry(6000, "testuser", "testpassword");
- @ClassRule public static final TestProject simpleTestProject = new TestProject("simple");
+ @TempDir Path tempDir;
- @Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder();
+ @ClassRule public final TestProject simpleTestProject = new TestProject("simple", tempDir);
private final String dockerHost =
System.getenv("DOCKER_IP") != null ? System.getenv("DOCKER_IP") : "localhost";
@@ -123,7 +122,7 @@ private static String readDigestFile(Path digestPath) throws IOException, Digest
return DescriptorDigest.fromDigest(digest).toString();
}
- private static String buildAndRunComplex(
+ private String buildAndRunComplex(
String imageReference, String username, String password, LocalRegistry targetRegistry)
throws IOException, InterruptedException {
Path baseCache = simpleTestProject.getProjectRoot().resolve("build/jib-base-cache");
@@ -166,13 +165,13 @@ private static String buildAndRunComplex(
}
@Before
- public void setup() throws IOException, InterruptedException {
+ void setup() throws IOException, InterruptedException {
// Pull distroless and push to local registry so we can test 'from' credentials
localRegistry1.pullAndPushToLocal("gcr.io/distroless/java:latest", "distroless/java");
}
@Test
- public void testBuild_simple()
+ void testBuild_simple()
throws IOException, InterruptedException, DigestException, InvalidImageReferenceException {
String targetImage =
IntegrationTestingConfiguration.getTestRepositoryLocation()
@@ -227,8 +226,7 @@ public void testBuild_simple()
}
@Test
- public void testBuild_dockerDaemonBase()
- throws IOException, InterruptedException, DigestException {
+ void testBuild_dockerDaemonBase() throws IOException, InterruptedException, DigestException {
String targetImage =
IntegrationTestingConfiguration.getTestRepositoryLocation()
+ "/simplewithdockerdaemonbase:gradle"
@@ -250,8 +248,8 @@ public void testBuild_dockerDaemonBase()
}
@Test
- public void testBuild_tarBase() throws IOException, InterruptedException, DigestException {
- Path path = temporaryFolder.getRoot().toPath().resolve("docker-save-distroless");
+ void testBuild_tarBase() throws IOException, InterruptedException, DigestException {
+ Path path = tempDir.resolve("docker-save-distroless");
new Command("docker", "save", "gcr.io/distroless/java:latest", "-o", path.toString()).run();
String targetImage =
IntegrationTestingConfiguration.getTestRepositoryLocation()
@@ -272,7 +270,7 @@ public void testBuild_tarBase() throws IOException, InterruptedException, Digest
}
@Test
- public void testBuild_failOffline() {
+ void testBuild_failOffline() {
String targetImage =
IntegrationTestingConfiguration.getTestRepositoryLocation()
+ "/simpleimageoffline:gradle"
@@ -295,8 +293,7 @@ public void testBuild_failOffline() {
}
@Test
- public void testDockerDaemon_simpleOnJava17()
- throws DigestException, IOException, InterruptedException {
+ void testDockerDaemon_simpleOnJava17() throws DigestException, IOException, InterruptedException {
assumeTrue(isJavaRuntimeAtLeast(17));
String targetImage = "simpleimage:gradle" + System.nanoTime();
@@ -309,8 +306,7 @@ public void testDockerDaemon_simpleOnJava17()
}
@Test
- public void testDockerDaemon_simpleOnJava11()
- throws DigestException, IOException, InterruptedException {
+ void testDockerDaemon_simpleOnJava11() throws DigestException, IOException, InterruptedException {
assumeTrue(isJavaRuntimeAtLeast(11));
String targetImage = "simpleimage:gradle" + System.nanoTime();
@@ -323,7 +319,7 @@ public void testDockerDaemon_simpleOnJava11()
}
@Test
- public void testDockerDaemon_simpleWithIncompatibleJava11() {
+ void testDockerDaemon_simpleWithIncompatibleJava11() {
assumeTrue(isJavaRuntimeAtLeast(11));
Exception exception =
@@ -341,7 +337,7 @@ public void testDockerDaemon_simpleWithIncompatibleJava11() {
}
@Test
- public void testDockerDaemon_simple_multipleExtraDirectories()
+ void testDockerDaemon_simple_multipleExtraDirectories()
throws DigestException, IOException, InterruptedException {
String targetImage = "simpleimage:gradle" + System.nanoTime();
String output =
@@ -362,7 +358,7 @@ public void testDockerDaemon_simple_multipleExtraDirectories()
}
@Test
- public void testDockerDaemon_simple_multipleExtraDirectoriesWithAlternativeConfig()
+ void testDockerDaemon_simple_multipleExtraDirectoriesWithAlternativeConfig()
throws DigestException, IOException, InterruptedException {
String targetImage = "simpleimage:gradle" + System.nanoTime();
String output =
@@ -383,7 +379,7 @@ public void testDockerDaemon_simple_multipleExtraDirectoriesWithAlternativeConfi
}
@Test
- public void testDockerDaemon_simple_multipleExtraDirectoriesWithClosure()
+ void testDockerDaemon_simple_multipleExtraDirectoriesWithClosure()
throws DigestException, IOException, InterruptedException {
String targetImage = "simpleimage:gradle" + System.nanoTime();
String output =
@@ -406,7 +402,7 @@ public void testDockerDaemon_simple_multipleExtraDirectoriesWithClosure()
}
@Test
- public void testDockerDaemon_simple_extraDirectoriesFiltering()
+ void testDockerDaemon_simple_extraDirectoriesFiltering()
throws DigestException, IOException, InterruptedException {
String targetImage = "simpleimage:gradle" + System.nanoTime();
JibRunHelper.buildToDockerDaemon(
@@ -423,7 +419,7 @@ public void testDockerDaemon_simple_extraDirectoriesFiltering()
}
@Test
- public void testBuild_complex()
+ void testBuild_complex()
throws IOException, InterruptedException, DigestException, InvalidImageReferenceException {
String targetImage = dockerHost + ":6000/compleximage:gradle" + System.nanoTime();
Instant beforeBuild = Instant.now();
@@ -448,7 +444,7 @@ public void testBuild_complex()
}
@Test
- public void testBuild_complex_sameFromAndToRegistry() throws IOException, InterruptedException {
+ void testBuild_complex_sameFromAndToRegistry() throws IOException, InterruptedException {
String targetImage = dockerHost + ":5000/compleximage:gradle" + System.nanoTime();
Instant beforeBuild = Instant.now();
buildAndRunComplex(targetImage, "testuser", "testpassword", localRegistry1);
@@ -457,7 +453,7 @@ public void testBuild_complex_sameFromAndToRegistry() throws IOException, Interr
}
@Test
- public void testDockerDaemon_simple() throws IOException, InterruptedException, DigestException {
+ void testDockerDaemon_simple() throws IOException, InterruptedException, DigestException {
String targetImage = "simpleimage:gradle" + System.nanoTime();
String output =
JibRunHelper.buildToDockerDaemonAndRun(simpleTestProject, targetImage, "build.gradle");
@@ -478,7 +474,7 @@ public void testDockerDaemon_simple() throws IOException, InterruptedException,
}
@Test
- public void testDockerDaemon_jarContainerization()
+ void testDockerDaemon_jarContainerization()
throws DigestException, IOException, InterruptedException {
String targetImage = "simpleimage:gradle" + System.nanoTime();
String output =
@@ -490,7 +486,7 @@ public void testDockerDaemon_jarContainerization()
}
@Test
- public void testBuild_skipDownloadingBaseImageLayers() throws IOException, InterruptedException {
+ void testBuild_skipDownloadingBaseImageLayers() throws IOException, InterruptedException {
Path baseLayersCacheDirectory =
simpleTestProject.getProjectRoot().resolve("build/jib-base-cache/layers");
String targetImage = dockerHost + ":6000/simpleimage:gradle" + System.nanoTime();
@@ -506,7 +502,7 @@ public void testBuild_skipDownloadingBaseImageLayers() throws IOException, Inter
}
@Test
- public void testDockerDaemon_timestampCustom()
+ void testDockerDaemon_timestampCustom()
throws DigestException, IOException, InterruptedException {
String targetImage = "simpleimage:gradle" + System.nanoTime();
String output =
@@ -520,7 +516,7 @@ public void testDockerDaemon_timestampCustom()
}
@Test
- public void testBuild_dockerClient() throws IOException, InterruptedException, DigestException {
+ void testBuild_dockerClient() throws IOException, InterruptedException, DigestException {
assumeFalse(System.getProperty("os.name").startsWith("Windows"));
new Command(
"chmod", "+x", simpleTestProject.getProjectRoot().resolve("mock-docker.sh").toString())
@@ -545,7 +541,7 @@ public void testBuild_dockerClient() throws IOException, InterruptedException, D
}
@Test
- public void testBuildTar_simple() throws IOException, InterruptedException {
+ void testBuildTar_simple() throws IOException, InterruptedException {
String targetImage = "simpleimage:gradle" + System.nanoTime();
String outputPath =
@@ -584,8 +580,7 @@ public void testBuildTar_simple() throws IOException, InterruptedException {
}
@Test
- public void testCredHelperConfiguration()
- throws DigestException, IOException, InterruptedException {
+ void testCredHelperConfiguration() throws DigestException, IOException, InterruptedException {
String targetImage = "simpleimage:gradle" + System.nanoTime();
assertThat(
JibRunHelper.buildToDockerDaemonAndRun(
diff --git a/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/SpringBootProjectIntegrationTest.java b/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/SpringBootProjectIntegrationTest.java
index dca766587b4..cbe97b3c32d 100644
--- a/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/SpringBootProjectIntegrationTest.java
+++ b/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/SpringBootProjectIntegrationTest.java
@@ -21,29 +21,33 @@
import com.google.cloud.tools.jib.api.HttpRequestTester;
import java.io.IOException;
import java.net.URL;
+import java.nio.file.Path;
import java.security.DigestException;
import javax.annotation.Nullable;
import org.junit.After;
import org.junit.Assert;
import org.junit.ClassRule;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
/** Integration tests for building Spring Boot images. */
-public class SpringBootProjectIntegrationTest {
+class SpringBootProjectIntegrationTest {
- @ClassRule public static final TestProject springBootProject = new TestProject("spring-boot");
+ @TempDir Path tempDir;
+
+ @ClassRule public final TestProject springBootProject = new TestProject("spring-boot", tempDir);
@Nullable private String containerName;
@After
- public void tearDown() throws IOException, InterruptedException {
+ void tearDown() throws IOException, InterruptedException {
if (containerName != null) {
new Command("docker", "stop", containerName).run();
}
}
@Test
- public void testBuild_packagedMode() throws IOException, InterruptedException, DigestException {
+ void testBuild_packagedMode() throws IOException, InterruptedException, DigestException {
buildAndRunWebApp("springboot:gradle", "build.gradle");
String output =
diff --git a/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/WarProjectIntegrationTest.java b/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/WarProjectIntegrationTest.java
index dbcf72940ba..650c7cee5c4 100644
--- a/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/WarProjectIntegrationTest.java
+++ b/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/WarProjectIntegrationTest.java
@@ -21,34 +21,37 @@
import com.google.cloud.tools.jib.api.HttpRequestTester;
import java.io.IOException;
import java.net.URL;
+import java.nio.file.Path;
import java.security.DigestException;
import javax.annotation.Nullable;
import org.junit.After;
import org.junit.ClassRule;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
/** Integration tests for building WAR images. */
-public class WarProjectIntegrationTest {
+class WarProjectIntegrationTest {
- @ClassRule public static final TestProject servlet25Project = new TestProject("war_servlet25");
+ @TempDir Path tempDir;
+
+ @ClassRule public final TestProject servlet25Project = new TestProject("war_servlet25", tempDir);
@Nullable private String containerName;
@After
- public void tearDown() throws IOException, InterruptedException {
+ void tearDown() throws IOException, InterruptedException {
if (containerName != null) {
new Command("docker", "stop", containerName).run();
}
}
@Test
- public void testBuild_jettyServlet25() throws IOException, InterruptedException, DigestException {
+ void testBuild_jettyServlet25() throws IOException, InterruptedException, DigestException {
verifyBuildAndRun(servlet25Project, "war_jetty_servlet25:gradle", "build.gradle");
}
@Test
- public void testBuild_tomcatServlet25()
- throws IOException, InterruptedException, DigestException {
+ void testBuild_tomcatServlet25() throws IOException, InterruptedException, DigestException {
verifyBuildAndRun(servlet25Project, "war_tomcat_servlet25:gradle", "build-tomcat.gradle");
}
diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BuildDockerTask.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BuildDockerTask.java
index 692449db037..86f29eef12d 100644
--- a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BuildDockerTask.java
+++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BuildDockerTask.java
@@ -44,6 +44,7 @@
import javax.annotation.Nullable;
import org.gradle.api.DefaultTask;
import org.gradle.api.GradleException;
+import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.Nested;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.options.Option;
@@ -54,6 +55,7 @@ public class BuildDockerTask extends DefaultTask implements JibTask {
private static final String HELPFUL_SUGGESTIONS_PREFIX = "Build to Docker daemon failed";
@Nullable private JibExtension jibExtension;
+ @Nullable private GradleProjectProperties projectProperties;
/**
* This will call the property {@code "jib"} so that it is the same name as the extension. This
@@ -63,10 +65,17 @@ public class BuildDockerTask extends DefaultTask implements JibTask {
*/
@Nested
@Nullable
+ @SuppressWarnings("java:S106")
public JibExtension getJib() {
return jibExtension;
}
+ @Nullable
+ @Internal
+ public GradleProjectProperties getProjectProperties() {
+ return projectProperties;
+ }
+
/**
* The target image can be overridden with the {@code --image} command line option.
*
@@ -91,6 +100,7 @@ public void buildDocker()
throws IOException, BuildStepsExecutionException, CacheDirectoryCreationException,
MainClassInferenceException, InvalidGlobalConfigException {
Preconditions.checkNotNull(jibExtension);
+ Preconditions.checkNotNull(projectProperties);
// Check deprecated parameters
Path dockerExecutable = jibExtension.getDockerClient().getExecutablePath();
@@ -104,23 +114,16 @@ public void buildDocker()
}
TaskCommon.disableHttpLogging();
- TempDirectoryProvider tempDirectoryProvider = new TempDirectoryProvider();
- GradleProjectProperties projectProperties =
- GradleProjectProperties.getForProject(
- getProject(),
- getLogger(),
- tempDirectoryProvider,
- jibExtension.getConfigurationName().get());
GlobalConfig globalConfig = GlobalConfig.readConfig();
Future> updateCheckFuture =
- TaskCommon.newUpdateChecker(projectProperties, globalConfig, getLogger());
- try {
+ TaskCommon.newUpdateChecker(this.projectProperties, globalConfig, getLogger());
+ try (TempDirectoryProvider tempDirectoryProvider = new TempDirectoryProvider()) {
PluginConfigurationProcessor.createJibBuildRunnerForDockerDaemonImage(
new GradleRawConfiguration(jibExtension),
ignored -> java.util.Optional.empty(),
- projectProperties,
+ this.projectProperties,
globalConfig,
new GradleHelpfulSuggestions(HELPFUL_SUGGESTIONS_PREFIX))
.runBuild();
@@ -187,8 +190,7 @@ public void buildDocker()
+ ex.getPath(),
ex);
} finally {
- tempDirectoryProvider.close();
- TaskCommon.finishUpdateChecker(projectProperties, updateCheckFuture);
+ TaskCommon.finishUpdateChecker(this.projectProperties, updateCheckFuture);
projectProperties.waitForLoggingThread();
}
}
@@ -196,6 +198,12 @@ public void buildDocker()
@Override
public BuildDockerTask setJibExtension(JibExtension jibExtension) {
this.jibExtension = jibExtension;
+ this.projectProperties =
+ GradleProjectProperties.getForProject(
+ getProject(),
+ getLogger(),
+ new TempDirectoryProvider(),
+ jibExtension.getConfigurationName().get());
return this;
}
}
diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BuildImageTask.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BuildImageTask.java
index 49265559a61..2aef54bbef4 100644
--- a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BuildImageTask.java
+++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BuildImageTask.java
@@ -43,6 +43,7 @@
import javax.annotation.Nullable;
import org.gradle.api.DefaultTask;
import org.gradle.api.GradleException;
+import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.Nested;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.options.Option;
@@ -54,6 +55,8 @@ public class BuildImageTask extends DefaultTask implements JibTask {
@Nullable private JibExtension jibExtension;
+ @Nullable private GradleProjectProperties projectProperties;
+
/**
* This will call the property {@code "jib"} so that it is the same name as the extension. This
* way, the user would see error messages for missing configuration with the prefix {@code jib.}.
@@ -66,6 +69,12 @@ public JibExtension getJib() {
return jibExtension;
}
+ @Nullable
+ @Internal
+ public GradleProjectProperties getProjectProperties() {
+ return projectProperties;
+ }
+
/**
* The target image can be overridden with the {@code --image} command line option.
*
@@ -91,15 +100,9 @@ public void buildImage()
MainClassInferenceException, InvalidGlobalConfigException {
// Asserts required @Input parameters are not null.
Preconditions.checkNotNull(jibExtension);
+ Preconditions.checkNotNull(projectProperties);
TaskCommon.disableHttpLogging();
- TempDirectoryProvider tempDirectoryProvider = new TempDirectoryProvider();
- GradleProjectProperties projectProperties =
- GradleProjectProperties.getForProject(
- getProject(),
- getLogger(),
- tempDirectoryProvider,
- jibExtension.getConfigurationName().get());
GlobalConfig globalConfig = GlobalConfig.readConfig();
Future> updateCheckFuture =
TaskCommon.newUpdateChecker(projectProperties, globalConfig, getLogger());
@@ -182,15 +185,28 @@ public void buildImage()
+ ex.getPath(),
ex);
} finally {
- tempDirectoryProvider.close();
- TaskCommon.finishUpdateChecker(projectProperties, updateCheckFuture);
- projectProperties.waitForLoggingThread();
+
+ if (projectProperties != null) {
+ TempDirectoryProvider tempDirectoryProvider = projectProperties.getTempDirectoryProvider();
+ if (tempDirectoryProvider != null) {
+ tempDirectoryProvider.close();
+ }
+ TaskCommon.finishUpdateChecker(projectProperties, updateCheckFuture);
+ projectProperties.waitForLoggingThread();
+ }
}
}
@Override
public BuildImageTask setJibExtension(JibExtension jibExtension) {
this.jibExtension = jibExtension;
+ this.projectProperties =
+ GradleProjectProperties.getForProject(
+ getProject(),
+ getLogger(),
+ new TempDirectoryProvider(),
+ jibExtension.getConfigurationName().get());
+
return this;
}
}
diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BuildTarTask.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BuildTarTask.java
index 1a77856b6b0..4f4219da378 100644
--- a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BuildTarTask.java
+++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BuildTarTask.java
@@ -47,6 +47,7 @@
import org.gradle.api.GradleException;
import org.gradle.api.file.FileCollection;
import org.gradle.api.tasks.InputFiles;
+import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.Nested;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;
@@ -71,6 +72,8 @@ public JibExtension getJib() {
return jibExtension;
}
+ @Nullable private GradleProjectProperties projectProperties;
+
/**
* The target image can be overridden with the {@code --image} command line option.
*
@@ -81,6 +84,12 @@ public void setTargetImage(String targetImage) {
Preconditions.checkNotNull(jibExtension).getTo().setImage(targetImage);
}
+ @Nullable
+ @Internal
+ public GradleProjectProperties getProjectProperties() {
+ return projectProperties;
+ }
+
/**
* Returns a collection of all the files that jib includes in the image. Only used to calculate
* UP-TO-DATE.
@@ -122,23 +131,19 @@ public void buildTar()
MainClassInferenceException, InvalidGlobalConfigException {
// Asserts required @Input parameters are not null.
Preconditions.checkNotNull(jibExtension);
+ Preconditions.checkNotNull(projectProperties);
TaskCommon.disableHttpLogging();
- TempDirectoryProvider tempDirectoryProvider = new TempDirectoryProvider();
- GradleProjectProperties projectProperties =
- GradleProjectProperties.getForProject(
- getProject(),
- getLogger(),
- tempDirectoryProvider,
- jibExtension.getConfigurationName().get());
GlobalConfig globalConfig = GlobalConfig.readConfig();
Future> updateCheckFuture =
- TaskCommon.newUpdateChecker(projectProperties, globalConfig, getLogger());
- try {
+ TaskCommon.newUpdateChecker(this.projectProperties, globalConfig, getLogger());
+
+ try (TempDirectoryProvider tempDirectoryProvider = new TempDirectoryProvider()) {
+
PluginConfigurationProcessor.createJibBuildRunnerForTarImage(
new GradleRawConfiguration(jibExtension),
ignored -> Optional.empty(),
- projectProperties,
+ this.projectProperties,
globalConfig,
new GradleHelpfulSuggestions(HELPFUL_SUGGESTIONS_PREFIX))
.runBuild();
@@ -204,7 +209,6 @@ public void buildTar()
+ ex.getPath(),
ex);
} finally {
- tempDirectoryProvider.close();
TaskCommon.finishUpdateChecker(projectProperties, updateCheckFuture);
projectProperties.waitForLoggingThread();
}
@@ -213,6 +217,12 @@ public void buildTar()
@Override
public BuildTarTask setJibExtension(JibExtension jibExtension) {
this.jibExtension = jibExtension;
+ this.projectProperties =
+ GradleProjectProperties.getForProject(
+ getProject(),
+ getLogger(),
+ new TempDirectoryProvider(),
+ jibExtension.getConfigurationName().get());
return this;
}
}
diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/ExtraDirectoriesParameters.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/ExtraDirectoriesParameters.java
index 30dc526e89b..c74ea7e8894 100644
--- a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/ExtraDirectoriesParameters.java
+++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/ExtraDirectoriesParameters.java
@@ -19,6 +19,7 @@
import com.google.cloud.tools.jib.plugins.common.ConfigurationPropertyValidator;
import com.google.cloud.tools.jib.plugins.common.PropertyNames;
import java.io.File;
+import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.List;
@@ -33,14 +34,15 @@
import org.gradle.api.provider.MapProperty;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.Input;
-import org.gradle.api.tasks.Internal;
+import org.gradle.api.tasks.Nested;
+import org.gradle.api.tasks.Optional;
/** Object in {@link JibExtension} that configures the extra directories. */
public class ExtraDirectoriesParameters {
private final ObjectFactory objects;
- private final Project project;
-
+ private final Path projectPath;
+ private final Provider extraDirPaths;
private ListProperty paths;
private ExtraDirectoryParametersSpec spec;
private MapProperty permissions;
@@ -48,10 +50,12 @@ public class ExtraDirectoriesParameters {
@Inject
public ExtraDirectoriesParameters(ObjectFactory objects, Project project) {
this.objects = objects;
- this.project = project;
paths = objects.listProperty(ExtraDirectoryParameters.class).empty();
spec = objects.newInstance(ExtraDirectoryParametersSpec.class, project, paths);
permissions = objects.mapProperty(String.class, String.class).empty();
+ this.projectPath = project.getProjectDir().toPath();
+ this.extraDirPaths =
+ project.getProviders().systemProperty(PropertyNames.EXTRA_DIRECTORIES_PATHS);
}
public void paths(Action super ExtraDirectoryParametersSpec> action) {
@@ -59,32 +63,26 @@ public void paths(Action super ExtraDirectoryParametersSpec> action) {
}
@Input
- public List getPathStrings() {
- // Gradle warns about @Input annotations on File objects, so we have to expose a getter for a
- // String to make them go away.
- return getPaths().stream()
- .map(extraDirectoryParameters -> extraDirectoryParameters.getFrom().toString())
- .collect(Collectors.toList());
+ @Optional
+ public Provider getExtraDirPaths() {
+ return extraDirPaths;
}
- @Internal
+ @Nested
public List getPaths() {
// Gradle warns about @Input annotations on File objects, so we have to expose a getter for a
// String to make them go away.
- String property = System.getProperty(PropertyNames.EXTRA_DIRECTORIES_PATHS);
- if (property != null) {
- List pathStrings = ConfigurationPropertyValidator.parseListProperty(property);
+ if (this.extraDirPaths.isPresent()) {
+ List pathStrings =
+ ConfigurationPropertyValidator.parseListProperty(this.extraDirPaths.get());
return pathStrings.stream()
- .map(path -> new ExtraDirectoryParameters(objects, project, Paths.get(path), "/"))
+ .map(path -> new ExtraDirectoryParameters(objects, Paths.get(path), "/"))
.collect(Collectors.toList());
}
if (paths.get().isEmpty()) {
return Collections.singletonList(
new ExtraDirectoryParameters(
- objects,
- project,
- project.getProjectDir().toPath().resolve("src").resolve("main").resolve("jib"),
- "/"));
+ objects, projectPath.resolve("src").resolve("main").resolve("jib"), "/"));
}
return paths.get();
}
@@ -115,8 +113,8 @@ public void setPaths(Provider