Home | History | Annotate | Download | only in validation
      1 /*******************************************************************************
      2  * Copyright (c) 2009, 2018 Mountainminds GmbH & Co. KG and Contributors
      3  * All rights reserved. This program and the accompanying materials
      4  * are made available under the terms of the Eclipse Public License v1.0
      5  * which accompanies this distribution, and is available at
      6  * http://www.eclipse.org/legal/epl-v10.html
      7  *
      8  * Contributors:
      9  *    Evgeny Mandrikov - initial API and implementation
     10  *
     11  *******************************************************************************/
     12 package org.jacoco.core.test.validation;
     13 
     14 import org.jacoco.core.analysis.ICounter;
     15 import org.jacoco.core.test.validation.targets.BadCycleInterface;
     16 import org.junit.Test;
     17 
     18 import java.util.regex.Matcher;
     19 import java.util.regex.Pattern;
     20 
     21 /**
     22  * Test of "bad cycles" with interfaces.
     23  */
     24 public class BadCycleInterfaceTest extends ValidationTestBase {
     25 
     26 	public BadCycleInterfaceTest() throws Exception {
     27 		super("src-java8", BadCycleInterface.class);
     28 	}
     29 
     30 	@Test
     31 	public void test() throws Exception {
     32 		final Matcher m = Pattern.compile("1\\.8\\.0_(\\d++)(-ea)?")
     33 				.matcher(System.getProperty("java.version"));
     34 		if (m.matches() && Integer.parseInt(m.group(1)) < 152) {
     35 			// Incorrect interpetation of JVMS 5.5 in JDK 8 causes a default
     36 			// method to be called before the static initializer of an interface
     37 			// (see JDK-8098557 and JDK-8164302):
     38 			assertLine("baseclinit", ICounter.FULLY_COVERED);
     39 			assertLine("childdefault", ICounter.FULLY_COVERED);
     40 
     41 			assertLogEvents("baseclinit", "childdefaultmethod", "childclinit",
     42 					"childstaticmethod");
     43 		} else {
     44 			// This shouldn't happen with JDK 9 (see also JDK-8043275)
     45 			// and starting with JDK 8u152 (see JDK-8167607):
     46 			assertLine("baseclinit", ICounter.EMPTY);
     47 			assertLine("childdefault", ICounter.NOT_COVERED);
     48 			assertLogEvents("childclinit", "childstaticmethod");
     49 		}
     50 		assertLine("childclinit", ICounter.FULLY_COVERED);
     51 		assertLine("childstatic", ICounter.FULLY_COVERED);
     52 	}
     53 
     54 }
     55