Restore dependency-tools API compatibility

Refactor dependency-tools to restore API compatibility with Spring
Boot 1.0. This should reduce reflection hacks that tools such as Gretty
would otherwise have to make.

See gh-1035
This commit is contained in:
Phillip Webb
2014-06-08 12:11:20 -07:00
parent f1d216a33b
commit 9b982dabdb
18 changed files with 357 additions and 218 deletions

View File

@@ -26,22 +26,22 @@ import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
/**
* Tests for {@link VersionManagedDependencies}.
* Tests for {@link ManagedDependenciesDelegate}.
*
* @author Phillip Webb
*/
public class VersionManagedDependenciesTests {
public class ManagedDependenciesDelegateTests {
private VersionManagedDependencies dependencies;
private ManagedDependenciesDelegate dependencies;
@Before
public void setup() throws Exception {
PropertiesFileManagedDependencies root = new PropertiesFileManagedDependencies(
getClass().getResourceAsStream("external.properties"));
PropertiesFileManagedDependencies extra = new PropertiesFileManagedDependencies(
getClass().getResourceAsStream("additional-external.properties"));
this.dependencies = new VersionManagedDependencies(root,
Collections.<ManagedDependencies> singleton(extra));
PropertiesFileDependencies root = new PropertiesFileDependencies(getClass()
.getResourceAsStream("external.properties"));
PropertiesFileDependencies extra = new PropertiesFileDependencies(getClass()
.getResourceAsStream("additional-external.properties"));
this.dependencies = new ManagedDependenciesDelegate(root,
Collections.<Dependencies> singleton(extra));
}
@Test
@@ -56,12 +56,6 @@ public class VersionManagedDependenciesTests {
equalTo("org.sample:sample02:2.0.0"));
}
@Test
public void getSpringBootVersion() throws Exception {
assertThat(this.dependencies.getSpringBootVersion(),
equalTo("1.0.0.BUILD-SNAPSHOT"));
}
@Test
public void iterator() throws Exception {
Iterator<Dependency> iterator = this.dependencies.iterator();

View File

@@ -0,0 +1,74 @@
/*
* Copyright 2012-2014 the original author or authors.
*
* Licensed 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.springframework.boot.dependency.tools;
import org.junit.Before;
import org.junit.Test;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
/**
* Tests for {@link ManagedDependencies}.
*
* @author Phillip Webb
*/
public class ManagedDependenciesTests {
private ManagedDependencies managedDependencies;
private Dependencies delegate;
@Before
public void setup() {
this.delegate = mock(Dependencies.class);
this.managedDependencies = new ManagedDependencies(this.delegate) {
};
}
@Test
@Deprecated
public void getVersion() throws Exception {
this.managedDependencies.getVersion();
verify(this.delegate).find("org.springframework.boot", "spring-boot");
}
@Test
public void getSpringBootVersion() throws Exception {
this.managedDependencies.getSpringBootVersion();
verify(this.delegate).find("org.springframework.boot", "spring-boot");
}
@Test
public void findGroupIdArtifactId() throws Exception {
this.managedDependencies.find("groupId", "artifactId");
verify(this.delegate).find("groupId", "artifactId");
}
@Test
public void findArtifactId() throws Exception {
this.managedDependencies.find("artifactId");
verify(this.delegate).find("artifactId");
}
@Test
public void iterator() throws Exception {
this.managedDependencies.iterator();
verify(this.delegate).iterator();
}
}

View File

@@ -28,18 +28,18 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
/**
* Tests for {@link PomManagedDependencies}.
* Tests for {@link PomDependencies}.
*
* @author Phillip Webb
*/
public class PomManagedDependenciesTests {
public class PomDependenciesTests {
private PomManagedDependencies dependencies;
private PomDependencies dependencies;
@Before
public void setup() {
InputStream x = getResource("test-effective-pom.xml");
this.dependencies = new PomManagedDependencies(x);
this.dependencies = new PomDependencies(x);
}
private InputStream getResource(String name) {
@@ -48,12 +48,6 @@ public class PomManagedDependenciesTests {
return inputStream;
}
@Test
public void springBootVersion() throws Exception {
assertThat(this.dependencies.getSpringBootVersion(),
equalTo("1.0.0.BUILD-SNAPSHOT"));
}
@Test
public void iterate() throws Exception {
Iterator<Dependency> iterator = this.dependencies.iterator();

View File

@@ -26,26 +26,20 @@ import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
/**
* Tests for {@link PropertiesFileManagedDependencies}.
* Tests for {@link PropertiesFileDependencies}.
*
* @author Phillip Webb
*/
public class PropertiesFileManagedDependenciesTests {
public class PropertiesFileDependenciesTests {
private PropertiesFileManagedDependencies dependencies;
private PropertiesFileDependencies dependencies;
@Before
public void setup() throws Exception {
this.dependencies = new PropertiesFileManagedDependencies(getClass()
this.dependencies = new PropertiesFileDependencies(getClass()
.getResourceAsStream("external.properties"));
}
@Test
public void springBootVersion() throws Exception {
assertThat(this.dependencies.getSpringBootVersion(),
equalTo("1.0.0.BUILD-SNAPSHOT"));
}
@Test
public void iterate() throws Exception {
Iterator<Dependency> iterator = this.dependencies.iterator();