aboutsummaryrefslogtreecommitdiffstats
path: root/org.jacoco.core.test/src/org/jacoco/core/data/ExecutionDataTest.java
blob: 541ddb33bff9d08acc118fdeda91cee7538c44e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*******************************************************************************
 * Copyright (c) 2009, 2016 Mountainminds GmbH & Co. KG and Contributors
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Marc R. Hoffmann - initial API and implementation
 *    
 *******************************************************************************/
package org.jacoco.core.data;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

/**
 * Unit tests for {@link ExecutionData}.
 */
public class ExecutionDataTest {

	@Test
	public void testCreateEmpty() {
		final ExecutionData e = new ExecutionData(5, "Example", 3);
		assertEquals(5, e.getId());
		assertEquals("Example", e.getName());
		assertEquals(3, e.getProbes().length);
		assertFalse(e.getProbes()[0]);
		assertFalse(e.getProbes()[1]);
		assertFalse(e.getProbes()[2]);
	}

	@Test
	public void testGetters() {
		final boolean[] data = new boolean[0];
		final ExecutionData e = new ExecutionData(5, "Example", data);
		assertEquals(5, e.getId());
		assertEquals("Example", e.getName());
		assertSame(data, e.getProbes());
	}

	@Test
	public void testReset() {
		final ExecutionData e = new ExecutionData(5, "Example", new boolean[] {
				true, false, true });
		e.reset();
		assertFalse(e.getProbes()[0]);
		assertFalse(e.getProbes()[1]);
		assertFalse(e.getProbes()[2]);
	}

	@Test
	public void testMerge() {
		final ExecutionData a = new ExecutionData(5, "Example", new boolean[] {
				false, true, false, true });
		final ExecutionData b = new ExecutionData(5, "Example", new boolean[] {
				false, false, true, true });
		a.merge(b);

		// b is merged into a:
		assertFalse(a.getProbes()[0]);
		assertTrue(a.getProbes()[1]);
		assertTrue(a.getProbes()[2]);
		assertTrue(a.getProbes()[3]);

		// b must not be modified:
		assertFalse(b.getProbes()[0]);
		assertFalse(b.getProbes()[1]);
		assertTrue(b.getProbes()[2]);
		assertTrue(b.getProbes()[3]);
	}

	@Test
	public void testMergeSubtract() {
		final ExecutionData a = new ExecutionData(5, "Example", new boolean[] {
				false, true, false, true });
		final ExecutionData b = new ExecutionData(5, "Example", new boolean[] {
				false, false, true, true });
		a.merge(b, false);

		// b is subtracted from a:
		assertFalse(a.getProbes()[0]);
		assertTrue(a.getProbes()[1]);
		assertFalse(a.getProbes()[2]);
		assertFalse(a.getProbes()[3]);

		// b must not be modified:
		assertFalse(b.getProbes()[0]);
		assertFalse(b.getProbes()[1]);
		assertTrue(b.getProbes()[2]);
		assertTrue(b.getProbes()[3]);
	}

	@Test
	public void testAssertCompatibility() {
		final ExecutionData a = new ExecutionData(5, "Example",
				new boolean[] { true });
		a.assertCompatibility(5, "Example", 1);
	}

	@Test(expected = IllegalStateException.class)
	public void testAssertCompatibilityNegative1() {
		final ExecutionData a = new ExecutionData(5, "Example",
				new boolean[] { true });
		a.assertCompatibility(55, "Example", 1);
	}

	@Test(expected = IllegalStateException.class)
	public void testAssertCompatibilityNegative2() {
		final ExecutionData a = new ExecutionData(5, "Example",
				new boolean[] { true });
		a.assertCompatibility(5, "Exxxample", 1);
	}

	@Test(expected = IllegalStateException.class)
	public void testAssertCompatibilityNegative3() {
		final ExecutionData a = new ExecutionData(5, "Example",
				new boolean[] { true });
		a.assertCompatibility(5, "Example", 3);
	}

	@Test
	public void testToString() {
		final ExecutionData a = new ExecutionData(Long.MAX_VALUE, "Example",
				new boolean[] { true });
		assertEquals("ExecutionData[name=Example, id=7fffffffffffffff]",
				a.toString());
	}

}