@Test public void shouldI() throws Exception { final Map<BlockLocation, Set<Integer>> actual = analyse(ThreeBlocks2.class); final Location l = Location.location(ClassName.fromClass(ThreeBlocks2.class), MethodName.fromString("foo"), "(I)I"); assertThat(actual.get(BlockLocation.blockLocation(l, 0))).containsOnly(105); assertThat(actual.get(BlockLocation.blockLocation(l, 1))).containsOnly(106); assertThat(actual.get(BlockLocation.blockLocation(l, 2))).containsOnly(108); }
@Test public void shouldMapAllLinesWhenMethodContainsThreeBlocks() throws Exception { final Map<BlockLocation, Set<Integer>> actual = analyse(ThreeBlocks.class); final Location l = Location.location(ClassName.fromClass(ThreeBlocks.class), MethodName.fromString("foo"), "(I)I"); assertThat(actual.get(BlockLocation.blockLocation(l, 0))).containsOnly(5); assertThat(actual.get(BlockLocation.blockLocation(l, 1))).containsOnly(6); assertThat(actual.get(BlockLocation.blockLocation(l, 2))).containsOnly(8); }
@Test public void shouldMapAllLinesWhenMethodContainsThreeMultiLineBlocks() throws Exception { final Map<BlockLocation, Set<Integer>> actual = analyse(ThreeMultiLineBlocks.class); final Location l = Location.location( ClassName.fromClass(ThreeMultiLineBlocks.class), MethodName.fromString("foo"), "(I)I"); assertThat(actual.get(BlockLocation.blockLocation(l, 0))).contains(5, 6); assertThat(actual.get(BlockLocation.blockLocation(l, 1))).contains(7, 8); assertThat(actual.get(BlockLocation.blockLocation(l, 2))).contains(10, 11); }
private static Generator<BlockLocationBuilder, BlockLocation> blockLocationSeed() { return b -> BlockLocation.blockLocation(b._Location(), b._Block()); }
@Test public void shouldMapLinesWhenLinesSpanBlocks() throws Exception { final Map<BlockLocation, Set<Integer>> actual = analyse(com.example.LineNumbersSpanBlocks.class); final Location l = Location.location( ClassName.fromClass(com.example.LineNumbersSpanBlocks.class), MethodName.fromString("foo"), "(I)I"); assertThat(actual.get(BlockLocation.blockLocation(l, 2))).containsOnly(12); }
@Test public void shouldIncludeLastLinesConstructorsInBlock() throws Exception { final Map<BlockLocation, Set<Integer>> actual = analyse(LastLineOfContructorCheck.class); final Location l = Location.location( ClassName.fromClass(LastLineOfContructorCheck.class), MethodName.fromString("<init>"), "()V"); assertThat(actual.get(BlockLocation.blockLocation(l, 0))).contains(6); }
@Test public void shouldCalculateCoverageForMethodThatThrowsExceptionWithFinallyBlock() throws IOException, InterruptedException, ExecutionException { final List<CoverageResult> coveredClasses = runCoverageForTest(TestThrowsExceptionInFinallyBlock.class); final ClassName clazz = ClassName .fromClass(ThrowsExceptionInFinallyBlockTestee.class); assertThat(coveredClasses).anyMatch(coverageFor(BlockLocation.blockLocation( Location.location(clazz, this.foo, "()V"), 0))); assertThat(coveredClasses).anyMatch(coverageFor(BlockLocation.blockLocation( Location.location(clazz, this.foo, "()V"), 1))); }
@Test public void shouldCalculateCoverageForSmallMethodThatThrowsException() throws IOException, InterruptedException, ExecutionException { final List<CoverageResult> coveredClasses = runCoverageForTest(TestsClassWithException.class); assertThat(coveredClasses).anyMatch(coverageFor(CoveredBeforeExceptionTestee.class)); final ClassName throwsException = ClassName .fromClass(ThrowsExceptionTestee.class); assertThat(coveredClasses).anyMatch(coverageFor(BlockLocation.blockLocation( Location.location(throwsException, this.foo, "()V"), 0))); assertThat(coveredClasses).anyMatch(coverageFor(BlockLocation.blockLocation( Location.location(throwsException, MethodName.fromString("throwsException"), "()V"), 0))); }
@Test public void shouldCalculateCoverageForLargeMethodThatThrowsException() throws IOException, InterruptedException, ExecutionException { final List<CoverageResult> coveredClasses = runCoverageForTest(TestThrowsExceptionFromLargeMethodTestee.class); final ClassName clazz = ClassName .fromClass(ThrowsExceptionFromLargeMethodTestee.class); assertThat(coveredClasses).anyMatch(coverageFor(BlockLocation.blockLocation( Location.location(clazz, this.foo, "()I"), 0))); }