View Javadoc
1   package org.eclipse.aether.util.graph.transformer;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   * 
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   * 
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import static org.junit.Assert.*;
23  
24  import org.eclipse.aether.util.graph.transformer.ConflictIdSorter.ConflictId;
25  import org.eclipse.aether.util.graph.transformer.ConflictIdSorter.RootQueue;
26  import org.junit.Test;
27  
28  public class RootQueueTest
29  {
30  
31      @Test
32      public void testIsEmpty()
33      {
34          ConflictId id = new ConflictId( "a", 0 );
35          RootQueue queue = new RootQueue( 10 );
36          assertTrue( queue.isEmpty() );
37          queue.add( id );
38          assertFalse( queue.isEmpty() );
39          assertSame( id, queue.remove() );
40          assertTrue( queue.isEmpty() );
41      }
42  
43      @Test
44      public void testAddSortsByDepth()
45      {
46          ConflictId id1 = new ConflictId( "a", 0 );
47          ConflictId id2 = new ConflictId( "b", 1 );
48          ConflictId id3 = new ConflictId( "c", 2 );
49          ConflictId id4 = new ConflictId( "d", 3 );
50  
51          RootQueue queue = new RootQueue( 10 );
52          queue.add( id1 );
53          queue.add( id2 );
54          queue.add( id3 );
55          queue.add( id4 );
56          assertSame( id1, queue.remove() );
57          assertSame( id2, queue.remove() );
58          assertSame( id3, queue.remove() );
59          assertSame( id4, queue.remove() );
60  
61          queue = new RootQueue( 10 );
62          queue.add( id4 );
63          queue.add( id3 );
64          queue.add( id2 );
65          queue.add( id1 );
66          assertSame( id1, queue.remove() );
67          assertSame( id2, queue.remove() );
68          assertSame( id3, queue.remove() );
69          assertSame( id4, queue.remove() );
70      }
71  
72      @Test
73      public void testAddWithArrayCompact()
74      {
75          ConflictId id = new ConflictId( "a", 0 );
76  
77          RootQueue queue = new RootQueue( 10 );
78          assertTrue( queue.isEmpty() );
79          queue.add( id );
80          assertFalse( queue.isEmpty() );
81          assertSame( id, queue.remove() );
82          assertTrue( queue.isEmpty() );
83          queue.add( id );
84          assertFalse( queue.isEmpty() );
85          assertSame( id, queue.remove() );
86          assertTrue( queue.isEmpty() );
87      }
88  
89      @Test
90      public void testAddMinimumAfterSomeRemoves()
91      {
92          ConflictId id1 = new ConflictId( "a", 0 );
93          ConflictId id2 = new ConflictId( "b", 1 );
94          ConflictId id3 = new ConflictId( "c", 2 );
95  
96          RootQueue queue = new RootQueue( 10 );
97          queue.add( id2 );
98          queue.add( id3 );
99          assertSame( id2, queue.remove() );
100         queue.add( id1 );
101         assertSame( id1, queue.remove() );
102         assertSame( id3, queue.remove() );
103         assertTrue( queue.isEmpty() );
104     }
105 
106 }