package org.testcontainers;

import org.assertj.core.api.ListAssert;
import org.junit.Test;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import static org.assertj.core.api.Assertions.assertThat;

public class JarFileShadingTest extends AbstractJarFileTest {

    @Test
    public void testPackages() throws Exception {
        assertThatFileList(root).containsOnly(
                "docker-java.properties",
                "org/",
                "META-INF/",
                "com/"
        );

        assertThatFileList(root.resolve("org")).containsOnly(
                "testcontainers/"
        );

        assertThatFileList(root.resolve("com")).containsOnly(
                "github/"
        );

        assertThatFileList(root.resolve("com").resolve("github")).containsOnly(
                "dockerjava/"
        );
    }

    @Test
    public void testMetaInf() throws Exception {
        assertThatFileList(root.resolve("META-INF")).containsOnly(
                "MANIFEST.MF",
                "services/",
                "native/"
        );

        assertThatFileList(root.resolve("META-INF").resolve("native")).containsOnly(
                "liborg-testcontainers-shaded-netty-transport-native-epoll.so",
                "liborg-testcontainers-shaded-netty-transport-native-kqueue.jnilib"
        );
    }

    @Test
    public void testMetaInfServices() throws Exception {
        assertThatFileList(root.resolve("META-INF").resolve("services"))
                .allMatch(it -> it.startsWith("org.testcontainers."));
    }

    private ListAssert<String> assertThatFileList(Path path) throws IOException {
        return (ListAssert) assertThat(Files.list(path))
                .extracting(Path::getFileName)
                .extracting(Object::toString);
    }
}

@@ -461,17 +461,16 @@
     %22org
-/
 %22,%0A     
@@ -489,17 +489,16 @@
 META-INF
-/
 %22,%0A     
@@ -512,17 +512,16 @@
     %22com
-/
 %22%0A      
@@ -619,17 +619,16 @@
 ntainers
-/
 %22%0A      
@@ -718,17 +718,16 @@
  %22github
-/
 %22%0A      
@@ -839,17 +839,16 @@
 ckerjava
-/
 %22%0A      
@@ -1041,17 +1041,16 @@
 services
-/
 %22,%0A     
@@ -1071,9 +1071,8 @@
 tive
-/
 %22%0A  
@@ -1784,14 +1784,12 @@
 ing(
-Object
+Path
 ::to
@@ -1795,16 +1795,108 @@
 oString)
+%0A                .extracting(it -%3E it.endsWith(%22/%22) ? it.substring(0, it.length() - 1) : it)
 ;%0A    %7D%0A

fix "JarFileShadingTest" on Java 9