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