2020import java .io .IOException ;
2121import java .io .PrintStream ;
2222import java .net .URI ;
23+ import java .util .Objects ;
2324
25+ import org .jspecify .annotations .Nullable ;
2426import org .junit .jupiter .api .Test ;
2527import org .mockito .ArgumentCaptor ;
2628import org .mockito .stubbing .Answer ;
@@ -77,6 +79,7 @@ class BuilderTests {
7779 private static final ImageReference BASE_CNB = ImageReference .of ("docker.io/cloudfoundry/run:base-cnb" );
7880
7981 @ Test
82+ @ SuppressWarnings ("NullAway" ) // Test null check
8083 void createWhenLogIsNullThrowsException () {
8184 assertThatIllegalArgumentException ().isThrownBy (() -> new Builder ((BuildLog ) null ))
8285 .withMessage ("'log' must not be null" );
@@ -106,6 +109,7 @@ void createDockerApiWithLogDockerSystemOutDelegate() {
106109 }
107110
108111 @ Test
112+ @ SuppressWarnings ("NullAway" ) // Test null check
109113 void buildWhenRequestIsNullThrowsException () {
110114 Builder builder = new Builder ();
111115 assertThatIllegalArgumentException ().isThrownBy (() -> builder .build (null ))
@@ -131,7 +135,9 @@ void buildInvokesBuilder() throws Exception {
131135 then (docker .image ()).should ().pull (eq (DEFAULT_BUILDER ), isNull (), any (), isNull ());
132136 then (docker .image ()).should ().pull (eq (BASE_CNB ), eq (ImagePlatform .from (builderImage )), any (), isNull ());
133137 then (docker .image ()).should ().load (archive .capture (), any ());
134- then (docker .image ()).should ().remove (archive .getValue ().getTag (), true );
138+ ImageReference tag = archive .getValue ().getTag ();
139+ assertThat (tag ).isNotNull ();
140+ then (docker .image ()).should ().remove (tag , true );
135141 then (docker .image ()).shouldHaveNoMoreInteractions ();
136142 }
137143
@@ -161,7 +167,9 @@ void buildInvokesBuilderAndPublishesImage() throws Exception {
161167 .pull (eq (BASE_CNB ), eq (ImagePlatform .from (builderImage )), any (), regAuthEq (builderToken ));
162168 then (docker .image ()).should ().push (eq (request .getName ()), any (), regAuthEq (publishToken ));
163169 then (docker .image ()).should ().load (archive .capture (), any ());
164- then (docker .image ()).should ().remove (archive .getValue ().getTag (), true );
170+ ImageReference tag = archive .getValue ().getTag ();
171+ assertThat (tag ).isNotNull ();
172+ then (docker .image ()).should ().remove (tag , true );
165173 then (docker .image ()).shouldHaveNoMoreInteractions ();
166174 }
167175
@@ -184,7 +192,9 @@ void buildInvokesBuilderWithDefaultImageTags() throws Exception {
184192 assertThat (out .toString ()).contains ("Successfully built image 'docker.io/library/my-application:latest'" );
185193 ArgumentCaptor <ImageArchive > archive = ArgumentCaptor .forClass (ImageArchive .class );
186194 then (docker .image ()).should ().load (archive .capture (), any ());
187- then (docker .image ()).should ().remove (archive .getValue ().getTag (), true );
195+ ImageReference tag = archive .getValue ().getTag ();
196+ assertThat (tag ).isNotNull ();
197+ then (docker .image ()).should ().remove (tag , true );
188198 }
189199
190200 @ Test
@@ -207,7 +217,9 @@ void buildInvokesBuilderWithRunImageInDigestForm() throws Exception {
207217 assertThat (out .toString ()).contains ("Successfully built image 'docker.io/library/my-application:latest'" );
208218 ArgumentCaptor <ImageArchive > archive = ArgumentCaptor .forClass (ImageArchive .class );
209219 then (docker .image ()).should ().load (archive .capture (), any ());
210- then (docker .image ()).should ().remove (archive .getValue ().getTag (), true );
220+ ImageReference tag = archive .getValue ().getTag ();
221+ assertThat (tag ).isNotNull ();
222+ then (docker .image ()).should ().remove (tag , true );
211223 }
212224
213225 @ Test
@@ -227,7 +239,9 @@ void buildInvokesBuilderWithNoStack() throws Exception {
227239 assertThat (out .toString ()).contains ("Successfully built image 'docker.io/library/my-application:latest'" );
228240 ArgumentCaptor <ImageArchive > archive = ArgumentCaptor .forClass (ImageArchive .class );
229241 then (docker .image ()).should ().load (archive .capture (), any ());
230- then (docker .image ()).should ().remove (archive .getValue ().getTag (), true );
242+ ImageReference tag = archive .getValue ().getTag ();
243+ assertThat (tag ).isNotNull ();
244+ then (docker .image ()).should ().remove (tag , true );
231245 }
232246
233247 @ Test
@@ -249,7 +263,9 @@ void buildInvokesBuilderWithRunImageFromRequest() throws Exception {
249263 assertThat (out .toString ()).contains ("Successfully built image 'docker.io/library/my-application:latest'" );
250264 ArgumentCaptor <ImageArchive > archive = ArgumentCaptor .forClass (ImageArchive .class );
251265 then (docker .image ()).should ().load (archive .capture (), any ());
252- then (docker .image ()).should ().remove (archive .getValue ().getTag (), true );
266+ ImageReference tag = archive .getValue ().getTag ();
267+ assertThat (tag ).isNotNull ();
268+ then (docker .image ()).should ().remove (tag , true );
253269 }
254270
255271 @ Test
@@ -271,7 +287,9 @@ void buildInvokesBuilderWithNeverPullPolicy() throws Exception {
271287 assertThat (out .toString ()).contains ("Successfully built image 'docker.io/library/my-application:latest'" );
272288 ArgumentCaptor <ImageArchive > archive = ArgumentCaptor .forClass (ImageArchive .class );
273289 then (docker .image ()).should ().load (archive .capture (), any ());
274- then (docker .image ()).should ().remove (archive .getValue ().getTag (), true );
290+ ImageReference tag = archive .getValue ().getTag ();
291+ assertThat (tag ).isNotNull ();
292+ then (docker .image ()).should ().remove (tag , true );
275293 then (docker .image ()).should (never ()).pull (any (), any (), any ());
276294 then (docker .image ()).should (times (2 )).inspect (any ());
277295 }
@@ -295,7 +313,9 @@ void buildInvokesBuilderWithAlwaysPullPolicy() throws Exception {
295313 assertThat (out .toString ()).contains ("Successfully built image 'docker.io/library/my-application:latest'" );
296314 ArgumentCaptor <ImageArchive > archive = ArgumentCaptor .forClass (ImageArchive .class );
297315 then (docker .image ()).should ().load (archive .capture (), any ());
298- then (docker .image ()).should ().remove (archive .getValue ().getTag (), true );
316+ ImageReference tag = archive .getValue ().getTag ();
317+ assertThat (tag ).isNotNull ();
318+ then (docker .image ()).should ().remove (tag , true );
299319 then (docker .image ()).should (times (2 )).pull (any (), any (), any (), isNull ());
300320 then (docker .image ()).should (never ()).inspect (any ());
301321 }
@@ -325,7 +345,9 @@ void buildInvokesBuilderWithIfNotPresentPullPolicy() throws Exception {
325345 assertThat (out .toString ()).contains ("Successfully built image 'docker.io/library/my-application:latest'" );
326346 ArgumentCaptor <ImageArchive > archive = ArgumentCaptor .forClass (ImageArchive .class );
327347 then (docker .image ()).should ().load (archive .capture (), any ());
328- then (docker .image ()).should ().remove (archive .getValue ().getTag (), true );
348+ ImageReference tag = archive .getValue ().getTag ();
349+ assertThat (tag ).isNotNull ();
350+ then (docker .image ()).should ().remove (tag , true );
329351 then (docker .image ()).should (times (2 )).inspect (any ());
330352 then (docker .image ()).should (times (2 )).pull (any (), any (), any (), isNull ());
331353 }
@@ -349,7 +371,9 @@ void buildInvokesBuilderWithTags() throws Exception {
349371 then (docker .image ()).should ().tag (eq (request .getName ()), eq (ImageReference .of ("my-application:1.2.3" )));
350372 ArgumentCaptor <ImageArchive > archive = ArgumentCaptor .forClass (ImageArchive .class );
351373 then (docker .image ()).should ().load (archive .capture (), any ());
352- then (docker .image ()).should ().remove (archive .getValue ().getTag (), true );
374+ ImageReference tag = archive .getValue ().getTag ();
375+ assertThat (tag ).isNotNull ();
376+ then (docker .image ()).should ().remove (tag , true );
353377 }
354378
355379 @ Test
@@ -385,7 +409,9 @@ void buildInvokesBuilderWithTagsAndPublishesImageAndTags() throws Exception {
385409 then (docker .image ()).should ().push (eq (builtImageReference ), any (), regAuthEq (publishToken ));
386410 ArgumentCaptor <ImageArchive > archive = ArgumentCaptor .forClass (ImageArchive .class );
387411 then (docker .image ()).should ().load (archive .capture (), any ());
388- then (docker .image ()).should ().remove (archive .getValue ().getTag (), true );
412+ ImageReference tag = archive .getValue ().getTag ();
413+ assertThat (tag ).isNotNull ();
414+ then (docker .image ()).should ().remove (tag , true );
389415 then (docker .image ()).shouldHaveNoMoreInteractions ();
390416 }
391417
@@ -408,7 +434,9 @@ void buildInvokesBuilderWithPlatform() throws Exception {
408434 then (docker .image ()).should ().pull (eq (DEFAULT_BUILDER ), eq (platform ), any (), isNull ());
409435 then (docker .image ()).should ().pull (eq (BASE_CNB ), eq (platform ), any (), isNull ());
410436 then (docker .image ()).should ().load (archive .capture (), any ());
411- then (docker .image ()).should ().remove (archive .getValue ().getTag (), true );
437+ ImageReference tag = archive .getValue ().getTag ();
438+ assertThat (tag ).isNotNull ();
439+ then (docker .image ()).should ().remove (tag , true );
412440 then (docker .image ()).shouldHaveNoMoreInteractions ();
413441 }
414442
@@ -483,7 +511,7 @@ private DockerApi mockDockerApi() throws IOException {
483511 return mockDockerApi (null );
484512 }
485513
486- private DockerApi mockDockerApi (ImagePlatform platform ) throws IOException {
514+ private DockerApi mockDockerApi (@ Nullable ImagePlatform platform ) throws IOException {
487515 ContainerApi containerApi = mock (ContainerApi .class );
488516 ContainerReference reference = ContainerReference .of ("container-ref" );
489517 given (containerApi .create (any (), eq (platform ), any ())).willReturn (reference );
@@ -531,7 +559,7 @@ private Answer<Image> withPulledImage(Image image) {
531559 }
532560
533561 private static String regAuthEq (DockerRegistryAuthentication authentication ) {
534- return argThat (authentication .getAuthHeader ():: equals );
562+ return argThat (( arg ) -> Objects . equals ( authentication .getAuthHeader (), arg ) );
535563 }
536564
537565 static class TestPrintStream extends PrintStream {
0 commit comments