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.lifecycle.mapping;
20  
21  import java.util.Arrays;
22  import java.util.List;
23  
24  import org.junit.jupiter.api.Test;
25  
26  import static org.junit.jupiter.api.Assertions.assertEquals;
27  import static org.junit.jupiter.api.Assertions.assertNotNull;
28  import static org.junit.jupiter.api.Assertions.assertNull;
29  
30  /**
31   */
32  class LifecyclePhaseTest {
33      @Test
34      void testToString() {
35          LifecyclePhase phase = new LifecyclePhase();
36          assertEquals("", phase.toString());
37  
38          LifecycleMojo mojo1 = new LifecycleMojo();
39          mojo1.setGoal("jar:jar");
40          phase.setMojos(Arrays.asList(mojo1));
41          assertEquals("jar:jar", phase.toString());
42  
43          LifecycleMojo mojo2 = new LifecycleMojo();
44          mojo2.setGoal("war:war");
45          phase.setMojos(Arrays.asList(mojo1, mojo2));
46          assertEquals("jar:jar,war:war", phase.toString());
47      }
48  
49      @Test
50      void testSet() {
51          LifecyclePhase phase = new LifecyclePhase();
52          assertNull(phase.getMojos());
53  
54          phase.set("");
55          assertNotNull(phase.getMojos());
56          assertEquals(0, phase.getMojos().size());
57  
58          phase.set("jar:jar, war:war");
59  
60          List<LifecycleMojo> mojos = phase.getMojos();
61          assertNotNull(mojos);
62          assertEquals(2, mojos.size());
63  
64          LifecycleMojo mojo1 = mojos.get(0);
65          assertNotNull(mojo1);
66          assertEquals("jar:jar", mojo1.getGoal());
67  
68          LifecycleMojo mojo2 = mojos.get(1);
69          assertNotNull(mojo2);
70          assertEquals("war:war", mojo2.getGoal());
71      }
72  }