// Path: heroku-deploy/src/main/java/com/heroku/sdk/deploy/util/PathUtils.java
// public class PathUtils {
// 
//     public static List<Path> normalizeAll(Path basePath, List<Path> paths) {
//         List<Path> normalizedPaths = new ArrayList<>();
//         for (Path path : paths) {
//             normalize(basePath, path).ifPresent(normalizedPaths::add);
//         }
// 
//         return normalizedPaths;
//     }
// 
//     public static Optional<Path> normalize(Path basePath, Path path) {
//         Path absoluteBasePath = basePath.toAbsolutePath();
//         Path normalizedAbsolutePath = absoluteBasePath.resolve(path).normalize();
// 
//         if (normalizedAbsolutePath.startsWith(absoluteBasePath)) {
//             return Optional.of(absoluteBasePath.relativize(normalizedAbsolutePath));
//         }
// 
//         return Optional.empty();
//     }
// 
//     public static boolean isValidPath(Path basePath, Path path) {
//         return normalize(basePath, path).isPresent();
//     }
// 
//     public static List<Path> expandDirectories(Path basePath, List<Path> paths) throws IOException {
//         ArrayList<Path> result = new ArrayList<>();
//         for (Path path : paths) {
//             result.addAll(expandDirectory(basePath, path));
//         }
// 
//         return result;
//     }
// 
//     public static List<Path> expandDirectory(Path basePath, Path path) throws IOException {
//         return Files
//                 .walk(basePath.resolve(path).normalize())
//                 .filter(subPath -> !Files.isDirectory(subPath))
//                 .map(subPath -> normalize(basePath, subPath))
//                 .filter(Optional::isPresent)
//                 .map(Optional::get)
//                 .collect(Collectors.toList());
//     }
// 
//     public static String separatorsToUnix(Path path) {
//         // Path will normalize separators back to Windows when run on Windows. We have to fall back to a String here.
//         return path.toString().replace('\\', '/');
//     }
// }


import com.heroku.sdk.deploy.util.PathUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.stream.Collectors;
import static org.junit.Assert.*;
package com.heroku.sdk.deploy.lib;




public class PathUtilsTest {
    private Path basePath = Paths.get("/home/user/projects/project");
    private Path existingBasePath;

    @Test
    public void testNormalizeAll() {
        ArrayList<Path> pathsToNormalize = new ArrayList<>();
        ArrayList<Path> expectedNormalizedPaths = new ArrayList<>();

        pathsToNormalize.add(Paths.get("README.md"));
        expectedNormalizedPaths.add(Paths.get("README.md"));

        pathsToNormalize.add(Paths.get("docs//HACKING.md"));
        expectedNormalizedPaths.add(Paths.get("docs/HACKING.md"));

        pathsToNormalize.add(Paths.get("target/dependencies/../project.war"));
        expectedNormalizedPaths.add(Paths.get("target/project.war"));

        pathsToNormalize.add(Paths.get("/home/user/projects/project/target/dependencies/dep1.jar"));
        expectedNormalizedPaths.add(Paths.get("target/dependencies/dep1.jar"));

        pathsToNormalize.add(Paths.get("../../projects/project/start.sh"));
        expectedNormalizedPaths.add(Paths.get("start.sh"));

        pathsToNormalize.add(Paths.get("../README.md"));
        // We expect this to be filtered out, hence no expectedNormalizedPaths entry here.

// Path: heroku-deploy/src/main/java/com/heroku/sdk/deploy/util/PathUtils.java
// public class PathUtils {
// 
//     public static List<Path> normalizeAll(Path basePath, List<Path> paths) {
//         List<Path> normalizedPaths = new ArrayList<>();
//         for (Path path : paths) {
//             normalize(basePath, path).ifPresent(normalizedPaths::add);
//         }
// 
//         return normalizedPaths;
//     }
// 
//     public static Optional<Path> normalize(Path basePath, Path path) {
//         Path absoluteBasePath = basePath.toAbsolutePath();
//         Path normalizedAbsolutePath = absoluteBasePath.resolve(path).normalize();
// 
//         if (normalizedAbsolutePath.startsWith(absoluteBasePath)) {
//             return Optional.of(absoluteBasePath.relativize(normalizedAbsolutePath));
//         }
// 
//         return Optional.empty();
//     }
// 
//     public static boolean isValidPath(Path basePath, Path path) {
//         return normalize(basePath, path).isPresent();
//     }
// 
//     public static List<Path> expandDirectories(Path basePath, List<Path> paths) throws IOException {
//         ArrayList<Path> result = new ArrayList<>();
//         for (Path path : paths) {
//             result.addAll(expandDirectory(basePath, path));
//         }
// 
//         return result;
//     }
// 
//     public static List<Path> expandDirectory(Path basePath, Path path) throws IOException {
//         return Files
//                 .walk(basePath.resolve(path).normalize())
//                 .filter(subPath -> !Files.isDirectory(subPath))
//                 .map(subPath -> normalize(basePath, subPath))
//                 .filter(Optional::isPresent)
//                 .map(Optional::get)
//                 .collect(Collectors.toList());
//     }
// 
//     public static String separatorsToUnix(Path path) {
//         // Path will normalize separators back to Windows when run on Windows. We have to fall back to a String here.
//         return path.toString().replace('\\', '/');
//     }
// }


// Path: heroku-deploy/src/test/java/com/heroku/sdk/deploy/lib/PathUtilsTest.java
import com.heroku.sdk.deploy.util.PathUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.stream.Collectors;
import static org.junit.Assert.*;

package com.heroku.sdk.deploy.lib;




public class PathUtilsTest {
    private Path basePath = Paths.get("/home/user/projects/project");
    private Path existingBasePath;

    @Test
    public void testNormalizeAll() {
        ArrayList<Path> pathsToNormalize = new ArrayList<>();
        ArrayList<Path> expectedNormalizedPaths = new ArrayList<>();

        pathsToNormalize.add(Paths.get("README.md"));
        expectedNormalizedPaths.add(Paths.get("README.md"));

        pathsToNormalize.add(Paths.get("docs//HACKING.md"));
        expectedNormalizedPaths.add(Paths.get("docs/HACKING.md"));

        pathsToNormalize.add(Paths.get("target/dependencies/../project.war"));
        expectedNormalizedPaths.add(Paths.get("target/project.war"));

        pathsToNormalize.add(Paths.get("/home/user/projects/project/target/dependencies/dep1.jar"));
        expectedNormalizedPaths.add(Paths.get("target/dependencies/dep1.jar"));

        pathsToNormalize.add(Paths.get("../../projects/project/start.sh"));
        expectedNormalizedPaths.add(Paths.get("start.sh"));

        pathsToNormalize.add(Paths.get("../README.md"));
        // We expect this to be filtered out, hence no expectedNormalizedPaths entry here.

        List<Path> normalizedPaths = PathUtils.normalizeAll(basePath, pathsToNormalize);