This commit is contained in:
Phillip Webb
2014-10-21 20:33:00 -07:00
parent d1ce83e3c3
commit 2e7aa4685b
33 changed files with 121 additions and 161 deletions

View File

@@ -78,6 +78,7 @@ public class GroovyGrabDependencyResolverTests {
public String[] getClasspath() {
return new String[] { "." };
}
};
this.resolver = new GroovyGrabDependencyResolver(configuration);
}

View File

@@ -32,8 +32,8 @@ import org.springframework.util.FileSystemUtils;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.junit.Assert.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* Tests for {@link Installer}
@@ -65,22 +65,17 @@ public class InstallerTests {
@Test
public void installNewDependency() throws Exception {
File foo = createTemporaryFile("foo.jar");
when(this.resolver.resolve(Arrays.asList("foo"))).thenReturn(Arrays.asList(foo));
given(this.resolver.resolve(Arrays.asList("foo"))).willReturn(Arrays.asList(foo));
this.installer.install(Arrays.asList("foo"));
assertThat(getNamesOfFilesInLib(), containsInAnyOrder("foo.jar", ".installed"));
}
@Test
public void installAndUninstall() throws Exception {
File foo = createTemporaryFile("foo.jar");
when(this.resolver.resolve(Arrays.asList("foo"))).thenReturn(Arrays.asList(foo));
given(this.resolver.resolve(Arrays.asList("foo"))).willReturn(Arrays.asList(foo));
this.installer.install(Arrays.asList("foo"));
this.installer.uninstall(Arrays.asList("foo"));
assertThat(getNamesOfFilesInLib(), contains(".installed"));
}
@@ -89,30 +84,24 @@ public class InstallerTests {
File alpha = createTemporaryFile("alpha.jar");
File bravo = createTemporaryFile("bravo.jar");
File charlie = createTemporaryFile("charlie.jar");
when(this.resolver.resolve(Arrays.asList("bravo"))).thenReturn(
given(this.resolver.resolve(Arrays.asList("bravo"))).willReturn(
Arrays.asList(bravo, alpha));
when(this.resolver.resolve(Arrays.asList("charlie"))).thenReturn(
given(this.resolver.resolve(Arrays.asList("charlie"))).willReturn(
Arrays.asList(charlie, alpha));
this.installer.install(Arrays.asList("bravo"));
assertThat(getNamesOfFilesInLib(),
containsInAnyOrder("alpha.jar", "bravo.jar", ".installed"));
this.installer.install(Arrays.asList("charlie"));
assertThat(getNamesOfFilesInLib(),
containsInAnyOrder("alpha.jar", "bravo.jar", "charlie.jar", ".installed"));
this.installer.uninstall(Arrays.asList("bravo"));
assertThat(getNamesOfFilesInLib(),
containsInAnyOrder("alpha.jar", "charlie.jar", ".installed"));
this.installer.uninstall(Arrays.asList("charlie"));
assertThat(getNamesOfFilesInLib(), containsInAnyOrder(".installed"));
}
@@ -122,20 +111,17 @@ public class InstallerTests {
File bravo = createTemporaryFile("bravo.jar");
File charlie = createTemporaryFile("charlie.jar");
when(this.resolver.resolve(Arrays.asList("bravo"))).thenReturn(
given(this.resolver.resolve(Arrays.asList("bravo"))).willReturn(
Arrays.asList(bravo, alpha));
when(this.resolver.resolve(Arrays.asList("charlie"))).thenReturn(
given(this.resolver.resolve(Arrays.asList("charlie"))).willReturn(
Arrays.asList(charlie, alpha));
this.installer.install(Arrays.asList("bravo"));
this.installer.install(Arrays.asList("charlie"));
assertThat(getNamesOfFilesInLib(),
containsInAnyOrder("alpha.jar", "bravo.jar", "charlie.jar", ".installed"));
this.installer.uninstallAll();
assertThat(getNamesOfFilesInLib(), containsInAnyOrder(".installed"));
}
@@ -152,4 +138,5 @@ public class InstallerTests {
temporaryFile.deleteOnExit();
return temporaryFile;
}
}

View File

@@ -35,7 +35,7 @@ import org.springframework.boot.cli.compiler.grape.DependencyResolutionContext;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.when;
import static org.mockito.BDDMockito.given;
/**
* Tests for {@link DependencyCustomizer}
@@ -56,13 +56,12 @@ public class DependencyCustomizerTests {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
when(this.resolver.getGroupId("spring-boot-starter-logging")).thenReturn(
given(this.resolver.getGroupId("spring-boot-starter-logging")).willReturn(
"org.springframework.boot");
when(this.resolver.getArtifactId("spring-boot-starter-logging")).thenReturn(
given(this.resolver.getArtifactId("spring-boot-starter-logging")).willReturn(
"spring-boot-starter-logging");
when(this.resolver.getVersion("spring-boot-starter-logging")).thenReturn("1.2.3");
given(this.resolver.getVersion("spring-boot-starter-logging"))
.willReturn("1.2.3");
this.moduleNode.addClass(this.classNode);
this.dependencyCustomizer = new DependencyCustomizer(new GroovyClassLoader(
getClass().getClassLoader()), this.moduleNode,
@@ -169,4 +168,5 @@ public class DependencyCustomizerTests {
private Object getMemberValue(AnnotationNode annotationNode, String member) {
return ((ConstantExpression) annotationNode.getMember(member)).getValue();
}
}

View File

@@ -46,8 +46,8 @@ import org.springframework.boot.cli.compiler.dependencies.ArtifactCoordinatesRes
import org.springframework.boot.cli.compiler.grape.DependencyResolutionContext;
import static org.junit.Assert.assertEquals;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* Tests for {@link ResolveDependencyCoordinatesTransformation}
@@ -73,9 +73,9 @@ public final class ResolveDependencyCoordinatesTransformationTests {
@Before
public void setupExpectations() {
when(this.coordinatesResolver.getGroupId("spring-core")).thenReturn(
given(this.coordinatesResolver.getGroupId("spring-core")).willReturn(
"org.springframework");
when(this.coordinatesResolver.getVersion("spring-core")).thenReturn("4.0.0.RC1");
given(this.coordinatesResolver.getVersion("spring-core")).willReturn("4.0.0.RC1");
}
@Test