001package org.eclipse.aether.util.graph.transformer; 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.eclipse.aether.util.graph.transformer.ConflictIdSorter.ConflictId; 025import org.eclipse.aether.util.graph.transformer.ConflictIdSorter.RootQueue; 026import org.junit.Test; 027 028public class RootQueueTest 029{ 030 031 @Test 032 public void testIsEmpty() 033 { 034 ConflictId id = new ConflictId( "a", 0 ); 035 RootQueue queue = new RootQueue( 10 ); 036 assertTrue( queue.isEmpty() ); 037 queue.add( id ); 038 assertFalse( queue.isEmpty() ); 039 assertSame( id, queue.remove() ); 040 assertTrue( queue.isEmpty() ); 041 } 042 043 @Test 044 public void testAddSortsByDepth() 045 { 046 ConflictId id1 = new ConflictId( "a", 0 ); 047 ConflictId id2 = new ConflictId( "b", 1 ); 048 ConflictId id3 = new ConflictId( "c", 2 ); 049 ConflictId id4 = new ConflictId( "d", 3 ); 050 051 RootQueue queue = new RootQueue( 10 ); 052 queue.add( id1 ); 053 queue.add( id2 ); 054 queue.add( id3 ); 055 queue.add( id4 ); 056 assertSame( id1, queue.remove() ); 057 assertSame( id2, queue.remove() ); 058 assertSame( id3, queue.remove() ); 059 assertSame( id4, queue.remove() ); 060 061 queue = new RootQueue( 10 ); 062 queue.add( id4 ); 063 queue.add( id3 ); 064 queue.add( id2 ); 065 queue.add( id1 ); 066 assertSame( id1, queue.remove() ); 067 assertSame( id2, queue.remove() ); 068 assertSame( id3, queue.remove() ); 069 assertSame( id4, queue.remove() ); 070 } 071 072 @Test 073 public void testAddWithArrayCompact() 074 { 075 ConflictId id = new ConflictId( "a", 0 ); 076 077 RootQueue queue = new RootQueue( 10 ); 078 assertTrue( queue.isEmpty() ); 079 queue.add( id ); 080 assertFalse( queue.isEmpty() ); 081 assertSame( id, queue.remove() ); 082 assertTrue( queue.isEmpty() ); 083 queue.add( id ); 084 assertFalse( queue.isEmpty() ); 085 assertSame( id, queue.remove() ); 086 assertTrue( queue.isEmpty() ); 087 } 088 089 @Test 090 public void testAddMinimumAfterSomeRemoves() 091 { 092 ConflictId id1 = new ConflictId( "a", 0 ); 093 ConflictId id2 = new ConflictId( "b", 1 ); 094 ConflictId id3 = new ConflictId( "c", 2 ); 095 096 RootQueue queue = new RootQueue( 10 ); 097 queue.add( id2 ); 098 queue.add( id3 ); 099 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}