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 *    Marc R. Hoffmann - initial API and implementation
10 *
11 *******************************************************************************/
12package org.jacoco.core.test.validation.targets;
13
14import java.util.ArrayList;
15import java.util.List;
16
17/**
18 * Collection of stub methods that are called from the coverage targets. *
19 */
20public class Stubs {
21
22	/**
23	 * Exception stub.
24	 */
25	public static class StubException extends RuntimeException {
26
27		static final long serialVersionUID = 0L;
28
29	}
30
31	/**
32	 * Superclass stub.
33	 */
34	public static class SuperClass {
35
36		public SuperClass(boolean arg) {
37		}
38
39	}
40
41	/**
42	 * Dummy method.
43	 */
44	public static void nop() {
45	}
46
47	/**
48	 * Dummy method.
49	 */
50	public static void nop(int i) {
51	}
52
53	/**
54	 * Dummy method.
55	 */
56	public static void nop(boolean b) {
57	}
58
59	/**
60	 * Dummy method.
61	 */
62	public static void nop(Object o) {
63	}
64
65	/**
66	 * @return always <code>true</code>
67	 */
68	public static boolean t() {
69		return true;
70	}
71
72	/**
73	 * @return always <code>false</code>
74	 */
75	public static boolean f() {
76		return false;
77	}
78
79	/**
80	 * @return always <code>1</code>
81	 */
82	public static int i1() {
83		return 1;
84	}
85
86	/**
87	 * @return always <code>3</code>
88	 */
89	public static int i2() {
90		return 2;
91	}
92
93	/**
94	 * @return always <code>3</code>
95	 */
96	public static int i3() {
97		return 3;
98	}
99
100	/**
101	 * Always throws a {@link RuntimeException}.
102	 *
103	 * @throws StubException
104	 *             always thrown
105	 */
106	public static void ex() throws StubException {
107		throw new StubException();
108	}
109
110	/**
111	 * Throws a {@link RuntimeException} if given argument is <code>true</code>.
112	 */
113	public static void ex(boolean t) {
114		if (t) {
115			throw new StubException();
116		}
117	}
118
119	/**
120	 * Directly executes the given runnable.
121	 */
122	public static void exec(Runnable task) {
123		task.run();
124	}
125
126	/**
127	 * Never executes the given runnable.
128	 */
129	public static void noexec(Runnable task) {
130	}
131
132	/**
133	 * List of logged events. Using a static member here works as this class is
134	 * loaded in a new class loader for every test case.
135	 */
136	private static List<String> events = new ArrayList<String>();
137
138	/**
139	 * Records a event with the given id for later verification.
140	 */
141	public static void logEvent(String id) {
142		events.add(id);
143	}
144
145	/**
146	 * Returns a list of all recorded events in the sequence of recording.
147	 */
148	public static List<String> getLogEvents() {
149		return events;
150	}
151
152}
153