2525import org .apache .maven .plugins .war .Overlay ;
2626import org .apache .maven .plugins .war .stub .MavenProjectArtifactsStub ;
2727import org .apache .maven .plugins .war .stub .WarArtifactStub ;
28- import org .codehaus . plexus . PlexusTestCase ;
28+ import org .junit . jupiter . api . Test ;
2929
3030import static org .apache .maven .plugins .war .Overlay .DEFAULT_EXCLUDES ;
3131import static org .apache .maven .plugins .war .Overlay .DEFAULT_INCLUDES ;
32+ import static org .junit .jupiter .api .Assertions .assertEquals ;
33+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
34+ import static org .junit .jupiter .api .Assertions .assertThrows ;
3235
3336/**
3437 * @author Stephane Nicoll
3538 */
36- public class OverlayManagerTest extends PlexusTestCase {
39+ class OverlayManagerTest {
3740
41+ @ Test
3842 public void testEmptyProject () throws Exception {
3943 final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub ();
4044 final List <Overlay > overlays = new ArrayList <>();
41- try {
42- final Overlay currentProjectOverlay = Overlay .createInstance ();
43- OverlayManager manager =
44- new OverlayManager (overlays , project , DEFAULT_INCLUDES , DEFAULT_EXCLUDES , currentProjectOverlay );
45- assertNotNull (manager .getOverlays ());
46- assertEquals (1 , manager .getOverlays ().size ());
47- assertEquals (currentProjectOverlay , manager .getOverlays ().get (0 ));
48- } catch (InvalidOverlayConfigurationException e ) {
49- e .printStackTrace ();
50- fail ("Should not have failed to validate a valid overly config " + e .getMessage ());
51- }
45+ final Overlay currentProjectOverlay = Overlay .createInstance ();
46+ OverlayManager manager =
47+ new OverlayManager (overlays , project , DEFAULT_INCLUDES , DEFAULT_EXCLUDES , currentProjectOverlay );
48+ assertNotNull (manager .getOverlays ());
49+ assertEquals (1 , manager .getOverlays ().size ());
50+ assertEquals (currentProjectOverlay , manager .getOverlays ().get (0 ));
5251 }
5352
54- public void testAutodetectSimpleOverlay (Overlay currentProjectOverlay ) throws Exception {
53+ // TODO investigate what test should do ....
54+ void testAutodetectSimpleOverlay (Overlay currentProjectOverlay ) throws Exception {
5555
5656 final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub ();
5757 final ArtifactStub first = newWarArtifact ("test" , "test-webapp" );
5858 project .addArtifact (first );
5959
6060 final List <Overlay > overlays = new ArrayList <>();
6161
62- try {
63- final Overlay overlay = currentProjectOverlay ;
64- OverlayManager manager = new OverlayManager (overlays , project , DEFAULT_INCLUDES , DEFAULT_EXCLUDES , overlay );
65- assertNotNull (manager .getOverlays ());
66- assertEquals (2 , manager .getOverlays ().size ());
67- assertEquals (overlay , manager .getOverlays ().get (0 ));
68- assertEquals (new DefaultOverlay (first ), manager .getOverlays ().get (1 ));
69- } catch (InvalidOverlayConfigurationException e ) {
70- e .printStackTrace ();
71- fail ("Should not have failed to validate a valid overlay config " + e .getMessage ());
72- }
62+ final Overlay overlay = currentProjectOverlay ;
63+ OverlayManager manager = new OverlayManager (overlays , project , DEFAULT_INCLUDES , DEFAULT_EXCLUDES , overlay );
64+ assertNotNull (manager .getOverlays ());
65+ assertEquals (2 , manager .getOverlays ().size ());
66+ assertEquals (overlay , manager .getOverlays ().get (0 ));
67+ assertEquals (new DefaultOverlay (first ), manager .getOverlays ().get (1 ));
7368 }
7469
75- public void testSimpleOverlay () throws Exception {
70+ @ Test
71+ void testSimpleOverlay () throws Exception {
7672
7773 final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub ();
7874 final ArtifactStub first = newWarArtifact ("test" , "test-webapp" );
@@ -81,21 +77,17 @@ public void testSimpleOverlay() throws Exception {
8177 final List <Overlay > overlays = new ArrayList <>();
8278 overlays .add (new DefaultOverlay (first ));
8379
84- try {
85- final Overlay currentProjectOverlay = Overlay .createInstance ();
86- OverlayManager manager =
87- new OverlayManager (overlays , project , DEFAULT_INCLUDES , DEFAULT_EXCLUDES , currentProjectOverlay );
88- assertNotNull (manager .getOverlays ());
89- assertEquals (2 , manager .getOverlays ().size ());
90- assertEquals (Overlay .createInstance (), manager .getOverlays ().get (0 ));
91- assertEquals (overlays .get (0 ), manager .getOverlays ().get (1 ));
92- } catch (InvalidOverlayConfigurationException e ) {
93- e .printStackTrace ();
94- fail ("Should not have failed to validate a valid overlay config " + e .getMessage ());
95- }
80+ final Overlay currentProjectOverlay = Overlay .createInstance ();
81+ OverlayManager manager =
82+ new OverlayManager (overlays , project , DEFAULT_INCLUDES , DEFAULT_EXCLUDES , currentProjectOverlay );
83+ assertNotNull (manager .getOverlays ());
84+ assertEquals (2 , manager .getOverlays ().size ());
85+ assertEquals (Overlay .createInstance (), manager .getOverlays ().get (0 ));
86+ assertEquals (overlays .get (0 ), manager .getOverlays ().get (1 ));
9687 }
9788
98- public void testUnknownOverlay () throws Exception {
89+ @ Test
90+ void testUnknownOverlay () throws Exception {
9991
10092 final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub ();
10193 final ArtifactStub first = newWarArtifact ("test" , "test-webapp" );
@@ -104,16 +96,14 @@ public void testUnknownOverlay() throws Exception {
10496 final List <Overlay > overlays = new ArrayList <>();
10597 overlays .add (new Overlay ("test" , "test-webapp-2" ));
10698
107- try {
108- final Overlay currentProjectOverlay = Overlay .createInstance ();
109- new OverlayManager (overlays , project , DEFAULT_INCLUDES , DEFAULT_EXCLUDES , currentProjectOverlay );
110- fail ("Should have failed to validate an unknown overlay" );
111- } catch (InvalidOverlayConfigurationException e ) {
112- // OK
113- }
99+ final Overlay currentProjectOverlay = Overlay .createInstance ();
100+ assertThrows (
101+ InvalidOverlayConfigurationException .class ,
102+ () -> new OverlayManager (overlays , project , DEFAULT_INCLUDES , DEFAULT_EXCLUDES , currentProjectOverlay ));
114103 }
115104
116- public void testCustomCurrentProject () throws Exception {
105+ @ Test
106+ void testCustomCurrentProject () throws Exception {
117107
118108 final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub ();
119109 final ArtifactStub first = newWarArtifact ("test" , "test-webapp" );
@@ -126,22 +116,17 @@ public void testCustomCurrentProject() throws Exception {
126116 final Overlay currentProjectOverlay = Overlay .createInstance ();
127117 overlays .add (currentProjectOverlay );
128118
129- try {
130- OverlayManager manager =
131- new OverlayManager (overlays , project , DEFAULT_INCLUDES , DEFAULT_EXCLUDES , currentProjectOverlay );
132- assertNotNull (manager .getOverlays ());
133- assertEquals (3 , manager .getOverlays ().size ());
134- assertEquals (overlays .get (0 ), manager .getOverlays ().get (0 ));
135- assertEquals (currentProjectOverlay , manager .getOverlays ().get (1 ));
136- assertEquals (new DefaultOverlay (second ), manager .getOverlays ().get (2 ));
137-
138- } catch (InvalidOverlayConfigurationException e ) {
139- e .printStackTrace ();
140- fail ("Should not have failed to validate a valid overlay config " + e .getMessage ());
141- }
119+ OverlayManager manager =
120+ new OverlayManager (overlays , project , DEFAULT_INCLUDES , DEFAULT_EXCLUDES , currentProjectOverlay );
121+ assertNotNull (manager .getOverlays ());
122+ assertEquals (3 , manager .getOverlays ().size ());
123+ assertEquals (overlays .get (0 ), manager .getOverlays ().get (0 ));
124+ assertEquals (currentProjectOverlay , manager .getOverlays ().get (1 ));
125+ assertEquals (new DefaultOverlay (second ), manager .getOverlays ().get (2 ));
142126 }
143127
144- public void testOverlaysWithSameArtifactAndGroupId () throws Exception {
128+ @ Test
129+ void testOverlaysWithSameArtifactAndGroupId () throws Exception {
145130
146131 final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub ();
147132 final ArtifactStub first = newWarArtifact ("test" , "test-webapp" );
@@ -154,24 +139,18 @@ public void testOverlaysWithSameArtifactAndGroupId() throws Exception {
154139 overlays .add (new DefaultOverlay (first ));
155140 overlays .add (new DefaultOverlay (second ));
156141
157- try {
158- final Overlay currentProjectOverlay = Overlay .createInstance ();
159- OverlayManager manager =
160- new OverlayManager (overlays , project , DEFAULT_INCLUDES , DEFAULT_EXCLUDES , currentProjectOverlay );
161- assertNotNull (manager .getOverlays ());
162- assertEquals (3 , manager .getOverlays ().size ());
163- assertEquals (currentProjectOverlay , manager .getOverlays ().get (0 ));
164- assertEquals (overlays .get (0 ), manager .getOverlays ().get (1 ));
165- assertEquals (overlays .get (1 ), manager .getOverlays ().get (2 ));
166-
167- } catch (InvalidOverlayConfigurationException e ) {
168- e .printStackTrace ();
169- fail ("Should not have failed to validate a valid overlay config " + e .getMessage ());
170- }
142+ final Overlay currentProjectOverlay = Overlay .createInstance ();
143+ OverlayManager manager =
144+ new OverlayManager (overlays , project , DEFAULT_INCLUDES , DEFAULT_EXCLUDES , currentProjectOverlay );
145+ assertNotNull (manager .getOverlays ());
146+ assertEquals (3 , manager .getOverlays ().size ());
147+ assertEquals (currentProjectOverlay , manager .getOverlays ().get (0 ));
148+ assertEquals (overlays .get (0 ), manager .getOverlays ().get (1 ));
149+ assertEquals (overlays .get (1 ), manager .getOverlays ().get (2 ));
171150 }
172151
173152 protected ArtifactStub newWarArtifact (String groupId , String artifactId , String classifier ) {
174- final WarArtifactStub a = new WarArtifactStub (getBasedir () );
153+ final WarArtifactStub a = new WarArtifactStub ("" );
175154 a .setGroupId (groupId );
176155 a .setArtifactId (artifactId );
177156 if (classifier != null ) {
0 commit comments