private void recordTestCoverage(final int executionTime, final int classId, final int probeNumber, final boolean testPassed) { when(this.is.readInt()).thenReturn(classId, executionTime); when(this.is.readString()).thenReturn("foo"); this.testee.apply(Id.CLAZZ, this.is); when(this.is.read(Description.class)).thenReturn(this.description); when(this.is.readInt()).thenReturn(1); when(this.is.readLong()).thenReturn(1l, CodeCoverageStore.encode(classId, probeNumber)); when(this.is.readBoolean()).thenReturn(testPassed); this.testee.apply(Id.OUTCOME, this.is); }
private SafeDataInputStream resultToStream() { final SafeDataInputStream is = new SafeDataInputStream( new ByteArrayInputStream(this.os.toByteArray())); return is; }
private CoverageResult createCoverageResult(final SafeDataInputStream is, final Description d, Collection<BlockLocation> visitedBlocks) { final boolean isGreen = is.readBoolean(); final int executionTime = is.readInt(); final CoverageResult cr = new CoverageResult(d, executionTime, isGreen, visitedBlocks); return cr; }
private static List<ClassName> receiveTestClassesFromParent( final SafeDataInputStream dis) { final int count = dis.readInt(); LOG.fine("Expecting " + count + " tests classes from parent"); final List<ClassName> classes = new ArrayList<>(count); for (int i = 0; i != count; i++) { classes.add(ClassName.fromString(dis.readString())); } LOG.fine("Tests classes received"); return classes; }
private void handleTestEnd(final SafeDataInputStream is) { final Description d = is.read(Description.class); final int numberOfResults = is.readInt(); final Set<BlockLocation> hits = new HashSet<>(numberOfResults); for (int i = 0; i != numberOfResults; i++) { readProbeHit(is, hits); } this.handler.apply(createCoverageResult(is, d, hits)); }
s = new Socket("localhost", port); final SafeDataInputStream dis = new SafeDataInputStream( s.getInputStream()); final CoverageOptions paramsFromParent = dis.read(CoverageOptions.class);
@Test public void shouldSendDetectionStatus() throws IOException { final MutationIdentifier mi = aMutationId().withIndex(0).withMutator("foo") .build(); final MutationStatusTestPair ms = new MutationStatusTestPair(2, DetectionStatus.KILLED, "foo"); this.testee.report(mi, ms); final SafeDataInputStream is = resultToStream(); assertEquals(Id.REPORT, is.readByte()); assertEquals(is.read(MutationIdentifier.class), mi); assertEquals(is.read(MutationStatusTestPair.class), ms); }
@Test public void shouldBeAbletoReadLargeStrings() { final char[] chars = new char[65536]; Arrays.fill(chars, '!'); final String s = new String(chars); final ByteArrayOutputStream o = new ByteArrayOutputStream(); final SafeDataOutputStream dos = new SafeDataOutputStream(o); dos.writeString(s); final ByteArrayInputStream i = new ByteArrayInputStream(o.toByteArray()); final SafeDataInputStream dis = new SafeDataInputStream(i); final String actual = dis.readString(); assertEquals(s, actual); }
private void readProbeHit(final SafeDataInputStream is, final Set<BlockLocation> hits) { final long encoded = is.readLong(); final BlockLocation location = probeToBlock(encoded); hits.add(location); }
private void handleProbes(final SafeDataInputStream is) { final int classId = is.readInt(); final String methodName = is.readString(); final String methodSig = is.readString(); final int first = is.readInt(); final int last = is.readInt(); final Location loc = Location.location(this.classIdToName.get(classId), MethodName.fromString(methodName), methodSig); for (int i = first; i != (last + 1); i++) { // nb, convert from classwide id to method scoped index within // BlockLocation this.probeToBlock.put(CodeCoverageStore.encode(classId, i), new BlockLocation(loc, i - first)); } }
s = new Socket("localhost", port); final SafeDataInputStream dis = new SafeDataInputStream( s.getInputStream()); final CoverageOptions paramsFromParent = dis.read(CoverageOptions.class);
private void handleDescribe(final SafeDataInputStream is) { final MutationIdentifier mutation = is.read(MutationIdentifier.class); this.idMap.put(mutation, MutationStatusTestPair.notAnalysed(1, DetectionStatus.STARTED)); }
@Test public void shouldSendMutationIdentifierToOutputStream() throws IOException { final MutationIdentifier mi = aMutationId().withIndex(0).withMutator("foo") .build(); this.testee.describe(mi); final SafeDataInputStream is = resultToStream(); assertEquals(Id.DESCRIBE, is.readByte()); assertEquals(is.read(MutationIdentifier.class), mi); }
@Override public void apply(final byte control, final SafeDataInputStream is) { switch (control) { case Id.CLAZZ: final int id = is.readInt(); final String name = is.readString(); this.classIdToName.put(id, ClassName.fromString(name)); break; case Id.PROBES: handleProbes(is); break; case Id.OUTCOME: handleTestEnd(is); break; case Id.DONE: // nothing to do ? } }
@Before public void setup() { MockitoAnnotations.initMocks(this); this.mutations = new ArrayList<>(); this.tests = new ArrayList<>(); this.args = new MinionArguments(this.mutations, this.tests, "anEgine", EngineArguments.arguments(), this.timeoutStrategy, false, false, TestPluginArguments.defaults()); when(this.is.read(MinionArguments.class)).thenReturn(this.args); when(this.engine.createMutator(any(ClassByteArraySource.class))) .thenReturn(this.mutater); final MutationEngineFactory factory = Mockito.mock(MutationEngineFactory.class); when(factory.createEngine(any(EngineArguments.class))).thenReturn(this.engine); when(this.settings.createEngine(any(String.class))).thenReturn(factory); this.testee = new MutationTestMinion(this.settings, this.is, this.reporter); }
@Override public ExitCode call() throws Exception { try (Socket clientSocket = this.socket.accept()) { try (BufferedInputStream bif = new BufferedInputStream( clientSocket.getInputStream())) { sendDataToMinion(clientSocket); final SafeDataInputStream is = new SafeDataInputStream(bif); return receiveResults(is); } catch (final IOException e) { throw Unchecked.translateCheckedException(e); } } finally { try { this.socket.close(); } catch (final IOException e) { throw Unchecked.translateCheckedException(e); } } }
private static List<ClassName> receiveTestClassesFromParent( final SafeDataInputStream dis) { final int count = dis.readInt(); LOG.fine("Expecting " + count + " tests classes from parent"); final List<ClassName> classes = new ArrayList<>(count); for (int i = 0; i != count; i++) { classes.add(ClassName.fromString(dis.readString())); } LOG.fine("Tests classes received"); return classes; }