Skip to content

Commit

Permalink
workaroud shading issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Coles committed Apr 20, 2021
1 parent ee18353 commit b937ba0
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 202 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.pitest.classinfo.ClassByteArraySource;
import org.pitest.classinfo.ClassInfo;
import org.pitest.classinfo.ClassInfoSource;
import org.pitest.classinfo.ClassName;
Expand All @@ -21,7 +22,7 @@
/**
* Provides access to code and tests on the classpath
*/
public class CodeSource implements ClassInfoSource {
public class CodeSource implements ClassInfoSource, ClassByteArraySource {

private final ProjectClassPaths classPath;
private final Repository classRepository;
Expand Down Expand Up @@ -75,7 +76,6 @@ public Collection<ClassInfo> getClassInfo(final Collection<ClassName> classes) {
.collect(Collectors.toList());
}

// not used but keep to allow plugins to query bytecode
public Optional<byte[]> fetchClassBytes(final ClassName clazz) {
return this.classRepository.querySource(clazz);
}
Expand All @@ -90,4 +90,8 @@ private Function<ClassName, Stream<ClassInfo>> nameToClassInfo() {
.andThen(Streams::fromOptional);
}

@Override
public Optional<byte[]> getBytes(String clazz) {
return fetchClassBytes(ClassName.fromString(clazz));
}
}

This file was deleted.

124 changes: 0 additions & 124 deletions pitest-entry/src/test/java/org/pitest/classinfo/ClassInfoTest.java

This file was deleted.

This file was deleted.

20 changes: 0 additions & 20 deletions pitest/src/main/java/org/pitest/classinfo/NameToClassInfo.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import org.pitest.classinfo.ClassByteArraySource;
import org.pitest.classinfo.ClassName;
import org.pitest.classpath.CodeSource;
import org.pitest.coverage.BlockLocation;
import org.pitest.coverage.LineMap;
import java.util.Optional;
Expand All @@ -18,9 +18,9 @@

public class LineMapper implements LineMap {

private final CodeSource source;
private final ClassByteArraySource source;

public LineMapper(final CodeSource source) {
public LineMapper(final ClassByteArraySource source) {
this.source = source;
}

Expand All @@ -29,7 +29,7 @@ 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);
final Optional<byte[]> maybeBytes = this.source.getBytes(clazz.asInternalName());
// classes generated at runtime eg by mocking frameworks
// will be instrumented but not available on the classpath
if (maybeBytes.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.pitest.coverage.codeassist;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;

import java.util.Map;
Expand All @@ -11,8 +11,8 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.pitest.classinfo.ClassByteArraySource;
import org.pitest.classinfo.ClassName;
import org.pitest.classpath.CodeSource;
import org.pitest.coverage.BlockLocation;
import org.pitest.coverage.LineMap;
import org.pitest.coverage.analysis.LineMapper;
Expand All @@ -29,7 +29,7 @@
public class LineMapperTest {

@Mock
CodeSource source;
ClassByteArraySource source;

@Test
public void shouldMapAllLinesWhenMethodContainsSingleBlock() throws Exception {
Expand Down Expand Up @@ -114,7 +114,7 @@ int foo(int i) {

private Map<BlockLocation, Set<Integer>> analyse(Class<?> clazz)
throws ClassNotFoundException {
when(this.source.fetchClassBytes(any(ClassName.class))).thenReturn(
when(this.source.getBytes(anyString())).thenReturn(
Optional.ofNullable(ClassUtils.classAsBytes(clazz)));
final LineMap testee = new LineMapper(this.source);
return testee.mapLines(ClassName.fromClass(clazz));
Expand Down

0 comments on commit b937ba0

Please sign in to comment.