private PitError createPitErrorForExceptionOnClass(final Exception ex, final ClientClasspathPlugin clazz) { return new PitError("Error getting location of class " + clazz, ex); } };
public static RuntimeException translateCheckedException( final String message, final Throwable ex) { return new PitError(message, ex); }
private static Function<String, File> stringToCanonicalFile() { return fileAsString -> { try { return new File(fileAsString).getCanonicalFile(); } catch (final IOException ex) { throw new PitError("Error transforming classpath element " + fileAsString, ex); } }; }
private void reportBadPlugin(final String missingProperty, final ClientClasspathPlugin a) { final Class<?> clss = a.getClass(); throw new PitError("No implementation " + missingProperty + " in manifest of plugin jar for " + clss + " in " + clss.getProtectionDomain().getCodeSource().getLocation()); }
private static <T> T firstOrDefault(final Collection<? extends T> found, final T defaultInstance) { if (found.isEmpty()) { return defaultInstance; } if (found.size() > 1) { throw new PitError( "Multiple implementations of plugin detected on classpath"); } return found.iterator().next(); }
private static <S> S createService(final String name, final Class<S> ifc, final ClassLoader loader) { try { final Class<?> clz = Class.forName(name, true, loader); final Class<? extends S> impl = clz.asSubclass(ifc); final Constructor<? extends S> ctor = impl.getConstructor(); return ctor.newInstance(); } catch (final Exception ex) { throw new PitError("Error creating service " + ifc.getName(), ex); } }
public static <S> Collection<S> load(final Class<S> ifc, final ClassLoader loader) { try { return loadImpl(ifc, loader); } catch (final IOException ex) { throw new PitError("Error creating service " + ifc.getName(), ex); } }
private byte[] classBytes(final String className) { final Optional<byte[]> bytes = this.classByteSource.getBytes(className); if (bytes.isPresent()) { return bytes.get(); } throw new PitError("Unable to load class content for " + className); }
private ReportGenerationStrategy locateReportGenerationStrategy( String sourceDataFormat) { for (ReportGenerationStrategy strategy : this.reportGenerationStrategyList) { if (sourceDataFormat.equalsIgnoreCase(strategy.getGeneratorDataFormat())) { return strategy; } } throw new PitError("Could not locate report generator for data source [" + sourceDataFormat + "]"); }
private void checkMatrixMode(ReportOptions data) { if (data.isFullMutationMatrix() && !data.getOutputFormats().contains("XML")) { throw new PitError("Full mutation matrix is only supported in the output format XML."); } }
public MutationEngineFactory createEngine(String engine) { for (final MutationEngineFactory each : this.plugins.findMutationEngines()) { if (each.name().equals(engine)) { return each; } } throw new PitError("Could not load requested engine " + engine); }
private ResultType classify(final TestResult result) { switch (result.getState()) { case STARTED: return ResultType.STARTED; case NOT_RUN: return ResultType.SKIPPED; case FINISHED: return classifyFinishedTest(result); default: throw new PitError("Unhandled state"); } }
public MutationEngineFactory createEngine() { for (final MutationEngineFactory each : this.plugins.findMutationEngines()) { if (each.name().equals(this.options.getMutationEngine())) { return each; } } throw new PitError("Could not load requested engine " + this.options.getMutationEngine()); }
private void mutate(final Number constant) { if (constant instanceof Integer) { mutate((Integer) constant); } else if (constant instanceof Long) { mutate((Long) constant); } else if (constant instanceof Float) { mutate((Float) constant); } else if (constant instanceof Double) { mutate((Double) constant); } else { throw new PitError("Unsupported subtype of Number found:" + constant.getClass()); } }
private Iterable<MutationResultListenerFactory> findListeners() { final Iterable<? extends MutationResultListenerFactory> listeners = this.plugins .findListeners(); final Collection<MutationResultListenerFactory> matches = FCollection .filter(listeners, nameMatches(this.options.getOutputFormats())); if (matches.size() < this.options.getOutputFormats().size()) { throw new PitError("Unknown listener requested in " + StringUtil.join(this.options.getOutputFormats(), ",")); } return matches; }
private InstantiationStrategy findInstantiationStrategy(final Class<?> clazz) { final List<InstantiationStrategy> strategies = FCollection.filter( this.instantiationStrategies, canInstantiate(clazz)); if (strategies.isEmpty()) { throw new PitError("Cannot instantiate " + clazz); } else { return strategies.get(0); } }
@Test public void containsShouldStopProcessingOnFirstMatch() { final Collection<Integer> xs = Arrays.asList(1, 2, 3); final Predicate<Integer> predicate = a -> { if (a == 2) { throw new PitError("Did not shortcut"); } return a == 1; }; FCollection.contains(xs, predicate); // pass }
@Test public void containsShouldStopProcessingOnFirstMatch() { final Integer[] xs = { 1, 2, 3 }; final Predicate<Integer> predicate = a -> { if (a == 2) { throw new PitError("Did not shortcut"); } return a == 1; }; FArray.contains(xs, predicate); // pass }
public Configuration getTestFrameworkPlugin(TestPluginArguments options, ClassByteArraySource source) { for (final TestPluginFactory each : this.plugins.findTestFrameworkPlugins()) { if (each.name().equals(options.getTestPlugin())) { return each.createTestFrameworkConfiguration(options.getGroupConfig(), source, options.getExcludedRunners(), options.getIncludedTestMethods()); } } throw new PitError("Could not load requested test plugin " + options.getTestPlugin()); }
@Test public void shouldReportErrorWhenOneOccursDuringAnalysis() { this.mutations.add(new MutationDetails(aMutationId().withIndex(0) .withMutator("foo").build(), "file", "desc", 0, 0)); when(this.mutater.getMutation(any(MutationIdentifier.class))).thenThrow( new PitError("foo")); this.testee.run(); verify(this.reporter).done(ExitCode.UNKNOWN_ERROR); }