Further re-organization of launcher code

This commit is contained in:
Phillip Webb
2013-09-24 15:30:22 -07:00
parent 0e0eb7d3fa
commit 15bc25dc29
17 changed files with 390 additions and 347 deletions

View File

@@ -17,63 +17,72 @@
package org.springframework.boot.loader;
import java.io.File;
import java.io.IOException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.test.util.ReflectionTestUtils;
import static org.junit.Assert.assertEquals;
/**
* Tests for {@link PropertiesLauncher}.
*
* @author Dave Syer
*/
public class PropertiesLauncherTests {
private PropertiesLauncher launcher = new PropertiesLauncher();
@Before
public void setup() throws IOException {
System.setProperty("loader.home",
new File("src/test/resources").getAbsolutePath());
}
@After
public void close() {
System.clearProperty("loader.system");
System.clearProperty("loader.home");
System.clearProperty("loader.path");
System.clearProperty("loader.main");
System.clearProperty("loader.config.name");
System.clearProperty("loader.config.location");
System.clearProperty("loader.system");
}
@Test
public void testDefaultHome() {
assertEquals(new File(System.getProperty("user.dir")),
this.launcher.getHomeDirectory());
PropertiesLauncher launcher = new PropertiesLauncher();
assertEquals(new File(System.getProperty("loader.home")),
launcher.getHomeDirectory());
}
@Test
public void testUserSpecifiedMain() throws Exception {
this.launcher.initialize(new File("."));
assertEquals("demo.Application", this.launcher.getMainClass(null));
PropertiesLauncher launcher = new PropertiesLauncher();
assertEquals("demo.Application", launcher.getMainClass());
assertEquals(null, System.getProperty("loader.main"));
}
@Test
public void testUserSpecifiedConfigName() throws Exception {
System.setProperty("loader.config.name", "foo");
this.launcher.initialize(new File("."));
assertEquals("my.Application", this.launcher.getMainClass(null));
assertEquals("[etc/]", ReflectionTestUtils.getField(this.launcher, "paths")
.toString());
PropertiesLauncher launcher = new PropertiesLauncher();
assertEquals("my.Application", launcher.getMainClass());
assertEquals("[etc/]", ReflectionTestUtils.getField(launcher, "paths").toString());
}
@Test
public void testSystemPropertySpecifiedMain() throws Exception {
System.setProperty("loader.main", "foo.Bar");
this.launcher.initialize(new File("."));
assertEquals("foo.Bar", this.launcher.getMainClass(null));
PropertiesLauncher launcher = new PropertiesLauncher();
assertEquals("foo.Bar", launcher.getMainClass());
}
@Test
public void testSystemPropertiesSet() throws Exception {
System.setProperty("loader.system", "true");
this.launcher.initialize(new File("."));
new PropertiesLauncher();
assertEquals("demo.Application", System.getProperty("loader.main"));
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.loader;
package org.springframework.boot.loader.archive;
import java.io.File;
import java.io.FileOutputStream;
@@ -33,7 +33,10 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.springframework.boot.loader.Archive.Entry;
import org.springframework.boot.loader.TestJarCreator;
import org.springframework.boot.loader.archive.Archive;
import org.springframework.boot.loader.archive.Archive.Entry;
import org.springframework.boot.loader.archive.ExplodedArchive;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
@@ -126,7 +129,7 @@ public class ExplodedArchiveTests {
@Test
public void getFilteredArchive() throws Exception {
Archive filteredArchive = this.archive
.getFilteredArchive(new Archive.EntryFilter() {
.getFilteredArchive(new Archive.EntryRenameFilter() {
@Override
public String apply(String entryName, Entry entry) {
if (entryName.equals("1.dat")) {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.loader;
package org.springframework.boot.loader.archive;
import java.io.File;
import java.net.URL;
@@ -25,9 +25,10 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.springframework.boot.loader.Archive;
import org.springframework.boot.loader.JarFileArchive;
import org.springframework.boot.loader.Archive.Entry;
import org.springframework.boot.loader.TestJarCreator;
import org.springframework.boot.loader.archive.Archive;
import org.springframework.boot.loader.archive.JarFileArchive;
import org.springframework.boot.loader.archive.Archive.Entry;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
@@ -83,7 +84,7 @@ public class JarFileArchiveTests {
@Test
public void getFilteredArchive() throws Exception {
Archive filteredArchive = this.archive
.getFilteredArchive(new Archive.EntryFilter() {
.getFilteredArchive(new Archive.EntryRenameFilter() {
@Override
public String apply(String entryName, Entry entry) {
if (entryName.equals("1.dat")) {