Repository: GoogleContainerTools/jib
File: jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/SkaffoldSyncMapTemplateTest.java (Java)

Code before:
    try {
      SkaffoldSyncMapTemplate.from(FAIL_TEST_JSON_BAD_PROPERTY_NAME);
      Assert.fail();
    } catch (UnrecognizedPropertyException ex) {
      Assert.assertTrue(ex.getMessage().contains("Unrecognized field \"jean-luc\""));
    }
  }

  @Test
  public void testFrom_missingField() throws IOException {
    try {
      SkaffoldSyncMapTemplate.from(FAIL_TEST_JSON_MISSING_FIELD);
      Assert.fail();
    } catch (MismatchedInputException ex) {
      Assert.assertTrue(ex.getMessage().contains("Missing required creator property 'dest'"));
    }
  }

  @Test
  public void testFrom_validEmpty() throws Exception {
    SkaffoldSyncMapTemplate templateEmptyGenerated =
        SkaffoldSyncMapTemplate.from(TEST_JSON_EMPTY_GENERATED);
    Assert.assertTrue(templateEmptyGenerated.getGenerated().isEmpty());
    SkaffoldSyncMapTemplate templateNoGenerated =
        SkaffoldSyncMapTemplate.from(TEST_JSON_NO_GENERATED);
    Assert.assertTrue(templateNoGenerated.getGenerated().isEmpty());
    // pass if no exceptions
  }

  @Test
  public void testGetJsonString() throws IOException {
    SkaffoldSyncMapTemplate ssmt = new SkaffoldSyncMapTemplate();
    ssmt.addGenerated(
        new FileEntry(
            GEN_SRC,
            AbsoluteUnixPath.get("/genDest"),
            FilePermissions.DEFAULT_FILE_PERMISSIONS,
            FileEntriesLayer.DEFAULT_MODIFICATION_TIME));
    ssmt.addDirect(
        new FileEntry(
            DIR_SRC_1,
            AbsoluteUnixPath.get("/dirDest1"),
            FilePermissions.DEFAULT_FILE_PERMISSIONS,
            FileEntriesLayer.DEFAULT_MODIFICATION_TIME));
    ssmt.addDirect(
        new FileEntry(
            DIR_SRC_2,
            AbsoluteUnixPath.get("/dirDest2"),
            FilePermissions.DEFAULT_FILE_PERMISSIONS,
            FileEntriesLayer.DEFAULT_MODIFICATION_TIME));
    Assert.assertEquals(TEST_JSON, ssmt.getJsonString());

Review comment (suggestion):
```suggestion
    SkaffoldSyncMapTemplate templateNoGenerated =
        SkaffoldSyncMapTemplate.from(TEST_JSON_NO_GENERATED);
    Assert.assertTrue(templateEmptyGenerated.getGenerated().isEmpty());
    Assert.assertTrue(templateNoGenerated.getGenerated().isEmpty());
```

Code after:
    try {
      SkaffoldSyncMapTemplate.from(FAIL_TEST_JSON_BAD_PROPERTY_NAME);
      Assert.fail();
    } catch (UnrecognizedPropertyException ex) {
      Assert.assertTrue(ex.getMessage().contains("Unrecognized field \"jean-luc\""));
    }
  }

  @Test
  public void testFrom_missingField() throws IOException {
    try {
      SkaffoldSyncMapTemplate.from(FAIL_TEST_JSON_MISSING_FIELD);
      Assert.fail();
    } catch (MismatchedInputException ex) {
      Assert.assertTrue(ex.getMessage().contains("Missing required creator property 'dest'"));
    }
  }

  @Test
  public void testFrom_validEmpty() throws Exception {
    SkaffoldSyncMapTemplate templateEmptyGenerated =
        SkaffoldSyncMapTemplate.from(TEST_JSON_EMPTY_GENERATED);
    SkaffoldSyncMapTemplate templateNoGenerated =
        SkaffoldSyncMapTemplate.from(TEST_JSON_NO_GENERATED);
    Assert.assertTrue(templateEmptyGenerated.getGenerated().isEmpty());
    Assert.assertTrue(templateNoGenerated.getGenerated().isEmpty());
  }

  @Test
  public void testGetJsonString() throws IOException {
    SkaffoldSyncMapTemplate ssmt = new SkaffoldSyncMapTemplate();
    ssmt.addGenerated(
        new FileEntry(
            GEN_SRC,
            AbsoluteUnixPath.get("/genDest"),
            FilePermissions.DEFAULT_FILE_PERMISSIONS,
            FileEntriesLayer.DEFAULT_MODIFICATION_TIME));
    ssmt.addDirect(
        new FileEntry(
            DIR_SRC_1,
            AbsoluteUnixPath.get("/dirDest1"),
            FilePermissions.DEFAULT_FILE_PERMISSIONS,
            FileEntriesLayer.DEFAULT_MODIFICATION_TIME));
    ssmt.addDirect(
        new FileEntry(
            DIR_SRC_2,
            AbsoluteUnixPath.get("/dirDest2"),
            FilePermissions.DEFAULT_FILE_PERMISSIONS,
            FileEntriesLayer.DEFAULT_MODIFICATION_TIME));
    Assert.assertEquals(TEST_JSON, ssmt.getJsonString());
  }