View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.eclipse.aether.internal.impl;
20  
21  import org.junit.Test;
22  
23  import static org.junit.Assert.*;
24  
25  public class PrioritizedComponentTest {
26  
27      @Test
28      public 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      public 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  }