handle both paths as effected for rename

This commit is contained in:
René Pfeuffer
2020-05-15 13:03:52 +02:00
parent 35ffc5c4e2
commit 74b959e451
3 changed files with 93 additions and 13 deletions

View File

@@ -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<String> 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<String> 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<String> 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<String> 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<String> getEffectedPaths() {
return of(targetPath);
}
}
}
interface EffectedPath {
String getEffectedPath();
Stream<String> getEffectedPaths();
}

View File

@@ -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<String> getEffectedPaths() {
return modifications.stream().map(Modification::getEffectedPath).collect(toList());
return effectedPathsStream().collect(toList());
}
public Stream<String> effectedPathsStream() {
return modifications.stream().flatMap(Modification::getEffectedPaths);
}
public List<Modification.Added> getAdded() {

View File

@@ -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");
}
}