Best Testcontainers-java code snippet using org.testcontainers.JarFileShadingTest.assertThatFileList
Source:JarFileShadingTest.java
...7import static org.assertj.core.api.Assertions.assertThat;8public class JarFileShadingTest extends AbstractJarFileTest {9 @Test10 public void testPackages() throws Exception {11 assertThatFileList(root).containsOnly(12 "docker-java.properties",13 "org",14 "META-INF",15 "com"16 );17 assertThatFileList(root.resolve("org")).containsOnly(18 "testcontainers"19 );20 assertThatFileList(root.resolve("com")).containsOnly(21 "github"22 );23 assertThatFileList(root.resolve("com").resolve("github")).containsOnly(24 "dockerjava"25 );26 }27 @Test28 public void testMetaInf() throws Exception {29 assertThatFileList(root.resolve("META-INF")).containsOnly(30 "MANIFEST.MF",31 "services",32 "native"33 );34 assertThatFileList(root.resolve("META-INF").resolve("native")).containsOnly(35 "liborg-testcontainers-shaded-netty-transport-native-epoll.so",36 "liborg-testcontainers-shaded-netty-transport-native-kqueue.jnilib"37 );38 }39 @Test40 public void testMetaInfServices() throws Exception {41 assertThatFileList(root.resolve("META-INF").resolve("services"))42 .allMatch(it -> it.startsWith("org.testcontainers."));43 }44 private ListAssert<String> assertThatFileList(Path path) throws IOException {45 return (ListAssert) assertThat(Files.list(path))46 .extracting(Path::getFileName)47 .extracting(Path::toString)48 .extracting(it -> it.endsWith("/") ? it.substring(0, it.length() - 1) : it);49 }50}...
assertThatFileList
Using AI Code Generation
1public void test() throws Exception {2 assertThatFileList("org/testcontainers/containers/ContainerFetchTest.class")3 .containsOnly("org/testcontainers/containers/ContainerFetchTest.class");4}5package org.testcontainers;6import org.junit.Test;7import java.io.File;8import java.io.IOException;9import java.net.URL;10import java.nio.file.Files;11import java.nio.file.Paths;12import java.util.Enumeration;13import java.util.List;14import java.util.jar.JarEntry;15import java.util.jar.JarFile;16import java.util.stream.Collectors;17import static org.assertj.core.api.Assertions.assertThat;18public class JarFileShadingTest {19 private static final String TESTCONTAINERS_JAR = "testcontainers-1.12.3.jar";20 public void test() throws Exception {21 assertThatFileList("org/testcontainers/containers/ContainerFetchTest.class")22 .containsOnly("org/testcontainers/containers/ContainerFetchTest.class");23 }24 public static FileListAssert assertThatFileList(String path) throws IOException {25 return new FileListAssert(path);26 }27 public static class FileListAssert {28 private final List<String> files;29 public FileListAssert(String path) throws IOException {30 JarFile jarFile = new JarFile(TESTCONTAINERS_JAR);31 Enumeration<JarEntry> entries = jarFile.entries();32 files = Files.walk(Paths.get(jarFile.getName()))33 .filter(Files::isRegularFile)34 .map(path1 -> {35 try {36 return new URL("jar:file:" + jarFile.getName() + "!/" + path1.toAbsolutePath().toString()).getPath();37 } catch (IOException e) {38 throw new RuntimeException(e);39 }40 })41 .filter(s -> s.contains(path))42 .collect(Collectors.toList());43 }44 public FileListAssert containsOnly(String... files) {45 assertThat(this.files).containsOnly(files);46 return this;47 }48 }49}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!