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
|
/*******************************************************************************
* Copyright (c) 2009, 2011 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.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
/**
* Unit tests for {@link SessionInfoStore}.
*/
public class SessionInfoStoreTest {
private SessionInfoStore store;
@Before
public void setup() {
store = new SessionInfoStore();
}
@Test
public void testEmpty() {
assertEquals(Collections.emptyList(), store.getInfos());
assertTrue(store.isEmpty());
}
@Test
public void testIsEmpty() {
store.visitSessionInfo(new SessionInfo("A", 123, 456));
assertFalse(store.isEmpty());
}
@Test
public void testGetInfos() {
final SessionInfo a = new SessionInfo("A", 12345, 500000);
store.visitSessionInfo(a);
final SessionInfo b = new SessionInfo("B", 12345, 400000);
store.visitSessionInfo(b);
final SessionInfo c = new SessionInfo("C", 12345, 600000);
store.visitSessionInfo(c);
assertEquals(Arrays.asList(b, a, c), store.getInfos());
}
@Test
public void testGetMergedEmpty() {
final SessionInfo info = store.getMerged("MERGE");
assertEquals("MERGE", info.getId());
assertEquals(0, info.getStartTimeStamp());
assertEquals(0, info.getDumpTimeStamp());
}
@Test
public void testGetMerged() {
store.visitSessionInfo(new SessionInfo("A", 23456, 500000));
store.visitSessionInfo(new SessionInfo("B", 12345, 400000));
store.visitSessionInfo(new SessionInfo("C", 34567, 600000));
final SessionInfo info = store.getMerged("MERGE");
assertEquals("MERGE", info.getId());
assertEquals(12345, info.getStartTimeStamp());
assertEquals(600000, info.getDumpTimeStamp());
}
@Test
public void testAccept() {
final SessionInfo a = new SessionInfo("A", 12345, 500000);
store.visitSessionInfo(a);
final SessionInfo b = new SessionInfo("B", 12345, 400000);
store.visitSessionInfo(b);
final SessionInfo c = new SessionInfo("C", 12345, 600000);
store.visitSessionInfo(c);
final List<SessionInfo> actual = new ArrayList<SessionInfo>();
store.accept(new ISessionInfoVisitor() {
public void visitSessionInfo(SessionInfo info) {
actual.add(info);
}
});
assertEquals(Arrays.asList(b, a, c), actual);
}
}
|