### Question:
CompileErrorValidator { public void validate(final File listingFile) { if (listingFile == null) throw new NullPointerException("File cannot be null."); final EtmPoint point = PointFactory.getPoint(getClass(), "validate"); try { ListingParseResult parserResult; try { parserResult = listingParser.parseListing(listingFile); } catch (final IOException e) { throw new CclCommandException( "Failed to parse listing data from file: " + listingFile.getAbsolutePath(), e); } if (!parserResult.getErrors().isEmpty()) throw new CclCompilationException( "Failure to compile code: " + parserResult.getErrors().iterator().next().getMessage()); } finally { point.collect(); } } CompileErrorValidator(final ListingParser listingParser); static CompileErrorValidator getInstance(); void validate(final File listingFile);  }### Answer:
@Test public void testValidateNoErrors() throws Exception { final EtmPoint point = mock(EtmPoint.class); mockStatic(PointFactory.class); when(PointFactory.getPoint(CompileErrorValidator.class, "validate")).thenReturn(point); final File listingFile = mock(File.class); final ListingParseResult result = mock(ListingParseResult.class); when(listingParser.parseListing(listingFile)).thenReturn(result); validator.validate(listingFile); verify(point).collect(); }
@Test public void testValidateNullFile() { NullPointerException e = assertThrows(NullPointerException.class, () -> { validator.validate(null); }); assertThat(e.getMessage()).isEqualTo("File cannot be null."); }
@Test public void testValidateWithErrors() throws Exception { final File listingFile = mock(File.class); final ListingParseResult result = mock(ListingParseResult.class); when(listingParser.parseListing(listingFile)).thenReturn(result); final String errorMessage = "oh noes!"; final CclError error = mock(CclError.class); when(error.getMessage()).thenReturn(errorMessage); when(result.getErrors()).thenReturn(Collections.singleton(error)); CclCompilationException e = assertThrows(CclCompilationException.class, () -> { validator.validate(listingFile); }); assertThat(e.getMessage()).isEqualTo("Failure to compile code: " + errorMessage); }