Repository: GoogleContainerTools/jib
File: jib-core/src/test/java/com/google/cloud/tools/jib/builder/steps/PlatformCheckerTest.java (Java)

Code before:
    Mockito.when(buildContext.getBaseImageConfiguration())
        .thenReturn(ImageConfiguration.builder(ImageReference.scratch()).build());
    Mockito.when(buildContext.getContainerConfiguration()).thenReturn(containerConfig);
  }

  @Test
  public void testCheckManifestPlatform_mismatch() {
    Mockito.when(containerConfig.getPlatforms())
        .thenReturn(ImmutableSet.of(new Platform("configured arch", "configured OS")));

    ContainerConfigurationTemplate containerConfigJson = new ContainerConfigurationTemplate();
    containerConfigJson.setArchitecture("actual arch");
    containerConfigJson.setOs("actual OS");
    Exception ex =
        assertThrows(
            PlatformNotFoundInBaseImageException.class,
            () -> PlatformChecker.checkManifestPlatform(buildContext, containerConfigJson));
    assertThat(ex)
        .hasMessageThat()
        .isEqualTo(
            "the configured platform (configured arch/configured OS) doesn't match the "
                + "platform (actual arch/actual OS) of the base image (scratch)");
  }

  @Test
  public void testCheckManifestPlatform_noWarningIfDefaultAmd64Linux()
      throws PlatformNotFoundInBaseImageException {
    Mockito.when(containerConfig.getPlatforms())
        .thenReturn(ImmutableSet.of(new Platform("amd64", "linux")));

    ContainerConfigurationTemplate containerConfigJson = new ContainerConfigurationTemplate();
    containerConfigJson.setArchitecture("actual arch");
    containerConfigJson.setOs("actual OS");
    PlatformChecker.checkManifestPlatform(buildContext, containerConfigJson);
  }

  @Test
  public void testCheckManifestPlatform_multiplePlatformsConfigured() {
    Mockito.when(containerConfig.getPlatforms())
        .thenReturn(ImmutableSet.of(new Platform("amd64", "linux"), new Platform("arch", "os")));
    Exception ex =
        assertThrows(
            PlatformNotFoundInBaseImageException.class,
            () ->
                PlatformChecker.checkManifestPlatform(
                    buildContext, new ContainerConfigurationTemplate()));
    assertThat(ex)
        .hasMessageThat()
        .isEqualTo(
            "cannot build for multiple platforms since the base image 'scratch' is not a manifest list.");
  }

Review comment (suggestion):
```suggestion
  public void testCheckManifestPlatform_noExceptionIfDefaultAmd64Linux()
```

Code after:
    Mockito.when(buildContext.getBaseImageConfiguration())
        .thenReturn(ImageConfiguration.builder(ImageReference.scratch()).build());
    Mockito.when(buildContext.getContainerConfiguration()).thenReturn(containerConfig);
  }

  @Test
  public void testCheckManifestPlatform_mismatch() {
    Mockito.when(containerConfig.getPlatforms())
        .thenReturn(ImmutableSet.of(new Platform("configured arch", "configured OS")));

    ContainerConfigurationTemplate containerConfigJson = new ContainerConfigurationTemplate();
    containerConfigJson.setArchitecture("actual arch");
    containerConfigJson.setOs("actual OS");
    Exception ex =
        assertThrows(
            PlatformNotFoundInBaseImageException.class,
            () -> PlatformChecker.checkManifestPlatform(buildContext, containerConfigJson));
    assertThat(ex)
        .hasMessageThat()
        .isEqualTo(
            "the configured platform (configured arch/configured OS) doesn't match the "
                + "platform (actual arch/actual OS) of the base image (scratch)");
  }

  @Test
  public void testCheckManifestPlatform_noExceptionIfDefaultAmd64Linux()
      throws PlatformNotFoundInBaseImageException {
    Mockito.when(containerConfig.getPlatforms())
        .thenReturn(ImmutableSet.of(new Platform("amd64", "linux")));

    ContainerConfigurationTemplate containerConfigJson = new ContainerConfigurationTemplate();
    containerConfigJson.setArchitecture("actual arch");
    containerConfigJson.setOs("actual OS");
    PlatformChecker.checkManifestPlatform(buildContext, containerConfigJson);
  }

  @Test
  public void testCheckManifestPlatform_multiplePlatformsConfigured() {
    Mockito.when(containerConfig.getPlatforms())
        .thenReturn(ImmutableSet.of(new Platform("amd64", "linux"), new Platform("arch", "os")));
    Exception ex =
        assertThrows(
            PlatformNotFoundInBaseImageException.class,
            () ->
                PlatformChecker.checkManifestPlatform(
                    buildContext, new ContainerConfigurationTemplate()));
    assertThat(ex)
        .hasMessageThat()
        .isEqualTo(
            "cannot build for multiple platforms since the base image 'scratch' is not a manifest list.");
  }