001package org.eclipse.aether.internal.impl;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 * 
012 *  http://www.apache.org/licenses/LICENSE-2.0
013 * 
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import static org.junit.Assert.*;
023
024import org.junit.Test;
025
026public class PrioritizedComponentTest
027{
028
029    @Test
030    public void testIsDisabled()
031    {
032        assertTrue(new PrioritizedComponent<>( "", String.class, Float.NaN, 0 ).isDisabled() );
033        assertFalse(new PrioritizedComponent<>( "", String.class, 0, 0 ).isDisabled() );
034        assertFalse(new PrioritizedComponent<>( "", String.class, 1, 0 ).isDisabled() );
035        assertFalse(new PrioritizedComponent<>( "", String.class, -1, 0 ).isDisabled() );
036    }
037
038    @Test
039    public void testCompareTo()
040    {
041        assertCompare( 0, Float.NaN, Float.NaN );
042        assertCompare( 0, 0, 0 );
043
044        assertCompare( 1, 0, 1 );
045        assertCompare( 1, 2, Float.POSITIVE_INFINITY );
046        assertCompare( 1, Float.NEGATIVE_INFINITY, -3 );
047
048        assertCompare( 1, Float.NaN, 0 );
049        assertCompare( 1, Float.NaN, -1 );
050        assertCompare( 1, Float.NaN, Float.NEGATIVE_INFINITY );
051        assertCompare( 1, Float.NaN, Float.POSITIVE_INFINITY );
052
053        assertCompare( -1, Float.NaN, 0, 1 );
054        assertCompare( -1, 10, 0, 1 );
055    }
056
057    private void assertCompare( int expected, float priority1, float priority2 )
058    {
059        PrioritizedComponent<?> one = new PrioritizedComponent<>( "", String.class, priority1, 0 );
060        PrioritizedComponent<?> two = new PrioritizedComponent<>( "", String.class, priority2, 0 );
061        assertEquals( expected, one.compareTo( two ) );
062        assertEquals( -expected, two.compareTo( one ) );
063    }
064
065    private void assertCompare( int expected, float priority, int index1, int index2 )
066    {
067        PrioritizedComponent<?> one = new PrioritizedComponent<>( "", String.class, priority, index1 );
068        PrioritizedComponent<?> two = new PrioritizedComponent<>( "", String.class, priority, index2 );
069        assertEquals( expected, one.compareTo( two ) );
070        assertEquals( -expected, two.compareTo( one ) );
071    }
072
073}