1 package org.eclipse.aether.util.graph.transformer;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 }