001package org.eclipse.aether.util.graph.visitor; 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 java.util.List; 025 026import org.eclipse.aether.graph.DependencyNode; 027import org.eclipse.aether.internal.test.util.DependencyGraphParser; 028import org.junit.Test; 029 030public class PostorderNodeListGeneratorTest 031{ 032 033 private DependencyNode parse( String resource ) 034 throws Exception 035 { 036 return new DependencyGraphParser( "visitor/ordered-list/" ).parseResource( resource ); 037 } 038 039 private void assertSequence( List<DependencyNode> actual, String... expected ) 040 { 041 assertEquals( actual.toString(), expected.length, actual.size() ); 042 for ( int i = 0; i < expected.length; i++ ) 043 { 044 DependencyNode node = actual.get( i ); 045 assertEquals( actual.toString(), expected[i], node.getDependency().getArtifact().getArtifactId() ); 046 } 047 } 048 049 @Test 050 public void testOrdering() 051 throws Exception 052 { 053 DependencyNode root = parse( "simple.txt" ); 054 055 PostorderNodeListGenerator visitor = new PostorderNodeListGenerator(); 056 root.accept( visitor ); 057 058 assertSequence( visitor.getNodes(), "c", "b", "e", "d", "a" ); 059 } 060 061 @Test 062 public void testDuplicateSuppression() 063 throws Exception 064 { 065 DependencyNode root = parse( "cycles.txt" ); 066 067 PostorderNodeListGenerator visitor = new PostorderNodeListGenerator(); 068 root.accept( visitor ); 069 070 assertSequence( visitor.getNodes(), "c", "b", "e", "d", "a" ); 071 } 072 073}