Skip to content

Commit

Permalink
Make sorting of available icons more stable
Browse files Browse the repository at this point in the history
  • Loading branch information
strangelookingnerd committed Mar 29, 2023
1 parent a7cf520 commit de0b95a
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

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

Expand Down Expand Up @@ -643,7 +644,7 @@ void testGetAvailableIcons(JenkinsRule r) throws Exception {
assertNotNull(icons);
assertEquals(3, icons.size());

Set<String> expected = Arrays.asList(file1, file2, file3).stream().sorted(Comparator.comparingLong((FilePath file) -> {
Set<String> expected = Stream.of(file1, file2, file3).sorted(Comparator.comparingLong((FilePath file) -> {
try {
return file.lastModified();
} catch (IOException | InterruptedException ex) {
Expand Down Expand Up @@ -775,13 +776,13 @@ void testGetAvailableIconsComparatorThrowingExceptions(JenkinsRule r) throws Exc
assertEquals(3, icons.size());
}

Set<String> expected = Arrays.asList(file1, file2, file3).stream().sorted((filePath1, filePath2) -> {
Set<String> expected = Stream.of(file1, file2, file3).sorted(Comparator.comparingLong((FilePath file) -> {
try {
return Long.compare(filePath2.lastModified(), filePath1.lastModified());
} catch (Exception ex) {
return file.lastModified();
} catch (IOException | InterruptedException ex) {
return 0;
}
}).map(FilePath::getName).collect(Collectors.toSet());
}).reversed()).map(FilePath::getName).collect(Collectors.toSet());

assertEquals(expected, icons);
}
Expand Down

0 comments on commit de0b95a

Please sign in to comment.