1/*******************************************************************************
2 * Copyright (c) 2009, 2015 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.agent.rt.internal;
13
14import static org.junit.Assert.assertEquals;
15import static org.junit.Assert.assertNull;
16
17import org.jacoco.agent.rt.internal.IExceptionLogger;
18
19/**
20 * {@link IExceptionLogger} implementation for testing purposes.
21 */
22public class ExceptionRecorder implements IExceptionLogger {
23
24	private Class<?> exceptionType;
25	private String message;
26	private Class<?> causeType;
27
28	public void logExeption(Exception ex) {
29		assertNull("multiple exeptions", exceptionType);
30		exceptionType = ex.getClass();
31		message = ex.getMessage();
32		causeType = ex.getCause() == null ? null : ex.getCause().getClass();
33	}
34
35	public void clear() {
36		exceptionType = null;
37		message = null;
38		causeType = null;
39	}
40
41	public void assertNoException() {
42		assertNull(exceptionType);
43	}
44
45	public void assertException(final Class<? extends Throwable> exceptionType,
46			final String message) {
47		assertEquals(exceptionType, this.exceptionType);
48		assertEquals(message, this.message);
49	}
50
51	public void assertException(final Class<? extends Throwable> exceptionType,
52			final String message, final Class<? extends Throwable> causeType) {
53		assertEquals(exceptionType, this.exceptionType);
54		assertEquals(message, this.message);
55		assertEquals(causeType, this.causeType);
56	}
57
58}
59