1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.internal.impl;
20
21 import org.junit.jupiter.api.Test;
22
23 import static org.junit.jupiter.api.Assertions.*;
24
25 public class PrioritizedComponentTest {
26
27 @Test
28 void testIsDisabled() {
29 assertTrue(new PrioritizedComponent<>("", String.class, Float.NaN, 0).isDisabled());
30 assertFalse(new PrioritizedComponent<>("", String.class, 0, 0).isDisabled());
31 assertFalse(new PrioritizedComponent<>("", String.class, 1, 0).isDisabled());
32 assertFalse(new PrioritizedComponent<>("", String.class, -1, 0).isDisabled());
33 }
34
35 @Test
36 void testCompareTo() {
37 assertCompare(0, Float.NaN, Float.NaN);
38 assertCompare(0, 0, 0);
39
40 assertCompare(1, 0, 1);
41 assertCompare(1, 2, Float.POSITIVE_INFINITY);
42 assertCompare(1, Float.NEGATIVE_INFINITY, -3);
43
44 assertCompare(1, Float.NaN, 0);
45 assertCompare(1, Float.NaN, -1);
46 assertCompare(1, Float.NaN, Float.NEGATIVE_INFINITY);
47 assertCompare(1, Float.NaN, Float.POSITIVE_INFINITY);
48
49 assertCompare(-1, Float.NaN, 0, 1);
50 assertCompare(-1, 10, 0, 1);
51 }
52
53 private void assertCompare(int expected, float priority1, float priority2) {
54 PrioritizedComponent<?> one = new PrioritizedComponent<>("", String.class, priority1, 0);
55 PrioritizedComponent<?> two = new PrioritizedComponent<>("", String.class, priority2, 0);
56 assertEquals(expected, one.compareTo(two));
57 assertEquals(-expected, two.compareTo(one));
58 }
59
60 private void assertCompare(int expected, float priority, int index1, int index2) {
61 PrioritizedComponent<?> one = new PrioritizedComponent<>("", String.class, priority, index1);
62 PrioritizedComponent<?> two = new PrioritizedComponent<>("", String.class, priority, index2);
63 assertEquals(expected, one.compareTo(two));
64 assertEquals(-expected, two.compareTo(one));
65 }
66 }