Skip to content

Commit

Permalink
Merge branch '2.3.x'
Browse files Browse the repository at this point in the history
Closes gh-24017
  • Loading branch information
wilkinsona committed Nov 3, 2020
2 parents f4e90f4 + f3d4b3e commit bbad377
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
Expand Up @@ -24,6 +24,7 @@
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.Manifest;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;

/**
Expand Down Expand Up @@ -67,6 +68,11 @@ public Enumeration<JarEntry> entries() {
return this.parent.entries();
}

@Override
public Stream<JarEntry> stream() {
return this.parent.stream();
}

@Override
public JarEntry getJarEntry(String name) {
return this.parent.getJarEntry(name);
Expand Down
Expand Up @@ -28,6 +28,7 @@
import java.util.Set;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;

import org.junit.jupiter.api.AfterEach;
Expand Down Expand Up @@ -150,6 +151,12 @@ void wrapperMustNotImplementClose() {
.isThrownBy(() -> JarFileWrapper.class.getDeclaredMethod("close"));
}

@Test
void streamDelegatestoParent() {
this.wrapper.stream();
this.parent.verify(Call.STREAM);
}

/**
* {@link JarFile} that we can spy (even on Java 11+)
*/
Expand Down Expand Up @@ -179,6 +186,12 @@ public Enumeration<java.util.jar.JarEntry> entries() {
return super.entries();
}

@Override
public Stream<java.util.jar.JarEntry> stream() {
mark(Call.STREAM);
return super.stream();
}

@Override
public JarEntry getJarEntry(String name) {
mark(Call.GET_JAR_ENTRY);
Expand Down Expand Up @@ -257,7 +270,9 @@ enum Call {

GET_COMMENT,

SIZE
SIZE,

STREAM

}

Expand Down
Expand Up @@ -20,6 +20,9 @@
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.net.URL;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.stream.Collectors;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -200,6 +203,14 @@ void getLastModifiedReturnsLastModifiedTimeOfJarEntry() throws Exception {
assertThat(connection.getLastModified()).isEqualTo(connection.getJarEntry().getTime());
}

@Test
void entriesCanBeStreamedFromJarFileOfConnection() throws Exception {
URL url = new URL("jar:" + this.rootJarFile.toURI().toURL() + "!/");
JarURLConnection connection = JarURLConnection.get(url, this.jarFile);
List<String> entryNames = connection.getJarFile().stream().map(JarEntry::getName).collect(Collectors.toList());
assertThat(entryNames).hasSize(12);
}

@Test
void jarEntryBasicName() {
assertThat(new JarEntryName(new StringSequence("a/b/C.class")).toString()).isEqualTo("a/b/C.class");
Expand Down

0 comments on commit bbad377

Please sign in to comment.