public static BlockLocation blockLocation(final Location location, final int block) { return new BlockLocation(location, block); }
@Override protected BlockCoverage mapToData(final Map<String, Object> map) { final String method = (String) map.get(METHOD); final Location location = new Location(ClassName.fromString((String) map.get(CLASSNAME)), MethodName.fromString(method.substring(0, method.indexOf(OPEN_PAREN))), method.substring(method.indexOf(OPEN_PAREN))); final BlockLocation blockLocation = new BlockLocation(location, Integer.parseInt((String) map.get(NUMBER))); @SuppressWarnings("unchecked") final Collection<String> tests = (Collection<String>) map.get(TESTS); return new BlockCoverage(blockLocation, tests); }
@Override public Map<BlockLocation, Set<Integer>> mapLines(final ClassName clazz) { final Map<BlockLocation, Set<Integer>> map = new HashMap<>(); final Optional<byte[]> maybeBytes = this.source.fetchClassBytes(clazz); // classes generated at runtime eg by mocking frameworks // will be instrumented but not available on the classpath if (maybeBytes.isPresent()) { final ClassReader cr = new ClassReader(maybeBytes.get()); final ClassNode classNode = new ClassNode(); cr.accept(classNode, ClassReader.EXPAND_FRAMES); for (final Object m : classNode.methods) { final MethodNode mn = (MethodNode) m; final Location l = Location.location(clazz, MethodName.fromString(mn.name), mn.desc); final List<Block> blocks = ControlFlowAnalyser.analyze(mn); for (int i = 0; i != blocks.size(); i++) { final BlockLocation bl = new BlockLocation(l, i); map.put(bl, blocks.get(i).getLines()); } } } return map; }
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)); } }
private Collection<BlockLocation> makeCoverage(final String clazz, final int block) { final BlockLocation cs = new BlockLocation(Location.location( ClassName.fromString(clazz), MethodName.fromString("foo"), "V"), block); return Collections.singleton(cs); }
private BlockLocation makeCoverage(final String name, final int block) { final Location l = Location.location(ClassName.fromString(name), MethodName.fromString("amethod"), "methodDesc"); final BlockLocation bl = new BlockLocation(l, block); return bl; }
@Test public void shouldMapAllLinesWhenMethodContainsSingleBlock() throws Exception { final Map<BlockLocation, Set<Integer>> actual = analyse(OneBlock.class); final Location l = Location.location(ClassName.fromClass(OneBlock.class), MethodName.fromString("foo"), "()I"); final BlockLocation bl = new BlockLocation(l, 0); assertThat(actual.get(bl)).containsOnly(5); }
public static BlockLocation blockLocation(final Location location, final int block) { return new BlockLocation(location, block); }
@Override public Map<BlockLocation, Set<Integer>> mapLines(final ClassName clazz) { final Map<BlockLocation, Set<Integer>> map = new HashMap<>(); final Optional<byte[]> maybeBytes = this.source.fetchClassBytes(clazz); // classes generated at runtime eg by mocking frameworks // will be instrumented but not available on the classpath if (maybeBytes.isPresent()) { final ClassReader cr = new ClassReader(maybeBytes.get()); final ClassNode classNode = new ClassNode(); cr.accept(classNode, ClassReader.EXPAND_FRAMES); for (final Object m : classNode.methods) { final MethodNode mn = (MethodNode) m; final Location l = Location.location(clazz, MethodName.fromString(mn.name), mn.desc); final List<Block> blocks = ControlFlowAnalyser.analyze(mn); for (int i = 0; i != blocks.size(); i++) { final BlockLocation bl = new BlockLocation(l, i); map.put(bl, blocks.get(i).getLines()); } } } return map; }