View Javadoc
1   package org.apache.maven.plugins.assembly.archive.phase;
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 org.apache.maven.plugins.assembly.AssemblerConfigurationSource;
23  import org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException;
24  import org.apache.maven.plugins.assembly.archive.ArchiveCreationException;
25  import org.apache.maven.plugins.assembly.artifact.DependencyResolutionException;
26  import org.apache.maven.plugins.assembly.format.AssemblyFormattingException;
27  import org.apache.maven.plugins.assembly.model.Assembly;
28  import org.codehaus.plexus.archiver.Archiver;
29  import org.junit.Test;
30  
31  import java.util.ArrayList;
32  import java.util.Collections;
33  import java.util.List;
34  
35  import static org.junit.Assert.assertSame;
36  
37  public class AssemblyArchiverPhaseComparatorTest
38  {
39  
40      @Test
41      public void comparatorSortsCorrectly()
42          throws Exception
43      {
44          List<AssemblyArchiverPhase> items = new ArrayList<>();
45          Unordered2 u2 = new Unordered2();
46          items.add( u2 );
47          Ordered2 o2 = new Ordered2();
48          items.add( o2 );
49          Ordered1 o1 = new Ordered1();
50          items.add( o1 );
51          Unordered1 u1 = new Unordered1();
52          items.add( u1 );
53          Collections.sort( items, new AssemblyArchiverPhaseComparator() );
54          assertSame( u1, items.get( 0 ) );
55          assertSame( u2, items.get( 1 ) );
56          assertSame( o1, items.get( 2 ) );
57          assertSame( o2, items.get( 3 ) );
58      }
59  
60      class Basic
61          implements AssemblyArchiverPhase
62      {
63          public void execute( Assembly assembly, Archiver archiver, AssemblerConfigurationSource configSource )
64              throws ArchiveCreationException, AssemblyFormattingException, InvalidAssemblerConfigurationException,
65              DependencyResolutionException
66          {
67  
68          }
69      }
70  
71      class Ordered1
72          extends Basic
73          implements PhaseOrder
74      {
75          public int order()
76          {
77              return 20;
78          }
79      }
80  
81      class Ordered2
82          extends Basic
83          implements PhaseOrder
84      {
85          public int order()
86          {
87              return 30;
88          }
89      }
90  
91      class Unordered1
92          extends Basic
93      {
94      }
95  
96      class Unordered2
97          extends Basic
98      {
99      }
100 }