How can I solve this problem of test difference caused by NBSP?

1 day ago 6
ARTICLE AD BOX

As far as I understand, the difference between expected and actual one is NBSP (Non-Breaking Space). I don’t know how to remove this. It doesn’t get highlighted and cannot be found using CTRL+H (looking for \u00A0).

I've already tried:

searching via CTRL+H to remove or replace it deleting the entire line and rewriting it manually.

here is the code of my test:

void shouldReturnFullReport_whenGivenSeveralDrivers() { Map<String, RacerInfo> racers = new LinkedHashMap<>(); racers.put("SVF", new RacerInfo("Sebastian Vettel", "FERRARI")); racers.put("DRR", new RacerInfo("Daniel Ricciardo", "RED BULL RACING TAG HEUER")); racers.put("VBM", new RacerInfo("Valtteri Bottas", "MERCEDES")); racers.put("LHM", new RacerInfo("Lewis Hamilton", "MERCEDES")); Map<String, Duration> lapTimes = new LinkedHashMap<>(); lapTimes.put("SVF", Duration.ofMinutes(1).plusSeconds(4).plusMillis(415)); lapTimes.put("DRR", Duration.ofMinutes(1).plusSeconds(12).plusMillis(13)); lapTimes.put("VBM", Duration.ofMinutes(1).plusSeconds(12).plusMillis(434)); lapTimes.put("LHM", Duration.ofMinutes(1).plusSeconds(12).plusMillis(460)); String expected = """ 1. Sebastian Vettel | FERRARI | 1:04.415 2. Daniel Ricciardo | RED BULL RACING TAG HEUER | 1:12.013 3. Valtteri Bottas | MERCEDES | 1:12.434 4. Lewis Hamilton | MERCEDES | 1:12.460 """; assertEquals(expected, ResultFormatter.format(lapTimes, racers)); }

here is the difference between expected and actual one

Read Entire Article