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.filter; 13 14 import org.jacoco.core.analysis.ICounter; 15 import org.jacoco.core.test.filter.targets.Synchronized; 16 import org.jacoco.core.test.validation.ValidationTestBase; 17 import org.junit.Test; 18 19 /** 20 * Test of filtering of a bytecode that is generated for a synchronized 21 * statement. 22 */ 23 public class SynchronizedTest extends ValidationTestBase { 24 25 public SynchronizedTest() { 26 super(Synchronized.class); 27 } 28 29 /** 30 * {@link Synchronized#normal()} 31 */ 32 @Test 33 public void normal() { 34 assertLine("before", ICounter.FULLY_COVERED); 35 // when compiled with ECJ next line covered partly without filter: 36 assertLine("monitorEnter", ICounter.FULLY_COVERED); 37 assertLine("body", ICounter.FULLY_COVERED); 38 if (isJDKCompiler) { 39 // without filter next line covered partly: 40 assertLine("monitorExit", ICounter.FULLY_COVERED); 41 } else { 42 assertLine("monitorExit", ICounter.EMPTY); 43 } 44 assertLine("after", ICounter.FULLY_COVERED); 45 } 46 47 /** 48 * {@link Synchronized#explicitException()} 49 */ 50 @Test 51 public void explicitException() { 52 assertLine("explicitException.monitorEnter", ICounter.FULLY_COVERED); 53 assertLine("explicitException.exception", ICounter.FULLY_COVERED); 54 // when compiled with javac next line covered fully without filter: 55 assertLine("explicitException.monitorExit", ICounter.EMPTY); 56 } 57 58 /** 59 * {@link Synchronized#implicitException()} 60 */ 61 @Test 62 public void implicitException() { 63 assertLine("implicitException.monitorEnter", isJDKCompiler 64 ? ICounter.FULLY_COVERED : ICounter.PARTLY_COVERED); 65 assertLine("implicitException.exception", ICounter.NOT_COVERED); 66 if (isJDKCompiler) { 67 // without filter next line covered partly: 68 assertLine("implicitException.monitorExit", ICounter.NOT_COVERED); 69 } else { 70 assertLine("implicitException.monitorExit", ICounter.EMPTY); 71 } 72 } 73 74 } 75