Home | History | Annotate | Download | only in targets
      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.targets;
     13 
     14 import static org.jacoco.core.test.validation.targets.Stubs.ex;
     15 import static org.jacoco.core.test.validation.targets.Stubs.nop;
     16 
     17 import org.jacoco.core.test.validation.targets.Stubs.StubException;
     18 
     19 /**
     20  * This test target is a synchronized statement.
     21  */
     22 public class Synchronized {
     23 
     24 	private static final Object lock = new Object();
     25 
     26 	private static void normal() {
     27 		nop(); // $line-before$
     28 		synchronized (lock) { // $line-monitorEnter$
     29 			nop(); // $line-body$
     30 		} // $line-monitorExit$
     31 		nop(); // $line-after$
     32 	}
     33 
     34 	private static void explicitException() {
     35 		synchronized (lock) { // $line-explicitException.monitorEnter$
     36 			throw new StubException(); // $line-explicitException.exception$
     37 		} // $line-explicitException.monitorExit$
     38 	}
     39 
     40 	private static void implicitException() {
     41 		synchronized (lock) { // $line-implicitException.monitorEnter$
     42 			ex(); // $line-implicitException.exception$
     43 		} // $line-implicitException.monitorExit$
     44 	}
     45 
     46 	public static void main(String[] args) {
     47 		normal();
     48 
     49 		try {
     50 			explicitException();
     51 		} catch (StubException e) {
     52 		}
     53 
     54 		try {
     55 			implicitException();
     56 		} catch (StubException e) {
     57 		}
     58 	}
     59 
     60 }
     61