### Question:
NmeaUtil { public static String supplementWithTime(String line, long arrivalTime) { line = line.trim(); final String amendedLine; NmeaMessage m = parseNmea(line); Long t = m.getUnixTimeMillis(); Long a = m.getArrivalTimeMillis(); if (t == null) { t = arrivalTime; if (line.startsWith("\\")) { int i = line.indexOf(BACKSLASH, 1); if (i == -1) throw new RuntimeException( "line starts with \\ but does not have closing tag block delimiter \\"); if (i < 4) throw new RuntimeException("tag block not long enough to have a checksum"); String content = line.substring(1, i - 3); StringBuilder s = new StringBuilder(content); s.append(","); appendTimes(arrivalTime, t, s); String checksum = NmeaUtil.getChecksum(s.toString(), false); s.append('*'); s.append(checksum); s.append(line.substring(i)); s.insert(0, BACKSLASH); amendedLine = s.toString(); } else { StringBuilder s = new StringBuilder(); appendTimes(t, arrivalTime, s); String checksum = NmeaUtil.getChecksum(s.toString(), false); s.append("*"); s.append(checksum); s.append(BACKSLASH); s.append(line); s.insert(0, BACKSLASH); amendedLine = s.toString(); } } else if (a == null) { int i = line.indexOf(BACKSLASH, 1); String content = line.substring(1, i - 3); StringBuilder s = new StringBuilder(content); s.append(",a:"); s.append(arrivalTime); String checksum = NmeaUtil.getChecksum(s.toString(), false); s.append('*'); s.append(checksum); s.append(line.substring(i)); s.insert(0, BACKSLASH); amendedLine = s.toString(); } else { amendedLine = line; } return amendedLine; } private  NmeaUtil(); static boolean isValid(String sentence); static String getChecksum(String sentence); static String getChecksum(String sentence, boolean ignoreLeadingDollarOrExclamation); static NmeaMessage parseNmea(String line); static String insertKeyValueInTagBlock(String line, String name, String value); static String supplementWithTime(String line, long arrivalTime); static Talker getTalker(String s); static String createTagBlock(LinkedHashMap<String, String> tags); static String createNmeaLine(LinkedHashMap<String, String> tags, List<String> items);  }### Answer:
@Test public void testSupplementWithTimeDoesNothingToMultilineMessagesAfterFirst() { String line = "\\g:2-2-3987*58\\!BSVDM,2,2,0,A,lQ@@0000002,0*00"; assertEquals("\\g:2-2-3987,c:0,a:0*5A\\!BSVDM,2,2,0,A,lQ@@0000002,0*00", NmeaUtil.supplementWithTime(line, 0)); }
@Test public void testSupplementWithTimeAddsArrivalTimeIfMissing() { String line = "\\s:rEV02,c:1334337322*5E\\!AIVDM,1,1,,B,14`980002?6UgpR1w0c8cG0L0Gww,0*58"; assertEquals( "\\s:rEV02,c:1334337322,a:0*19\\!AIVDM,1,1,,B,14`980002?6UgpR1w0c8cG0L0Gww,0*58", NmeaUtil.supplementWithTime(line, 0)); }
@Test public void testSupplementWithTime() { NmeaUtil.supplementWithTime("\\1G3:33799,s:Point Lookout,c:1486441015*73\\", 123); }