public HierarchicalClassId getHierarchicalId() { return new HierarchicalClassId(this.id, getDeepHash()); }
@Test public void shouldRecordClassPath() { final ClassName clazz = ClassName.fromClass(Foo.class); final HierarchicalClassId fooId = new HierarchicalClassId( new ClassIdentifier(0, clazz), "0"); final ClassInfo foo = ClassInfoMother.make(fooId.getId()); when(this.code.getCodeUnderTestNames()).thenReturn( Collections.singleton(clazz)); when(this.code.getClassInfo(any(List.class))).thenReturn( Collections.singletonList(foo)); createAndRunTestee(); verify(this.history).recordClassPath(Arrays.asList(fooId), this.coverageDb); }
@Test public void shouldRecordAndRetrieveClassPath() { final ClassHistory foo = new ClassHistory(new HierarchicalClassId( new ClassIdentifier(0, ClassName.fromString("foo")), ""), COV); final ClassHistory bar = new ClassHistory(new HierarchicalClassId( new ClassIdentifier(0, ClassName.fromString("bar")), ""), COV); recordClassPathWithTestee(foo.getId(), bar.getId()); final Reader reader = new StringReader(this.output.toString()); this.testee = new ObjectOutputStreamHistoryStore(this.writerFactory, Optional.ofNullable(reader)); this.testee.initialize(); final Map<ClassName, ClassHistory> expected = new HashMap<>(); expected.put(foo.getName(), foo); expected.put(bar.getName(), bar); assertEquals(expected, this.testee.getHistoricClassPath()); }
@Test public void shouldTreatClassesWithSameHashAsUnChanged() { final ClassName foo = ClassName.fromString("foo"); final HierarchicalClassId currentId = new HierarchicalClassId(0, foo, "0"); setCurrentClassPath(currentId); this.historicClassPath.put(foo, makeHistory(currentId)); assertFalse(this.testee.hasClassChanged(ClassName.fromString("foo"))); }
@Test public void shouldReadCorruptFiles() throws IOException { final HierarchicalClassId foo = new HierarchicalClassId( new ClassIdentifier(0, ClassName.fromString("foo")), ""); recordClassPathWithTestee(foo); final MutationResult mr = new MutationResult( MutationTestResultMother.createDetails("foo"), new MutationStatusTestPair(1, DetectionStatus.KILLED, "testName")); this.testee.recordResult(mr); this.output.append("rubbish"); final Reader reader = new StringReader(this.output.toString()); this.testee = new ObjectOutputStreamHistoryStore(this.writerFactory, Optional.ofNullable(reader)); this.testee.initialize(); assertFalse(this.testee.getHistoricResults().isEmpty()); }
@Test public void shouldTreatClassesWithDifferentHashesAsChanged() { final long currentHash = 42; final ClassName foo = ClassName.fromString("foo"); final ClassIdentifier currentId = new ClassIdentifier(currentHash, foo); setCurrentClassPath(ClassInfoMother.make(currentId)); this.historicClassPath.put(foo, makeHistory(new HierarchicalClassId( currentHash + 1, foo, "0"))); assertTrue(this.testee.hasClassChanged(ClassName.fromString("foo"))); }
@Test public void shouldRecordAndRetrieveResults() { final HierarchicalClassId foo = new HierarchicalClassId( new ClassIdentifier(0, ClassName.fromString("foo")), ""); recordClassPathWithTestee(foo); final MutationResult mr = new MutationResult( MutationTestResultMother.createDetails("foo"), new MutationStatusTestPair(1, DetectionStatus.KILLED, "testName")); this.testee.recordResult(mr); final Reader reader = new StringReader(this.output.toString()); this.testee = new ObjectOutputStreamHistoryStore(this.writerFactory, Optional.ofNullable(reader)); this.testee.initialize(); final Map<MutationIdentifier, MutationStatusTestPair> expected = new HashMap<>(); expected.put(mr.getDetails().getId(), mr.getStatusTestPair()); assertEquals(expected, this.testee.getHistoricResults()); }
public HierarchicalClassId getHierarchicalId() { return new HierarchicalClassId(this.id, getDeepHash()); }