0

Here is my test case and I am individually pasing this junit it is passing but when I am doing maven build it is showing some encoding error in json file, Please check the error message I provide in below

@Test
      public void testRemoveEmoji() throws Exception {    
        Items items = getSampleItems("/json/ItemObjectWithEmojiContent.json");
        List<Item> itemList = items.getItemsList();
        for(Item item : itemList) {
            assertNotNull(item);
            this.starcImportProcessor.removeEmojis(item);
            assertEquals("(Open -> In Progress -> Open -> Closed)", item.getDescription());
            for(ItemComment itemComments : item.getItemComments()) {
                assertEquals("Test comment", itemComments.getComment());
            }
        }

getSampleItems code :

private Items getSampleItems(final String path) throws JsonParseException, JsonMappingException, IOException {
    Items downloadedItems = new Items();
    JSONArray inputWorkitem = new JSONArray(new String(getJSONFromFile(path)));
    final ObjectMapper objectMapper = new ObjectMapper();
    List<Item> items = objectMapper.readValue(inputWorkitem.toString(), new TypeReference<List<Item>>() {});
    downloadedItems.setItemsList(items);
    return downloadedItems;
  }

private static byte[] getJSONFromFile(final String  jsonFilePath) throws IOException {
Resource resource = new ClassPathResource(jsonFilePath);
File file = resource.getFile();
return Files.readAllBytes(file.toPath());

}

Here is json file :

[
{
  "id" : 233565,
  "name" : "Hafmap DaimlerBosch Test4 CRL Reject",
  "createdAt" : "2020-09-29T16:07:23.918",
  "modifiedAt" : "2021-07-08T19:03:12.477",
  "version" : "15",
  "description" : "(Open -> In Progress -> Open -> Closed)",
  "descriptionFormat" : "Wiki",
  "assignedAt" : "2020-10-01T15:09:26.022",
  "typeName" : "Bug",
  "endDate" : "2020-10-08T14:40:00.000",
  "closedAt" : "2020-10-08T14:40:34.385",
  "ordinal" : 0,
  "createdBy" : {
    "id" : 1255,
    "name" : "CHRBOOT",
    "type" : "UserReference",
    "email" : "christian.bootz@daimler.com",
    "value" : null
  },
  "modifiedBy" : {
    "id" : 3,
    "name" : "computed.update",
    "type" : "UserReference",
    "email" : "codebeamer@intland.com",
    "value" : null
  },
  "tracker" : {
    "id" : 269438,
    "name" : "Change Request Light",
   "type" : "TrackerReference",
    "email" : null,
    "value" : null
  },
  "priority" : {
    "id" : 0,
    "name" : "Unset",
    "type" : "ChoiceOptionReference",
    "email" : null,
    "value" : null
  },
  "status" : {
    "id" : 7,
    "name" : "Closed",
    "type" : "ChoiceOptionReference",
    "email" : null,
    "value" : null
  },
  "severities" : [ {
    "id" : 3,
    "name" : "VoCA Prio 3",
    "type" : "ChoiceOptionReference",
    "email" : null,
    "value" : null
  } ],
  "resolutions" : [ ],
  "children" : [ ],
  "subjects" : [ ],
  "assignedTo" : [ {
    "id" : 3463,
    "name" : "PID8CBD",
    "type" : "UserReference",
    "email" : "christian.bootz@daimler.com",
    "value" : null
  } ],
  "owners" : null,
  "comments" : [ {
    "id" : 675988,
    "name" : "attachment mit leerzeichen.txt",
    "type" : "CommentReference",
    "email" : null,
    "value" : null
  }, {
    "id" : 675990,
    "name" : "Comment-1601992066937",
    "type" : "CommentReference",
    "email" : null,
    "value" : null
  }, {
    "id" : 675991,
    "name" : "Comment-1601992069782",
    "type" : "CommentReference",
    "email" : null,
    "value" : null
  } ],
  "categories" : [ ],
  "platforms" : [ ],
  "customFields" : [ {
    "fieldId" : 1001,
    "name" : "Sync Allowed",
    "values" : [ {
      "id" : 1,
      "name" : "Supplier External Tool",
      "type" : "ChoiceOptionReference",
      "email" : null,
      "value" : null
    } ],
    "type" : "ChoiceFieldValue",
    "value" : null
  }, {
    "fieldId" : 1003,
    "name" : "Top Ten",
    "values" : [ {
      "id" : 2,
      "name" : "No",
      "type" : "ChoiceOptionReference",
      "email" : null,
      "value" : null
    } ],
    "type" : "ChoiceFieldValue",
    "value" : null
  }, {
    "fieldId" : 1012,
    "name" : "Supplier Status",
    "values" : [ {
      "id" : 7,
      "name" : "Supplier Closed",
      "type" : "ChoiceOptionReference",
      "email" : null,
      "value" : null
    } ],
    "type" : "ChoiceFieldValue",
    "value" : null
  }, {
    "fieldId" : 1015,
    "name" : "Verification By Test Group",
    "values" : [ {
      "id" : 2,
      "name" : "No",
      "type" : "ChoiceOptionReference",
      "email" : null,
      "value" : null
    } ],
    "type" : "ChoiceFieldValue",
    "value" : null
  }, {
    "fieldId" : 1019,
    "name" : "Closing Reason",
    "values" : [ {
      "id" : 6,
      "name" : "No Defect / Issue",
      "type" : "ChoiceOptionReference",
      "email" : null,
      "value" : null
    } ],
    "type" : "ChoiceFieldValue",
    "value" : null
  }, {
    "fieldId" : 1020,
    "name" : "Reject Reason",
    "values" : [ {
      "id" : 4,
      "name" : "Not Reproducible",
      "type" : "ChoiceOptionReference",
      "email" : null,
      "value" : null
    } ],
    "type" : "ChoiceFieldValue",
    "value" : null
  }, {
    "fieldId" : 1028,
    "name" : "Supplier",
    "values" : [ {
      "id" : 594222,
      "name" : "Supplier_Bosch_MAP_ECU",
      "type" : "UserGroupReference",
      "email" : null,
      "value" : null
    } ],
    "type" : "ChoiceFieldValue",
    "value" : null
  }, {
    "fieldId" : 10000,
    "name" : "DEFAULT_PERMISSION_1",
    "values" : null,
    "type" : "TextFieldValue",
    "value" : "1"
  }, {
    "fieldId" : 10002,
    "name" : "Created On Date",
    "values" : null,
    "type" : "DateFieldValue",
    "value" : "2020-09-29T02:00:00.000"
  }, {
    "fieldId" : 10006,
    "name" : "Domain",
    "values" : null,
    "type" : "TextFieldValue",
    "value" : "Automated driving"
  }, {
    "fieldId" : 10007,
    "name" : "Supplier ID",
    "values" : null,
    "type" : "TextFieldValue",
    "value" : "DYMAPDAIEX-155919"
  }, {
    "fieldId" : 10024,
    "name" : "Last Status Change",
    "values" : null,
    "type" : "DateFieldValue",
    "value" : "2020-09-29T18:07:23.000"
  }, {
    "fieldId" : 10026,
    "name" : "DEFAULT_PERMISSION_READONLY_INPROGRESS",
    "values" : null,
    "type" : "TextFieldValue",
    "value" : "1"
  } ],
  "attachmentData" : [ {
    "id" : 675988,
    "name" : "attachment mit leerzeichen.txt",
    "description" : null,
    "descriptionFormat" : "PlainText",
    "createdAt" : "2020-10-06T13:47:45.956",
    "createdBy" : {
      "id" : 3463,
      "name" : "PID8CBD",
      "type" : "UserReference",
      "email" : "christian.bootz@daimler.com",
      "value" : null
    },
    "modifiedAt" : "2020-10-06T13:47:45.956",
    "modifiedBy" : {
      "id" : 3463,
      "name" : "PID8CBD",
      "type" : "UserReference",
      "email" : "christian.bootz@daimler.com",
      "value" : null
    },
    "version" : 1,
    "size" : 317,
    "md5" : "A2DE48D274A08AD80D19E8829D0093D4",
    "filePath" : null
  } ],
  "itemComments" : [ {
    "id" : 675990,
    "name" : "Comment-1601992066937",
    "createdAt" : "2020-10-06T13:47:46.937",
    "modifiedAt" : null,
    "version" : "1",
    "createdBy" : {
      "id" : 3463,
      "name" : "PID8CBD",
      "type" : "UserReference",
      "email" : "christian.bootz@daimler.com",
      "value" : null
    },
    "modifiedBy" : null,
    "comment" : "Test comment",
    "commentFormat" : "PlainText",
    "parent" : null,
    "attachments" : [ ]
  } ]
}

]

Here is the error when i am doing maven build here some encoding error it is showing: Could you please help me out how to resolve this issue

testRemoveEmoji(com.bosch.edexas.starc.processor.STARCImportProcessorTest)  Time elapsed: 0.008 sec  <<< FAILURE!
org.junit.ComparisonFailure: expected:<(Open -> []In Progress -> Open ...> but was:<(Open -> **[😀]**In Progress -> Open ...>
        at org.junit.Assert.assertEquals(Assert.java:125)
        at org.junit.Assert.assertEquals(Assert.java:147)
        at com.bosch.edexas.starc.processor.STARCImportProcessorTest.testRemoveEmoji(STARCImportProcessorTest.java:195)

OpenJDK 64-Bit Server VM warning: ignoring option UseSplitVerifier; support was removed in 8.0

Results :

Failed tests:
  STARCImportProcessorTest.testRemoveEmoji:195 expected:<(Open -> []In Progress -> Open ...> but was:<(Open -> **[????]**In Progress -> Open ...>
  • Show us getSampleItems code. Is there another method that populates that json file used?? – JCompetence Aug 30 '21 at 12:21
  • Please check my getSampleItem Code – Susilkumar Aug 30 '21 at 12:25
  • One question: are you running on windows? If so you might have to tell the vm that it should use UTF encoding by default. Not sure how to do that with maven but for wrting utf8 I had to add ` -Dfile.encoding=UTF-8`to my java call. – Lutz Aug 30 '21 at 12:27
  • Alternatively you could try to have a look at https://stackoverflow.com/questions/12096844/how-to-read-a-file-in-java-with-specific-character-encoding to make sure your reading UTF – Lutz Aug 30 '21 at 12:31
  • @Lutz : Yeah I am using windows – Susilkumar Aug 30 '21 at 12:33

1 Answers1

0

Please do the following when you are trying to make a new String() when your getJSONFromFile(path) returns a byte[] array.

new String(getJSONFromFile(path), StandardCharsets.UTF_8);
JCompetence
  • 6,997
  • 3
  • 19
  • 26