Skip to content

Commit 9dcc230

Browse files
committed
Povide coverage for LinkSetViewAggregations
1 parent b4a02ec commit 9dcc230

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package life.qbic.compass
2+
3+
import life.qbic.compass.SignPostingProcessor.LinkSetViewAggregationMode
4+
import life.qbic.compass.processing.FailOnMultipleLinkSetViewAggregation
5+
import life.qbic.compass.processing.MergeLinkSetViewAggregation
6+
import life.qbic.compass.processing.NoLinkSetViewAggregation
7+
import life.qbic.compass.processing.TakeFirstLinkSetViewAggregation
8+
import spock.lang.Specification
9+
import spock.lang.Unroll
10+
11+
class LinkSetViewAggregationsSpec extends Specification {
12+
13+
@Unroll
14+
def "routes mode #mode to strategy type #expectedType.simpleName"() {
15+
when:
16+
def strategy = LinkSetViewAggregations.forMode(mode)
17+
18+
then:
19+
strategy != null
20+
strategy.class == expectedType
21+
22+
where:
23+
mode || expectedType
24+
LinkSetViewAggregationMode.NONE || NoLinkSetViewAggregation
25+
LinkSetViewAggregationMode.FIRST || TakeFirstLinkSetViewAggregation
26+
LinkSetViewAggregationMode.MERGE || MergeLinkSetViewAggregation
27+
LinkSetViewAggregationMode.FAIL_ON_MULTIPLE || FailOnMultipleLinkSetViewAggregation
28+
}
29+
30+
@Unroll
31+
def "returns singleton instance for mode #mode (same object on repeated calls)"() {
32+
when:
33+
def s1 = LinkSetViewAggregations.forMode(mode as LinkSetViewAggregationMode)
34+
def s2 = LinkSetViewAggregations.forMode(mode as LinkSetViewAggregationMode)
35+
def s3 = LinkSetViewAggregations.forMode(mode as LinkSetViewAggregationMode)
36+
37+
then: "Groovy identity check"
38+
s1.is(s2)
39+
s2.is(s3)
40+
41+
where:
42+
mode << LinkSetViewAggregationMode.values()
43+
}
44+
45+
def "different modes return different instances (no accidental aliasing)"() {
46+
when:
47+
def strategies = LinkSetViewAggregationMode.values()
48+
.collect { LinkSetViewAggregations.forMode(it) }
49+
50+
then: "all strategies are pairwise distinct by identity"
51+
def identities = strategies.collect { System.identityHashCode(it) }
52+
identities.size() == identities.toSet().size()
53+
54+
and: "sanity: exactly one instance per mode"
55+
strategies.size() == LinkSetViewAggregationMode.values().length
56+
}
57+
58+
def "null mode throws NullPointerException"() {
59+
when:
60+
LinkSetViewAggregations.forMode(null)
61+
62+
then:
63+
thrown(NullPointerException)
64+
}
65+
}

0 commit comments

Comments
 (0)