From 74b959e4514e1d1a8341f59963857bfc9958dab0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Pfeuffer?= Date: Fri, 15 May 2020 13:03:52 +0200 Subject: [PATCH] handle both paths as effected for rename --- .../sonia/scm/repository/Modification.java | 25 ++++--- .../sonia/scm/repository/Modifications.java | 8 +- .../scm/repository/ModificationsTest.java | 73 +++++++++++++++++++ 3 files changed, 93 insertions(+), 13 deletions(-) create mode 100644 scm-core/src/test/java/sonia/scm/repository/ModificationsTest.java diff --git a/scm-core/src/main/java/sonia/scm/repository/Modification.java b/scm-core/src/main/java/sonia/scm/repository/Modification.java index 94d74ae722..2b675230fa 100644 --- a/scm-core/src/main/java/sonia/scm/repository/Modification.java +++ b/scm-core/src/main/java/sonia/scm/repository/Modification.java @@ -28,6 +28,9 @@ import lombok.AllArgsConstructor; import lombok.Getter; import java.io.Serializable; +import java.util.stream.Stream; + +import static java.util.stream.Stream.of; public interface Modification extends EffectedPath, Serializable { @@ -37,8 +40,8 @@ public interface Modification extends EffectedPath, Serializable { private final String path; @Override - public String getEffectedPath() { - return path; + public Stream getEffectedPaths() { + return of(path); } } @@ -48,8 +51,8 @@ public interface Modification extends EffectedPath, Serializable { private final String path; @Override - public String getEffectedPath() { - return path; + public Stream getEffectedPaths() { + return of(path); } } @@ -59,8 +62,8 @@ public interface Modification extends EffectedPath, Serializable { private final String path; @Override - public String getEffectedPath() { - return path; + public Stream getEffectedPaths() { + return of(path); } } @@ -71,8 +74,8 @@ public interface Modification extends EffectedPath, Serializable { private final String newPath; @Override - public String getEffectedPath() { - return newPath; + public Stream getEffectedPaths() { + return of(oldPath, newPath); } } @@ -83,12 +86,12 @@ public interface Modification extends EffectedPath, Serializable { private final String targetPath; @Override - public String getEffectedPath() { - return targetPath; + public Stream getEffectedPaths() { + return of(targetPath); } } } interface EffectedPath { - String getEffectedPath(); + Stream getEffectedPaths(); } diff --git a/scm-core/src/main/java/sonia/scm/repository/Modifications.java b/scm-core/src/main/java/sonia/scm/repository/Modifications.java index ce43fe58f8..891bf50216 100644 --- a/scm-core/src/main/java/sonia/scm/repository/Modifications.java +++ b/scm-core/src/main/java/sonia/scm/repository/Modifications.java @@ -25,7 +25,6 @@ package sonia.scm.repository; import com.google.common.collect.ImmutableList; -import lombok.Builder; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; @@ -33,6 +32,7 @@ import lombok.ToString; import java.io.Serializable; import java.util.Collection; import java.util.List; +import java.util.stream.Stream; import static java.util.Arrays.asList; import static java.util.stream.Collectors.toList; @@ -57,7 +57,11 @@ public class Modifications implements Serializable { } public List getEffectedPaths() { - return modifications.stream().map(Modification::getEffectedPath).collect(toList()); + return effectedPathsStream().collect(toList()); + } + + public Stream effectedPathsStream() { + return modifications.stream().flatMap(Modification::getEffectedPaths); } public List getAdded() { diff --git a/scm-core/src/test/java/sonia/scm/repository/ModificationsTest.java b/scm-core/src/test/java/sonia/scm/repository/ModificationsTest.java new file mode 100644 index 0000000000..2832d8f5ef --- /dev/null +++ b/scm-core/src/test/java/sonia/scm/repository/ModificationsTest.java @@ -0,0 +1,73 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.repository; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; + +class ModificationsTest { + + public static final Modifications MODIFICATIONS = new Modifications("123", + new Modification.Added("added"), + new Modification.Removed("removed"), + new Modification.Modified("modified"), + new Modification.Renamed("rename from", "rename to"), + new Modification.Copied("copy from", "copy to") + ); + + @Test + void shouldFindAddedFilesAsEffected() { + assertThat(MODIFICATIONS.getEffectedPaths()) + .contains("added"); + } + + @Test + void shouldFindRemovedFilesAsEffected() { + assertThat(MODIFICATIONS.getEffectedPaths()) + .contains("removed"); + } + + @Test + void shouldFindModifiedFilesAsEffected() { + assertThat(MODIFICATIONS.getEffectedPaths()) + .contains("modified"); + } + + @Test + void shouldFindRenamedFilesAsEffected() { + assertThat(MODIFICATIONS.getEffectedPaths()) + .contains("rename from", "rename to"); + } + + @Test + void shouldFindTargetOfCopiedFilesAsEffected() { + assertThat(MODIFICATIONS.getEffectedPaths()) + .contains("copy to") + .doesNotContain("copy from"); + } +}