diff --git a/pitest/src/main/java/org/pitest/classinfo/Repository.java b/pitest-entry/src/main/java/org/pitest/classinfo/Repository.java similarity index 90% rename from pitest/src/main/java/org/pitest/classinfo/Repository.java rename to pitest-entry/src/main/java/org/pitest/classinfo/Repository.java index db58a203b..e9489fd9f 100644 --- a/pitest/src/main/java/org/pitest/classinfo/Repository.java +++ b/pitest-entry/src/main/java/org/pitest/classinfo/Repository.java @@ -108,3 +108,19 @@ private ClassPointer resolveClass(final String clazz) { } } + +class DeferredClassPointer implements ClassPointer { + private final Repository repository; + private final ClassName name; + + DeferredClassPointer(final Repository repository, final ClassName name) { + this.repository = repository; + this.name = name; + } + + @Override + public Optional fetch() { + return this.repository.fetchClass(this.name); + } + +} diff --git a/pitest/src/main/java/org/pitest/classpath/CodeSource.java b/pitest-entry/src/main/java/org/pitest/classpath/CodeSource.java similarity index 100% rename from pitest/src/main/java/org/pitest/classpath/CodeSource.java rename to pitest-entry/src/main/java/org/pitest/classpath/CodeSource.java diff --git a/pitest/src/main/java/org/pitest/coverage/analysis/LineMapper.java b/pitest-entry/src/main/java/org/pitest/coverage/analysis/LineMapper.java similarity index 100% rename from pitest/src/main/java/org/pitest/coverage/analysis/LineMapper.java rename to pitest-entry/src/main/java/org/pitest/coverage/analysis/LineMapper.java diff --git a/pitest/src/test/java/org/pitest/classpath/CodeSourceTest.java b/pitest-entry/src/test/java/org/pitest/classpath/CodeSourceTest.java similarity index 100% rename from pitest/src/test/java/org/pitest/classpath/CodeSourceTest.java rename to pitest-entry/src/test/java/org/pitest/classpath/CodeSourceTest.java diff --git a/pitest/src/test/java/org/pitest/coverage/codeassist/LineMapperTest.java b/pitest-entry/src/test/java/org/pitest/coverage/codeassist/LineMapperTest.java similarity index 100% rename from pitest/src/test/java/org/pitest/coverage/codeassist/LineMapperTest.java rename to pitest-entry/src/test/java/org/pitest/coverage/codeassist/LineMapperTest.java diff --git a/pitest/src/main/java/org/pitest/classinfo/AddlerHash.java b/pitest/src/main/java/org/pitest/classinfo/AddlerHash.java deleted file mode 100644 index e34b75009..000000000 --- a/pitest/src/main/java/org/pitest/classinfo/AddlerHash.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.pitest.classinfo; - -import java.util.zip.Adler32; - -public class AddlerHash implements HashFunction { - - @Override - public long hash(final byte[] value) { - final Adler32 adler = new Adler32(); - adler.update(value, 0, value.length); - return adler.getValue(); - } - -} diff --git a/pitest/src/main/java/org/pitest/classinfo/ClassPointer.java b/pitest/src/main/java/org/pitest/classinfo/ClassPointer.java index 82c76835a..2b65d3c77 100644 --- a/pitest/src/main/java/org/pitest/classinfo/ClassPointer.java +++ b/pitest/src/main/java/org/pitest/classinfo/ClassPointer.java @@ -35,18 +35,4 @@ public Optional fetch() { } -class DeferredClassPointer implements ClassPointer { - private final Repository repository; - private final ClassName name; - DeferredClassPointer(final Repository repository, final ClassName name) { - this.repository = repository; - this.name = name; - } - - @Override - public Optional fetch() { - return this.repository.fetchClass(this.name); - } - -} diff --git a/pitest/src/main/java/org/pitest/classinfo/TestToClassMapper.java b/pitest/src/main/java/org/pitest/classinfo/TestToClassMapper.java deleted file mode 100644 index d85999bee..000000000 --- a/pitest/src/main/java/org/pitest/classinfo/TestToClassMapper.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2011 Henry Coles - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and limitations under the License. - */ -package org.pitest.classinfo; - -import java.util.Optional; - -public class TestToClassMapper { - - private static final int TEST_LENGTH = "Test".length(); - private final Repository repository; - - public TestToClassMapper(final Repository repository) { - this.repository = repository; - } - - public Optional findTestee(final String className) { - - final ClassName name = ClassName.fromString(className); - - if (name.asJavaName().endsWith("Test") - && tryName(name.withoutSuffixChars(TEST_LENGTH))) { - return Optional.ofNullable(name.withoutSuffixChars(TEST_LENGTH)); - } - - if (name.getNameWithoutPackage().asJavaName().startsWith("Test") - && tryName(name.withoutPrefixChars(TEST_LENGTH))) { - return Optional.ofNullable(name.withoutPrefixChars(TEST_LENGTH)); - } - - return Optional.empty(); - } - - private boolean tryName(final ClassName name) { - return this.repository.hasClass(name); - } - -} diff --git a/pitest/src/main/java/org/pitest/junit/TestInfo.java b/pitest/src/main/java/org/pitest/junit/TestInfo.java deleted file mode 100644 index 9750e9dd7..000000000 --- a/pitest/src/main/java/org/pitest/junit/TestInfo.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2010 Henry Coles - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and limitations under the License. - */ -package org.pitest.junit; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.pitest.classinfo.ClassInfo; - -import java.util.Optional; -import java.util.function.Predicate; - -abstract class TestInfo { - - public static boolean isWithinATestClass(final ClassInfo clazz) { - - final Optional outerClass = clazz.getOuterClass(); - return isATest(clazz) - || (outerClass.isPresent() && isATest(outerClass.get())); - - } - - private static boolean isATest(final ClassInfo clazz) { - return isJUnit3Test(clazz) || isJUnit4Test(clazz) - || isATest(clazz.getSuperClass()); - } - - private static boolean isATest(final Optional clazz) { - return clazz.filter(TestInfo::isATest).isPresent(); - } - - public static Predicate isATest() { - return TestInfo::isATest; - } - - private static boolean isJUnit3Test(final ClassInfo clazz) { - return clazz.descendsFrom(junit.framework.TestCase.class) - || clazz.descendsFrom(junit.framework.TestSuite.class); - } - - private static boolean isJUnit4Test(final ClassInfo clazz) { - return clazz.hasAnnotation(RunWith.class) - || clazz.hasAnnotation(Test.class); - } - -} diff --git a/pitest/src/test/java/org/pitest/classinfo/AddlerHashTest.java b/pitest/src/test/java/org/pitest/classinfo/AddlerHashTest.java deleted file mode 100644 index 537db45cc..000000000 --- a/pitest/src/test/java/org/pitest/classinfo/AddlerHashTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.pitest.classinfo; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.io.Serializable; - -import org.junit.Before; -import org.junit.Test; -import org.pitest.coverage.codeassist.ClassUtils; - -public class AddlerHashTest { - - private AddlerHash testee; - - @Before - public void setUp() { - this.testee = new AddlerHash(); - } - - @Test - public void shouldCreateChecksumOfSuppliedBytes() - throws ClassNotFoundException { - assertTrue(this.testee.hash(ClassUtils.classAsBytes(String.class)) != 0); - } - - @Test - public void shouldGenerateSameHashForSameInput() - throws ClassNotFoundException { - final long expected = this.testee.hash(ClassUtils - .classAsBytes(String.class)); - assertEquals(expected, - this.testee.hash(ClassUtils.classAsBytes(String.class))); - } - - @Test - public void shouldCreateDifferentHashesForDifferentClasses() - throws ClassNotFoundException { - assertTrue(this.testee.hash(ClassUtils.classAsBytes(Comparable.class)) != this.testee - .hash(ClassUtils.classAsBytes(Serializable.class))); - } - -} diff --git a/pitest/src/test/java/org/pitest/classinfo/NameToClassInfoTest.java b/pitest/src/test/java/org/pitest/classinfo/NameToClassInfoTest.java deleted file mode 100644 index c36518b1c..000000000 --- a/pitest/src/test/java/org/pitest/classinfo/NameToClassInfoTest.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.pitest.classinfo; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - -import org.junit.Test; - -public class NameToClassInfoTest { - - @Test - public void shouldFetchClassWhenApplied() { - final Repository repository = mock(Repository.class); - final NameToClassInfo testee = new NameToClassInfo(repository); - testee.apply(ClassName.fromString("foo")); - verify(repository).fetchClass(ClassName.fromString("foo")); - } - -} diff --git a/pitest/src/test/java/org/pitest/classinfo/RepositoryTest.java b/pitest/src/test/java/org/pitest/classinfo/RepositoryTest.java deleted file mode 100644 index 2bf1b8ff0..000000000 --- a/pitest/src/test/java/org/pitest/classinfo/RepositoryTest.java +++ /dev/null @@ -1,291 +0,0 @@ -/* - * Copyright 2011 Henry Coles - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and limitations under the License. - */ -package org.pitest.classinfo; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.io.Serializable; - -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.pitest.classpath.ClassloaderByteArraySource; -import org.pitest.coverage.codeassist.ClassUtils; -import java.util.Optional; -import org.pitest.util.IsolationUtils; - -public class RepositoryTest { - - private Repository testee; - - @Mock - private ClassByteArraySource source; - - @Mock - private HashFunction hashFunction; - - @Before - public void setUp() { - MockitoAnnotations.openMocks(this); - this.testee = new Repository(new ClassloaderByteArraySource( - IsolationUtils.getContextClassLoader()), this.hashFunction); - } - - @Test - public void shouldReturnTrueWhenAskedForKnownClass() { - assertTrue(this.testee.hasClass(ClassName.fromClass(Integer.class))); - } - - @Test - public void shouldReturnFalseWhenAskedForUnknownClass() { - assertFalse(this.testee.hasClass(ClassName.fromString("never.heard.of.you"))); - } - - @Test - public void shouldOnlyCheckSourceForUnknownClassesOnce() { - this.testee = new Repository(this.source); - when(this.source.getBytes(anyString())).thenReturn(Optional. empty()); - this.testee.hasClass(ClassName.fromString("foo")); - this.testee.hasClass(ClassName.fromString("foo")); - verify(this.source, times(1)).getBytes("foo"); - } - - @Test - public void shouldReturnNoneWhenAskedForUnknownClass() { - assertEquals(Optional.empty(), - this.testee.fetchClass(ClassName.fromString("never.heard.of.you"))); - } - - @Test - public void shouldOnlyLookForUnknownClassesOnce() { - this.testee = new Repository(this.source); - when(this.source.getBytes(anyString())).thenReturn(Optional. empty()); - this.testee.fetchClass(ClassName.fromString("foo")); - this.testee.fetchClass(ClassName.fromString("foo")); - verify(this.source, times(1)).getBytes("foo"); - } - - @Test - public void shouldOnlyQuerySourceForAnUnknownClassOnce() { - this.testee = new Repository(this.source); - when(this.source.getBytes(anyString())).thenReturn(Optional. empty()); - this.testee.hasClass(ClassName.fromString("foo")); - this.testee.fetchClass(ClassName.fromString("foo")); - verify(this.source, times(1)).getBytes("foo"); - } - - @Test - public void shouldReturnInfoForClassOnClassPath() { - assertTrue(this.testee.fetchClass(Integer.class).isPresent()); - } - - @Test - public void shouldOnlyLookForKnownClassOnce() throws ClassNotFoundException { - this.testee = new Repository(this.source); - when(this.source.getBytes(anyString())).thenReturn( - Optional.ofNullable(ClassUtils.classAsBytes(String.class))); - this.testee.fetchClass(ClassName.fromString("foo")); - this.testee.fetchClass(ClassName.fromString("foo")); - verify(this.source, times(1)).getBytes("foo"); - } - - @Test - public void shouldDetectInterfacesAsInterfaces() { - final Optional anInterface = this.testee - .fetchClass(Serializable.class); - assertTrue(anInterface.get().isInterface()); - } - - @Test - public void shouldDetectInterfacesAsAbstract() { - final Optional anInterface = this.testee - .fetchClass(Serializable.class); - assertTrue(anInterface.get().isAbstract()); - } - - @Test - public void shouldDetectConcreteClassesAsNotInterfaces() { - final Optional aClass = this.testee.fetchClass(String.class); - assertFalse(aClass.get().isInterface()); - } - - @Test - public void shouldDetectConcreteClassesAsNotAbstract() { - final Optional aClass = this.testee.fetchClass(String.class); - assertFalse(aClass.get().isAbstract()); - } - - public static class SimpleInnerClass { - - } - - @Test - public void shouldReportOuterClassForStaticInnerClasses() { - final String actual = getOuterClassNameFor(SimpleInnerClass.class); - assertEquals(RepositoryTest.class.getName().replace(".", "/"), actual); - } - - @Test - public void shouldReportOuterClassForLocalClasses() { - final Object local = new Object() { - - }; - - final String actual = getOuterClassNameFor(local.getClass()); - assertEquals(RepositoryTest.class.getName().replace(".", "/"), actual); - } - - public class NonStaticInnerClass { - - } - - @Test - public void shouldReportOuterClassForNonStaticInnerClasses() { - final String actual = getOuterClassNameFor(NonStaticInnerClass.class); - assertEquals(RepositoryTest.class.getName().replace(".", "/"), actual); - } - - public static class OuterStaticInnerClass { - public static class InnerStaticClass { - - } - } - - @Test - public void shouldReportInnermstOuterClassForNestedInnerClasses() { - final String actual = getOuterClassNameFor(OuterStaticInnerClass.InnerStaticClass.class); - assertEquals( - RepositoryTest.OuterStaticInnerClass.class.getName().replace(".", "/"), - actual); - } - - static class Foo { - - } - - static class Bar extends Foo { - - } - - @Test - public void shouldReportSuperClass() { - final Optional aClass = this.testee.fetchClass(Bar.class); - assertEquals(ClassName.fromClass(Foo.class), aClass.get().getSuperClass() - .get().getName()); - } - - @Test - public void shouldReportSuperClassAsObjectWhenNoneDeclared() { - final Optional aClass = this.testee.fetchClass(Foo.class); - assertEquals(ClassName.fromClass(Object.class), aClass.get().getSuperClass() - .get().getName()); - } - - @Test - public void shouldReportNoSuperClassForObject() { - final Optional aClass = this.testee.fetchClass(Object.class); - assertEquals(Optional.empty(), aClass.get().getSuperClass()); - } - - @Test - public void shouldReportCodeLines() { - final Optional aClass = this.testee - .fetchClass(RepositoryTest.class); - aClass.get().isCodeLine(139); // flakey - } - - @Ignore - static class Annotated { - - } - - @Test - public void shouldRecordClassLevelAnnotations() { - final Optional aClass = this.testee.fetchClass(Annotated.class); - assertTrue(aClass.get().hasAnnotation(Ignore.class)); - } - - static class HasAnnotatedMethod { - @Test - public void foo() { - - } - } - - @Test - public void shouldRecordMethodLevelAnnotations() { - final Optional aClass = this.testee - .fetchClass(HasAnnotatedMethod.class); - assertTrue(aClass.get().hasAnnotation(Test.class)); - } - - static interface ITop { - - } - - static class Top implements ITop { - - } - - static class Middle extends Top { - - } - - static class Bottom extends Middle { - - } - - @Test - public void shouldCorrectlyNegotiateClassHierachies() { - final Optional aClass = this.testee.fetchClass(Bottom.class); - assertTrue(aClass.get().descendsFrom(Middle.class)); - assertTrue(aClass.get().descendsFrom(Top.class)); - assertTrue(aClass.get().descendsFrom(Object.class)); - assertFalse(aClass.get().descendsFrom(String.class)); - } - - @Test - public void doesNotTreatInterfacesAsPartOfClassHierachy() { - final Optional aClass = this.testee.fetchClass(Bottom.class); - assertFalse(aClass.get().descendsFrom(ITop.class)); - } - - @Test - public void shouldRecordSourceFile() { - final Optional aClass = this.testee.fetchClass(String.class); - assertEquals("String.java", aClass.get().getSourceFileName()); - } - - @Test - public void shouldCalculateHashForSuppledClass() { - this.testee.fetchClass(String.class); - verify(this.hashFunction).hash(any(byte[].class)); - } - - private String getOuterClassNameFor(final Class clazz) { - return this.testee.fetchClass(clazz).get().getOuterClass().get() - .getName().asInternalName(); - } - -} diff --git a/pitest/src/test/java/org/pitest/classinfo/TestToClassMapperTest.java b/pitest/src/test/java/org/pitest/classinfo/TestToClassMapperTest.java deleted file mode 100644 index e2e2609d0..000000000 --- a/pitest/src/test/java/org/pitest/classinfo/TestToClassMapperTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2011 Henry Coles - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and limitations under the License. - */ -package org.pitest.classinfo; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.when; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import java.util.Optional; - -public class TestToClassMapperTest { - - @Mock - private ClassByteArraySource source; - - private Repository repository; - - private TestToClassMapper testee; - - @Before - public void setUp() { - MockitoAnnotations.openMocks(this); - this.repository = new Repository(this.source); - this.testee = new TestToClassMapper(this.repository); - } - - @Test - public void shouldMapTestsPostfixedWithTestToTesteeWhenTesteeExists() { - final byte[] bytes = { 0 }; - when(this.source.getBytes("com.example.Foo")) - .thenReturn(Optional.ofNullable(bytes)); - assertEquals(ClassName.fromString("com.example.Foo"), - this.testee.findTestee("com.example.FooTest").get()); - } - - @Test - public void shouldMapTestsPrefixedWithTestToTesteeWhenTesteeExists() { - final byte[] bytes = { 0 }; - when(this.source.getBytes("com.example.Foo")) - .thenReturn(Optional.ofNullable(bytes)); - assertEquals(ClassName.fromString("com.example.Foo"), - this.testee.findTestee("com.example.TestFoo").get()); - } - - @Test - public void shouldReturnNoneWhenNoTesteeExistsMatchingNamingConvention() { - final byte[] bytes = null; - when(this.source.getBytes("com.example.Foo")) - .thenReturn(Optional.ofNullable(bytes)); - assertEquals(Optional.empty(), this.testee.findTestee("com.example.TestFoo")); - } - -} diff --git a/pitest/src/test/java/org/pitest/junit/TestInfoTest.java b/pitest/src/test/java/org/pitest/junit/TestInfoTest.java deleted file mode 100644 index d37203c26..000000000 --- a/pitest/src/test/java/org/pitest/junit/TestInfoTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2011 Henry Coles - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and limitations under the License. - */ -package org.pitest.junit; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Before; -import org.junit.Test; -import org.pitest.classinfo.ClassInfo; -import org.pitest.classinfo.Repository; -import org.pitest.classpath.ClassloaderByteArraySource; -import org.pitest.util.IsolationUtils; - -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class TestInfoTest { - - private Repository repository; - - @Before - public void setUp() { - this.repository = new Repository(new ClassloaderByteArraySource( - IsolationUtils.getContextClassLoader())); - } - - @Test - public void isATestShouldReturnTrueForJUnit3Tests() { - class JU3Test extends TestCase { - - } - assertTrue(TestInfo.isATest().test(fetchClass(JU3Test.class))); - } - - @Test - public void isATestShouldReturnTrueForJUnit3Suites() { - class JU3Test extends TestSuite { - - } - assertTrue(TestInfo.isATest().test(fetchClass(JU3Test.class))); - } - - @Test - public void isATestShouldReturnTrueForJUnit4Tests() { - assertTrue(TestInfo.isATest().test(fetchClass(TestInfoTest.class))); - } - - @Test - public void isATestShouldReturnFalseForNonTests() { - assertFalse(TestInfo.isATest().test(fetchClass(String.class))); - } - - static class Nested { - - } - - @Test - public void isWithinATestClassShouldReturnTrueForNestedClassesWithinATest() { - assertTrue(TestInfo.isWithinATestClass(fetchClass(Nested.class))); - } - - private ClassInfo fetchClass(final Class clazz) { - return this.repository.fetchClass(clazz).get(); - } - -}