From 296f992a80fb545bb3447c8882cf213f56a765bd Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Mon, 27 Feb 2017 15:03:44 +0100 Subject: Exclude enum methods "values" and "valueOf" from reports (#491) --- .../test/validation/EnumImplicitMethodsTest.java | 39 ++++++++++++++++++ .../validation/targets/EnumImplicitMethods.java | 48 ++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 org.jacoco.core.test/src/org/jacoco/core/test/validation/EnumImplicitMethodsTest.java create mode 100644 org.jacoco.core.test/src/org/jacoco/core/test/validation/targets/EnumImplicitMethods.java (limited to 'org.jacoco.core.test/src/org/jacoco/core/test/validation') diff --git a/org.jacoco.core.test/src/org/jacoco/core/test/validation/EnumImplicitMethodsTest.java b/org.jacoco.core.test/src/org/jacoco/core/test/validation/EnumImplicitMethodsTest.java new file mode 100644 index 00000000..ddc1da12 --- /dev/null +++ b/org.jacoco.core.test/src/org/jacoco/core/test/validation/EnumImplicitMethodsTest.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2009, 2017 Mountainminds GmbH & Co. KG and Contributors + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Evgeny Mandrikov - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.core.test.validation; + +import org.jacoco.core.analysis.ICounter; +import org.jacoco.core.test.validation.targets.EnumImplicitMethods; +import org.junit.Test; + +/** + * Test of an implicit methods and static initializer in enums. + */ +public class EnumImplicitMethodsTest extends ValidationTestBase { + + public EnumImplicitMethodsTest() { + super(EnumImplicitMethods.class); + } + + @Test + public void testCoverageResult() { + assertLine("classdef", ICounter.FULLY_COVERED); + assertLine("customValueOfMethod", ICounter.NOT_COVERED); + assertLine("customValuesMethod", ICounter.NOT_COVERED); + + assertLine("const", ICounter.PARTLY_COVERED); + assertLine("staticblock", ICounter.FULLY_COVERED); + assertLine("super", ICounter.FULLY_COVERED); + assertLine("constructor", ICounter.FULLY_COVERED); + } + +} diff --git a/org.jacoco.core.test/src/org/jacoco/core/test/validation/targets/EnumImplicitMethods.java b/org.jacoco.core.test/src/org/jacoco/core/test/validation/targets/EnumImplicitMethods.java new file mode 100644 index 00000000..aaa5e987 --- /dev/null +++ b/org.jacoco.core.test/src/org/jacoco/core/test/validation/targets/EnumImplicitMethods.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2009, 2017 Mountainminds GmbH & Co. KG and Contributors + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Evgeny Mandrikov - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.core.test.validation.targets; + +public enum EnumImplicitMethods { // $line-classdef$ + + CONST(Stubs.f() ? new Object() : new Object()); // $line-const$ + + static { + } // $line-staticblock$ + + /** + * Unlike in {@link Target07 regular classes}, even if enum has explicit + * constructor, {@code clinit} method in any case has a reference to the + * line of enum definition. + */ + EnumImplicitMethods(Object o) { // $line-super$ + } // $line-constructor$ + + /** + * This method should not be excluded from analysis unlike implicitly + * created {@link #valueOf(String)} method that refers to the line of enum + * definition. + */ + public void valueOf() { + } // $line-customValueOfMethod$ + + /** + * This method should not be excluded from analysis unlike implicitly + * created {@link #values()} method that refers to the line of enum + * definition. + */ + public void values(Object o) { + } // $line-customValuesMethod$ + + public static void main(String[] args) { + } + +} -- cgit v1.2.3