@ -26,6 +26,7 @@ import org.junit.jupiter.api.io.TempDir;
import org.springframework.boot.loader.launch.Archive.Entry ;
import org.springframework.boot.loader.launch.Archive.Entry ;
import org.springframework.boot.loader.testsupport.TestJar ;
import org.springframework.boot.loader.testsupport.TestJar ;
import org.springframework.boot.loader.zip.AssertFileChannelDataBlocksClosed ;
import static org.assertj.core.api.Assertions.assertThat ;
import static org.assertj.core.api.Assertions.assertThat ;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException ;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException ;
@ -40,6 +41,7 @@ import static org.mockito.Mockito.withSettings;
*
*
* @author Phillip Webb
* @author Phillip Webb
* /
* /
@AssertFileChannelDataBlocksClosed
class ArchiveTests {
class ArchiveTests {
@TempDir
@TempDir
@ -75,9 +77,10 @@ class ArchiveTests {
CodeSource codeSource = mock ( CodeSource . class ) ;
CodeSource codeSource = mock ( CodeSource . class ) ;
given ( protectionDomain . getCodeSource ( ) ) . willReturn ( codeSource ) ;
given ( protectionDomain . getCodeSource ( ) ) . willReturn ( codeSource ) ;
given ( codeSource . getLocation ( ) ) . willReturn ( jarFile . toURI ( ) . toURL ( ) ) ;
given ( codeSource . getLocation ( ) ) . willReturn ( jarFile . toURI ( ) . toURL ( ) ) ;
Archive archive = Archive . create ( protectionDomain ) ;
try ( Archive archive = Archive . create ( protectionDomain ) ) {
assertThat ( archive ) . isInstanceOf ( JarFileArchive . class ) ;
assertThat ( archive ) . isInstanceOf ( JarFileArchive . class ) ;
}
}
}
@Test
@Test
void createFromProtectionDomainWhenNoLocationThrowsException ( ) throws Exception {
void createFromProtectionDomainWhenNoLocationThrowsException ( ) throws Exception {
@ -99,13 +102,17 @@ class ArchiveTests {
void createFromFileWhenJarFileReturnsJarFileArchive ( ) throws Exception {
void createFromFileWhenJarFileReturnsJarFileArchive ( ) throws Exception {
File target = new File ( this . temp , "missing" ) ;
File target = new File ( this . temp , "missing" ) ;
TestJar . create ( target ) ;
TestJar . create ( target ) ;
assertThat ( Archive . create ( target ) ) . isInstanceOf ( JarFileArchive . class ) ;
try ( Archive archive = Archive . create ( target ) ) {
assertThat ( archive ) . isInstanceOf ( JarFileArchive . class ) ;
}
}
}
@Test
@Test
void createFromFileWhenDirectoryReturnsExplodedFileArchive ( ) throws Exception {
void createFromFileWhenDirectoryReturnsExplodedFileArchive ( ) throws Exception {
File target = this . temp ;
File target = this . temp ;
assertThat ( Archive . create ( target ) ) . isInstanceOf ( ExplodedArchive . class ) ;
try ( Archive archive = Archive . create ( target ) ) {
assertThat ( archive ) . isInstanceOf ( ExplodedArchive . class ) ;
}
}
}
}
}