From 307362432a3c6193f7ac9c55f12dfafc517b5a90 Mon Sep 17 00:00:00 2001 From: Juul Hobert Date: Fri, 15 Mar 2024 15:38:29 +0100 Subject: [PATCH] Renamed class, formatter can be made functional with maven 3.x --- .../help/DefaultInputLocationFormatter.java | 14 +- .../maven/plugins/help/EffectivePomMojo.java | 20 +-- .../help/ImportedFromLocationFormatter.java | 124 ++++++++++++++++ .../help/InputLocationFormatterFactory.java | 28 ++-- .../help/Maven4InputLocationFormatter.java | 134 ------------------ .../DefaultInputLocationFormatterTest.java | 48 +++---- ...=> ImportedFromLocationFormatterTest.java} | 33 ++--- .../InputLocationFormatterFactoryTest.java | 14 +- 8 files changed, 187 insertions(+), 228 deletions(-) create mode 100644 src/main/java/org/apache/maven/plugins/help/ImportedFromLocationFormatter.java delete mode 100644 src/main/java/org/apache/maven/plugins/help/Maven4InputLocationFormatter.java rename src/test/java/org/apache/maven/plugins/help/{Maven4InputLocationFormatterTest.java => ImportedFromLocationFormatterTest.java} (76%) diff --git a/src/main/java/org/apache/maven/plugins/help/DefaultInputLocationFormatter.java b/src/main/java/org/apache/maven/plugins/help/DefaultInputLocationFormatter.java index 41c67160..856c6dd1 100644 --- a/src/main/java/org/apache/maven/plugins/help/DefaultInputLocationFormatter.java +++ b/src/main/java/org/apache/maven/plugins/help/DefaultInputLocationFormatter.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.help; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.help; import org.apache.maven.model.InputLocation; import org.apache.maven.model.InputSource; @@ -26,21 +25,18 @@ /** * Maven 3.x-based implementation of {@link InputLocation.StringFormatter}. */ -public class DefaultInputLocationFormatter extends InputLocation.StringFormatter -{ +public class DefaultInputLocationFormatter extends InputLocation.StringFormatter { @Override - public String toString( InputLocation location ) - { + public String toString(InputLocation location) { InputSource source = location.getSource(); String s = source.getModelId(); // by default, display modelId - if ( StringUtils.isBlank( s ) || s.contains( "[unknown-version]" ) ) - { + if (StringUtils.isBlank(s) || s.contains("[unknown-version]")) { // unless it is blank or does not provide version information s = source.toString(); } - return '}' + s + ( ( location.getLineNumber() >= 0 ) ? ", line " + location.getLineNumber() : "" ) + ' '; + return '}' + s + ((location.getLineNumber() >= 0) ? ", line " + location.getLineNumber() : "") + ' '; } } diff --git a/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java b/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java index 4e421487..824e071b 100644 --- a/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java @@ -24,8 +24,6 @@ import java.util.List; import java.util.Properties; -import org.apache.maven.model.InputLocation; -import org.apache.maven.model.InputSource; import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Writer; import org.apache.maven.model.io.xpp3.MavenXpp3WriterEx; @@ -175,7 +173,7 @@ private void writeEffectivePom(MavenProject project, XMLWriter writer) throws Mo try { if (verbose) { MavenXpp3WriterEx mavenXpp3WriterEx = new MavenXpp3WriterEx(); - mavenXpp3WriterEx.setStringFormatter(new InputLocationStringFormatter()); + mavenXpp3WriterEx.setStringFormatter(InputLocationFormatterFactory.produce(getLog(), project)); mavenXpp3WriterEx.write(sWriter, pom); } else { new MavenXpp3Writer().write(sWriter, pom); @@ -202,20 +200,4 @@ private static void cleanModel(Model pom) { properties.putAll(pom.getProperties()); pom.setProperties(properties); } - - private static class InputLocationStringFormatter extends InputLocation.StringFormatter { - @Override - public String toString(InputLocation location) { - InputSource source = location.getSource(); - - String s = source.getModelId(); // by default, display modelId - - if (StringUtils.isBlank(s) || s.contains("[unknown-version]")) { - // unless it is blank or does not provide version information - s = source.toString(); - } - - return '}' + s + ((location.getLineNumber() >= 0) ? ", line " + location.getLineNumber() : "") + ' '; - } - } } diff --git a/src/main/java/org/apache/maven/plugins/help/ImportedFromLocationFormatter.java b/src/main/java/org/apache/maven/plugins/help/ImportedFromLocationFormatter.java new file mode 100644 index 00000000..b3716d42 --- /dev/null +++ b/src/main/java/org/apache/maven/plugins/help/ImportedFromLocationFormatter.java @@ -0,0 +1,124 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.plugins.help; + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Map; +import java.util.Set; + +import org.apache.maven.model.Dependency; +import org.apache.maven.model.InputLocation; +import org.apache.maven.model.InputSource; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.StringUtils; + +/** + * Implementation of {@link InputLocation.StringFormatter}. Enhances the default implementation with support for + * following "references" (caused by e.g. dependency management imports). + */ +public class ImportedFromLocationFormatter extends InputLocation.StringFormatter { + private final Method getImportedFromMethod; + private final MavenProject project; + + public ImportedFromLocationFormatter(final Method getImportedFromMethod, final MavenProject project) { + this.getImportedFromMethod = getImportedFromMethod; + this.project = project; + } + + @Override + public String toString(InputLocation location) { + InputSource source = location.getSource(); + + String s = source.getModelId(); // by default, display modelId + + if (StringUtils.isBlank(s) || s.contains("[unknown-version]")) { + // unless it is blank or does not provide version information + s = source.toString(); + } + + InputLocation importedFrom = getImportedFrom(location); + + StringBuilder p = new StringBuilder(); + + while (importedFrom != null) { + p.append(" from ").append(importedFrom.getSource().getModelId()); + importedFrom = getImportedFrom(importedFrom); + } + + return '}' + s + ((location.getLineNumber() >= 0) ? ", line " + location.getLineNumber() : "") + p; + } + + protected InputLocation getImportedFrom(final InputLocation location) { + try { + InputLocation result = (InputLocation) getImportedFromMethod.invoke(location); + + if (result == null && project != null) { + for (Dependency dependency : project.getDependencyManagement().getDependencies()) { + // Until a new maven api model is released, we need to use reflection to access the locations + Set locationKeys = getLocationKeys(dependency); + for (Object key : locationKeys) { + if (!(key instanceof String)) { + throw new RuntimeException( + "Expected a String, got " + key.getClass().getName()); + } + + InputLocation dependencyLocation = dependency.getLocation(key); + if (dependencyLocation != null + && dependencyLocation.toString().equals(location.toString())) { + result = (InputLocation) Dependency.class + .getMethod("getImportedFrom") + .invoke(dependency); + break; + } + } + } + } + + return result; + } catch (IllegalAccessException + | InvocationTargetException + | NoSuchMethodException + | NoSuchFieldException + | ClassNotFoundException e) { + throw new RuntimeException(e); + } + } + + private Set getLocationKeys(Dependency dependency) + throws NoSuchFieldException, IllegalAccessException, ClassNotFoundException { + Field delegateField = Class.forName("org.apache.maven.model.BaseObject").getDeclaredField("delegate"); + delegateField.setAccessible(true); + Object delegate = delegateField.get(dependency); + delegateField.setAccessible(false); + + Field locationsField = delegate.getClass().getDeclaredField("locations"); + locationsField.setAccessible(true); + Object locations = locationsField.get(delegate); + locationsField.setAccessible(false); + + if (!(locations instanceof Map)) { + throw new RuntimeException( + "Expected a Map, got " + locations.getClass().getName()); + } + + return ((Map) locations).keySet(); + } +} diff --git a/src/main/java/org/apache/maven/plugins/help/InputLocationFormatterFactory.java b/src/main/java/org/apache/maven/plugins/help/InputLocationFormatterFactory.java index 8712f8da..048758c0 100644 --- a/src/main/java/org/apache/maven/plugins/help/InputLocationFormatterFactory.java +++ b/src/main/java/org/apache/maven/plugins/help/InputLocationFormatterFactory.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.help; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,33 +16,29 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.help; + +import java.lang.reflect.Method; import org.apache.maven.model.InputLocation; import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; -import java.lang.reflect.Method; - /** * Selects the most suitable implementation for {@link InputLocation.StringFormatter}. */ -public class InputLocationFormatterFactory -{ +public class InputLocationFormatterFactory { static Class inputLocationClass = InputLocation.class; - public static InputLocation.StringFormatter produce( final Log log, final MavenProject project ) - { - try - { + public static InputLocation.StringFormatter produce(final Log log, final MavenProject project) { + try { // This method was introduced in Maven 4. - Method getImportedFromMethod = inputLocationClass.getDeclaredMethod( "getImportedFrom" ); - return new Maven4InputLocationFormatter( getImportedFromMethod, project ); - } - catch ( NoSuchMethodException nsme ) - { + Method getImportedFromMethod = inputLocationClass.getDeclaredMethod("getImportedFrom"); + return new ImportedFromLocationFormatter(getImportedFromMethod, project); + } catch (NoSuchMethodException nsme) { // Fallback to pre-Maven 4 implementation. - log.info( "Unable to print chain of POM imports, falling back to printing the source POM " - + "without import information. This feature is available in Maven 4.0.0+." ); + log.info("Unable to print chain of POM imports, falling back to printing the source POM " + + "without import information. This feature is available in Maven 4.0.0+."); return new DefaultInputLocationFormatter(); } } diff --git a/src/main/java/org/apache/maven/plugins/help/Maven4InputLocationFormatter.java b/src/main/java/org/apache/maven/plugins/help/Maven4InputLocationFormatter.java deleted file mode 100644 index badf37ac..00000000 --- a/src/main/java/org/apache/maven/plugins/help/Maven4InputLocationFormatter.java +++ /dev/null @@ -1,134 +0,0 @@ -package org.apache.maven.plugins.help; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.model.Dependency; -import org.apache.maven.model.InputLocation; -import org.apache.maven.model.InputSource; -import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.util.StringUtils; - -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Map; -import java.util.Set; - -/** - * Maven 4.x-based implementation of {@link InputLocation.StringFormatter}. Enhances the default implementation - * with support for following "references" (caused by e.g. dependency management imports). - */ -public class Maven4InputLocationFormatter extends InputLocation.StringFormatter -{ - private final Method getImportedFromMethod; - private final MavenProject project; - - public Maven4InputLocationFormatter( final Method getImportedFromMethod, final MavenProject project ) - { - this.getImportedFromMethod = getImportedFromMethod; - this.project = project; - } - - @Override - public String toString( InputLocation location ) - { - InputSource source = location.getSource(); - - String s = source.getModelId(); // by default, display modelId - - if ( StringUtils.isBlank( s ) || s.contains( "[unknown-version]" ) ) - { - // unless it is blank or does not provide version information - s = source.toString(); - } - - InputLocation importedFrom = getImportedFrom( location ); - - StringBuilder p = new StringBuilder(); - - while ( importedFrom != null ) - { - p.append( " from " ).append( importedFrom.getSource().getModelId() ); - importedFrom = getImportedFrom( importedFrom ); - } - - return '}' + s + ( ( location.getLineNumber() >= 0 ) ? ", line " + location.getLineNumber() : "" ) + p; - } - - protected InputLocation getImportedFrom( final InputLocation location ) - { - try - { - InputLocation result = (InputLocation) getImportedFromMethod.invoke( location ); - - if ( result == null && project != null ) - { - for ( Dependency dependency : project.getDependencyManagement().getDependencies() ) - { - // Until a new maven api model is released, we need to use reflection to access the locations - Set locationKeys = getLocationKeys( dependency ); - for ( Object key : locationKeys ) - { - if ( !( key instanceof String ) ) - { - throw new RuntimeException( "Expected a String, got " + key.getClass().getName() ); - } - - InputLocation dependencyLocation = dependency.getLocation( key ); - if ( dependencyLocation != null && dependencyLocation.toString().equals( location.toString() ) ) - { - result = ( InputLocation ) Dependency.class.getMethod( "getImportedFrom" ) - .invoke( dependency ); - break; - } - } - } - } - - return result; - } - catch ( IllegalAccessException | InvocationTargetException | NoSuchMethodException | NoSuchFieldException - | ClassNotFoundException e ) - { - throw new RuntimeException( e ); - } - } - - private Set getLocationKeys( Dependency dependency ) throws NoSuchFieldException, IllegalAccessException - , ClassNotFoundException - { - Field delegateField = Class.forName( "org.apache.maven.model.BaseObject" ).getDeclaredField( "delegate" ); - delegateField.setAccessible( true ); - Object delegate = delegateField.get( dependency ); - delegateField.setAccessible( false ); - - Field locationsField = delegate.getClass().getDeclaredField( "locations" ); - locationsField.setAccessible( true ); - Object locations = locationsField.get( delegate ); - locationsField.setAccessible( false ); - - if ( !( locations instanceof Map ) ) - { - throw new RuntimeException( "Expected a Map, got " + locations.getClass().getName() ); - } - - return ( (Map) locations ).keySet(); - } -} diff --git a/src/test/java/org/apache/maven/plugins/help/DefaultInputLocationFormatterTest.java b/src/test/java/org/apache/maven/plugins/help/DefaultInputLocationFormatterTest.java index 0db8ae04..288e4932 100644 --- a/src/test/java/org/apache/maven/plugins/help/DefaultInputLocationFormatterTest.java +++ b/src/test/java/org/apache/maven/plugins/help/DefaultInputLocationFormatterTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.help; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,75 +16,75 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.help; import org.apache.maven.model.InputLocation; import org.apache.maven.model.InputSource; import org.junit.Test; -import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.StringContains.containsString; -public class DefaultInputLocationFormatterTest -{ +public class DefaultInputLocationFormatterTest { private final InputLocation.StringFormatter formatter = new DefaultInputLocationFormatter(); @Test public void withLineNumberShouldIncludeLineNumber() { // Arrange final InputSource source = new InputSource(); - source.setModelId( "foo:bar:1.0-SNAPSHOT" ); - source.setLocation( "/tmp/project/pom.xml" ); - final InputLocation location = new InputLocation( 3, 5, source ); + source.setModelId("foo:bar:1.0-SNAPSHOT"); + source.setLocation("/tmp/project/pom.xml"); + final InputLocation location = new InputLocation(3, 5, source); // Act - final String result = formatter.toString( location ); + final String result = formatter.toString(location); // Assert - assertThat( result, containsString( "line 3" ) ); + assertThat(result, containsString("line 3")); } @Test public void withoutLineNumberShouldNotIncludeLineNumber() { // Arrange final InputSource source = new InputSource(); - source.setModelId( "foo:bar:1.0-SNAPSHOT" ); - source.setLocation( "/tmp/project/pom.xml" ); - final InputLocation location = new InputLocation( -1, -1, source ); + source.setModelId("foo:bar:1.0-SNAPSHOT"); + source.setLocation("/tmp/project/pom.xml"); + final InputLocation location = new InputLocation(-1, -1, source); // Act - final String result = formatter.toString( location ); + final String result = formatter.toString(location); // Assert - assertThat( result, not( containsString( "line" ) ) ); + assertThat(result, not(containsString("line"))); } @Test public void withModelIdShouldIncludeModelId() { // Arrange final InputSource source = new InputSource(); - source.setModelId( "foo:bar:1.0-SNAPSHOT" ); - source.setLocation( "/tmp/project/pom.xml" ); - final InputLocation location = new InputLocation( 3, 5, source ); + source.setModelId("foo:bar:1.0-SNAPSHOT"); + source.setLocation("/tmp/project/pom.xml"); + final InputLocation location = new InputLocation(3, 5, source); // Act - final String result = formatter.toString( location ); + final String result = formatter.toString(location); // Assert - assertThat( result, containsString( "foo:bar:1.0-SNAPSHOT" ) ); + assertThat(result, containsString("foo:bar:1.0-SNAPSHOT")); } @Test public void withoutModelIdShouldIncludeUnknownVersion() { // Arrange final InputSource source = new InputSource(); - source.setLocation( "/tmp/project/pom.xml" ); - final InputLocation location = new InputLocation( 3, 5, source ); + source.setLocation("/tmp/project/pom.xml"); + final InputLocation location = new InputLocation(3, 5, source); // Act - final String result = formatter.toString( location ); + final String result = formatter.toString(location); // Assert - assertThat( result, not( containsString( "foo:bar:1.0-SNAPSHOT" ) ) ); + assertThat(result, not(containsString("foo:bar:1.0-SNAPSHOT"))); } -} \ No newline at end of file +} diff --git a/src/test/java/org/apache/maven/plugins/help/Maven4InputLocationFormatterTest.java b/src/test/java/org/apache/maven/plugins/help/ImportedFromLocationFormatterTest.java similarity index 76% rename from src/test/java/org/apache/maven/plugins/help/Maven4InputLocationFormatterTest.java rename to src/test/java/org/apache/maven/plugins/help/ImportedFromLocationFormatterTest.java index a840c582..4184840d 100644 --- a/src/test/java/org/apache/maven/plugins/help/Maven4InputLocationFormatterTest.java +++ b/src/test/java/org/apache/maven/plugins/help/ImportedFromLocationFormatterTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.help; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,23 +16,24 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.help; + +import java.util.Stack; import org.apache.maven.model.InputLocation; import org.apache.maven.model.InputSource; import org.apache.maven.project.MavenProject; import org.junit.Test; -import java.util.Stack; - import static org.junit.Assert.assertEquals; -public class Maven4InputLocationFormatterTest { +public class ImportedFromLocationFormatterTest { @Test public void testImportedFromNullToString() { // Arrange final MavenProject project = new MavenProject(); - final Maven4InputLocationFormatter formatter = new Maven4InputLocationFormatterMock(project); + final ImportedFromLocationFormatter formatter = new ImportedFromLocationFormatterMock(project); final InputSource source = new InputSource(); source.setModelId("org.example:MPG-183-project:1-SNAPSHOT"); @@ -55,7 +54,7 @@ public void testImportedFromNotNullToString() { final InputLocation importedFrom = new InputLocation(7, 5, importedFromSource); final MavenProject project = new MavenProject(); - final Maven4InputLocationFormatter formatter = new Maven4InputLocationFormatterMock(project, importedFrom); + final ImportedFromLocationFormatter formatter = new ImportedFromLocationFormatterMock(project, importedFrom); final InputSource source = new InputSource(); source.setModelId("org.example:MPG-183-project:1-SNAPSHOT"); @@ -71,7 +70,7 @@ public void testImportedFromNotNullToString() { @Test public void testMultipleImportedFromToString() { // Arrange - final Maven4InputLocationFormatter formatter = createMultiImportedFromFormatter(); + final ImportedFromLocationFormatter formatter = createMultiImportedFromFormatter(); final InputSource source = new InputSource(); source.setModelId("org.example:MPG-183-project:1-SNAPSHOT"); @@ -81,10 +80,12 @@ public void testMultipleImportedFromToString() { final String result = formatter.toString(location); // Assert - assertEquals("}org.example:MPG-183-project:1-SNAPSHOT, line 7 from org.example:MPG-183-bom-2:1-SNAPSHOT from org.example:MPG-183-bom-1:1-SNAPSHOT", result); + String expected = + "}org.example:MPG-183-project:1-SNAPSHOT, line 7 from org.example:MPG-183-bom-2:1-SNAPSHOT from org.example:MPG-183-bom-1:1-SNAPSHOT"; + assertEquals(expected, result); } - private static Maven4InputLocationFormatter createMultiImportedFromFormatter() { + private static ImportedFromLocationFormatter createMultiImportedFromFormatter() { final InputSource importedFromSource1 = new InputSource(); importedFromSource1.setModelId("org.example:MPG-183-bom-1:1-SNAPSHOT"); final InputLocation importedFrom1 = new InputLocation(7, 5, importedFromSource1); @@ -93,22 +94,22 @@ private static Maven4InputLocationFormatter createMultiImportedFromFormatter() { importedFromSource2.setModelId("org.example:MPG-183-bom-2:1-SNAPSHOT"); final InputLocation importedFrom2 = new InputLocation(7, 5, importedFromSource2); - return new Maven4InputLocationFormatterMock(new MavenProject(), importedFrom1, importedFrom2); + return new ImportedFromLocationFormatterMock(new MavenProject(), importedFrom1, importedFrom2); } - private static class Maven4InputLocationFormatterMock extends Maven4InputLocationFormatter { + private static class ImportedFromLocationFormatterMock extends ImportedFromLocationFormatter { private final Stack mockedImportedFrom; - public Maven4InputLocationFormatterMock(MavenProject project) { + public ImportedFromLocationFormatterMock(MavenProject project) { this(project, new Stack<>()); } - public Maven4InputLocationFormatterMock(MavenProject project, Stack mockedImportedFrom) { + public ImportedFromLocationFormatterMock(MavenProject project, Stack mockedImportedFrom) { super(null, project); this.mockedImportedFrom = mockedImportedFrom; } - public Maven4InputLocationFormatterMock(MavenProject project, InputLocation... mockedImportedFrom) { + public ImportedFromLocationFormatterMock(MavenProject project, InputLocation... mockedImportedFrom) { super(null, project); this.mockedImportedFrom = new Stack<>(); @@ -122,4 +123,4 @@ protected InputLocation getImportedFrom(InputLocation location) { return !mockedImportedFrom.isEmpty() ? mockedImportedFrom.pop() : null; } } -} \ No newline at end of file +} diff --git a/src/test/java/org/apache/maven/plugins/help/InputLocationFormatterFactoryTest.java b/src/test/java/org/apache/maven/plugins/help/InputLocationFormatterFactoryTest.java index 8f65db69..f383abb8 100644 --- a/src/test/java/org/apache/maven/plugins/help/InputLocationFormatterFactoryTest.java +++ b/src/test/java/org/apache/maven/plugins/help/InputLocationFormatterFactoryTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.help; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,15 +16,15 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.help; import org.apache.maven.model.InputLocation; import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; import org.junit.Test; -import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.CoreMatchers.instanceOf; - +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.*; public class InputLocationFormatterFactoryTest { @@ -46,7 +44,7 @@ public void whenNoSuchMethodThrownReturnsDefaultInputLocationFormatter() { @Test public void whenMethodExistsReturnsMaven4InputLocationFormatter() { // Arrange - InputLocationFormatterFactory.inputLocationClass = Maven4InputLocationStub.class; + InputLocationFormatterFactory.inputLocationClass = InputLocationStub.class; final Log log = mock(Log.class); final MavenProject project = mock(MavenProject.class); @@ -55,12 +53,12 @@ public void whenMethodExistsReturnsMaven4InputLocationFormatter() { final InputLocation.StringFormatter result = InputLocationFormatterFactory.produce(log, project); // Assert - assertThat(result, instanceOf(Maven4InputLocationFormatter.class)); + assertThat(result, instanceOf(ImportedFromLocationFormatter.class)); } - private static class Maven4InputLocationStub { + private static class InputLocationStub { public String getImportedFrom() { return ""; } } -} \ No newline at end of file +}