Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ dependencies {
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion")
implementation("org.slf4j:slf4j-api:2.0.6")
compileOnly("org.jetbrains:annotations:24.0.0")

testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.2")
}

description = "General-purpose utilities and helper classes shared across Flamingock modules"
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/io/flamingock/internal/util/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.nio.file.Files;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Objects;

public final class FileUtil {
Expand All @@ -38,10 +39,15 @@ private FileUtil() {


public static List<File> getAllYamlFiles(File directory) {
FilenameFilter fileNameFilter = (dir, name) -> name.endsWith(".yaml");
FilenameFilter fileNameFilter = (dir, name) -> isYamlFileName(name);
return getAllFiles(directory, fileNameFilter);
}

private static boolean isYamlFileName(String fileName) {
String normalizedFileName = fileName.toLowerCase(Locale.ROOT);
return normalizedFileName.endsWith(".yaml") || normalizedFileName.endsWith(".yml");
}

public static List<File> getAllFiles(File directory, FilenameFilter filenameFilter) {
File[] files = directory.listFiles(filenameFilter);
return Arrays.asList(Objects.requireNonNull(files));
Expand Down
54 changes: 54 additions & 0 deletions src/test/java/io/flamingock/internal/util/FileUtilTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2026 Flamingock (https://www.flamingock.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.flamingock.internal.util;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.assertEquals;

class FileUtilTest {

@TempDir
Path tempDir;

@Test
void shouldReturnYamlAndYmlFilesIgnoringCase() throws Exception {
Files.createFile(tempDir.resolve("alpha.yaml"));
Files.createFile(tempDir.resolve("bravo.yml"));
Files.createFile(tempDir.resolve("charlie.YAML"));
Files.createFile(tempDir.resolve("delta.YmL"));
Files.createFile(tempDir.resolve("echo.txt"));

List<String> fileNames = FileUtil.getAllYamlFiles(tempDir.toFile())
.stream()
.map(File::getName)
.sorted()
.collect(Collectors.toList());

assertEquals(4, fileNames.size());
assertEquals("alpha.yaml", fileNames.get(0));
assertEquals("bravo.yml", fileNames.get(1));
assertEquals("charlie.YAML", fileNames.get(2));
assertEquals("delta.YmL", fileNames.get(3));
}
}
Loading