You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2020/05/28 20:58:14 UTC
[maven-dependency-plugin] 01/01: [MDEP-700] Fix possible NPE
This is an automated email from the ASF dual-hosted git repository.
michaelo pushed a commit to branch MDEP-700
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git
commit 7920c86b8ffe5f44be08ba76070c2d881d830ac0
Author: Piotrek Żygieło <pz...@users.noreply.github.com>
AuthorDate: Sat May 2 12:27:25 2020 +0200
[MDEP-700] Fix possible NPE
This closes #47
---
.../maven/plugins/dependency/tree/TreeMojo.java | 9 ++--
.../tree/TestTreeMojo_ContainsVersion.java | 51 ++++++++++++++++++++++
2 files changed, 57 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/apache/maven/plugins/dependency/tree/TreeMojo.java b/src/main/java/org/apache/maven/plugins/dependency/tree/TreeMojo.java
index ab1e7b2..3643b07 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/tree/TreeMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/tree/TreeMojo.java
@@ -479,9 +479,12 @@ public class TreeMojo
return true;
}
}
+ return false;
+ }
+ else
+ {
+ // only singular versions ever have a recommendedVersion
+ return recommendedVersion.compareTo( theVersion ) <= 0;
}
-
- // only singular versions ever have a recommendedVersion
- return recommendedVersion.compareTo( theVersion ) <= 0;
}
}
diff --git a/src/test/java/org/apache/maven/plugins/dependency/tree/TestTreeMojo_ContainsVersion.java b/src/test/java/org/apache/maven/plugins/dependency/tree/TestTreeMojo_ContainsVersion.java
new file mode 100644
index 0000000..4c9815a
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugins/dependency/tree/TestTreeMojo_ContainsVersion.java
@@ -0,0 +1,51 @@
+package org.apache.maven.plugins.dependency.tree;
+
+/*
+ * 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 junit.framework.TestCase;
+import org.apache.maven.artifact.versioning.ArtifactVersion;
+import org.apache.maven.artifact.versioning.Restriction;
+import org.apache.maven.artifact.versioning.VersionRange;
+
+import java.util.Collections;
+
+import static org.apache.maven.plugins.dependency.tree.TreeMojo.containsVersion;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests <code>TreeMojo.containsVersion</code>.
+ */
+public class TestTreeMojo_ContainsVersion extends TestCase
+{
+ private VersionRange range = mock( VersionRange.class );
+
+ private ArtifactVersion version = mock( ArtifactVersion.class );
+
+ public void testWhenRecommendedVersionIsNullAndNoRestrictions()
+ {
+ when( range.getRecommendedVersion() ).thenReturn( null );
+ when( range.getRestrictions() ).thenReturn( Collections.<Restriction>emptyList() );
+
+ boolean doesItContain = containsVersion( range, version );
+
+ assertFalse( doesItContain );
+ }
+}