View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.assembly.archive.phase;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  import org.apache.maven.plugins.assembly.AssemblerConfigurationSource;
25  import org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException;
26  import org.apache.maven.plugins.assembly.archive.ArchiveCreationException;
27  import org.apache.maven.plugins.assembly.artifact.DependencyResolutionException;
28  import org.apache.maven.plugins.assembly.format.AssemblyFormattingException;
29  import org.apache.maven.plugins.assembly.model.Assembly;
30  import org.codehaus.plexus.archiver.Archiver;
31  import org.junit.Test;
32  
33  import static org.junit.Assert.assertSame;
34  
35  public class AssemblyArchiverPhaseComparatorTest {
36  
37      @Test
38      public void comparatorSortsCorrectly() throws Exception {
39          List<AssemblyArchiverPhase> items = new ArrayList<>();
40          Unordered2 u2 = new Unordered2();
41          items.add(u2);
42          Ordered2 o2 = new Ordered2();
43          items.add(o2);
44          Ordered1 o1 = new Ordered1();
45          items.add(o1);
46          Unordered1 u1 = new Unordered1();
47          items.add(u1);
48          items.sort(new AssemblyArchiverPhaseComparator());
49          assertSame(u1, items.get(0));
50          assertSame(u2, items.get(1));
51          assertSame(o1, items.get(2));
52          assertSame(o2, items.get(3));
53      }
54  
55      static class Basic implements AssemblyArchiverPhase {
56          public void execute(Assembly assembly, Archiver archiver, AssemblerConfigurationSource configSource)
57                  throws ArchiveCreationException, AssemblyFormattingException, InvalidAssemblerConfigurationException,
58                          DependencyResolutionException {}
59      }
60  
61      static class Ordered1 extends Basic implements PhaseOrder {
62          public int order() {
63              return 20;
64          }
65      }
66  
67      static class Ordered2 extends Basic implements PhaseOrder {
68          public int order() {
69              return 30;
70          }
71      }
72  
73      static class Unordered1 extends Basic {}
74  
75      static class Unordered2 extends Basic {}
76  }