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

Code before:
  @Mock private ContainerConfiguration containerConfig;

  @Before
  public void setUp() {
    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");
    try {
      PlatformChecker.checkManifestPlatform(buildContext, containerConfigJson);
      Assert.fail();
    } catch (PlatformNotFoundInBaseImageException ex) {
      Assert.assertEquals(
          "the configured platform (configured arch/configured OS) doesn't match the "
              + "platform (actual arch/actual OS) of the base image (scratch)",
          ex.getMessage());
    }
  }

  @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")));

    try {
      PlatformChecker.checkManifestPlatform(buildContext, new ContainerConfigurationTemplate());
      Assert.fail();
    } catch (PlatformNotFoundInBaseImageException ex) {
      Assert.assertEquals(
          "cannot build for multiple platforms since the base image 'scratch' is not a manifest list.",

Review comment (suggestion):
How about we do the following here and in the tests below:

```
Exception exception = assertThrows(PlatformNotFoundInBaseImageException.class, () -> PlatformChecker.checkManifestPlatform(buildContext, containerConfigJson))
assertThat(exception).hasMessageThat().isEqualTo( "the configured platform (configured arch/configured OS) doesn't match the "
              + "platform (actual arch/actual OS) of the base image (scratch)");
```
We might have to add the following to the import statements: `import static org.junit.Assert.assertThrows;` and use Truth for `assertThat`

Code after:

  @Mock private BuildContext buildContext;
  @Mock private ContainerConfiguration containerConfig;

  @Before
  public void setUp() {
    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(