Support rename in rest layer

This commit is contained in:
René Pfeuffer
2020-05-11 17:19:38 +02:00
parent fba34b3bab
commit 5421d41161
2 changed files with 30 additions and 4 deletions

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.api.v2.resources;
import de.otto.edison.hal.Link;
@@ -35,11 +35,13 @@ import sonia.scm.repository.api.DiffResult;
import sonia.scm.repository.api.Hunk;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.OptionalInt;
import static java.net.URI.create;
import static java.util.Collections.emptyIterator;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -60,6 +62,7 @@ class DiffResultToDiffResultDtoMapperTest {
assertAddedFile(files.get(0), "A.java", "abc", "java");
assertModifiedFile(files.get(1), "B.ts", "abc", "def", "typescript");
assertDeletedFile(files.get(2), "C.go", "ghi", "golang");
assertRenamedFile(files.get(3), "typo.ts", "okay.ts", "def", "fixed", "typescript");
DiffResultDto.HunkDto hunk = files.get(1).getHunks().get(0);
assertHunk(hunk, "@@ -3,4 1,2 @@", 1, 2, 3, 4);
@@ -104,7 +107,8 @@ class DiffResultToDiffResultDtoMapperTest {
deletedLine("c", 3)
)
),
deletedFile("C.go", "ghi")
deletedFile("C.go", "ghi"),
renamedFile("okay.ts", "typo.ts", "fixed", "def")
);
}
@@ -161,6 +165,15 @@ class DiffResultToDiffResultDtoMapperTest {
assertThat(file.getLanguage()).isEqualTo(language);
}
private void assertRenamedFile(DiffResultDto.FileDto file, String oldPath, String newPath, String oldRevision, String newRevision, String language) {
assertThat(file.getOldPath()).isEqualTo(oldPath);
assertThat(file.getNewPath()).isEqualTo(newPath);
assertThat(file.getOldRevision()).isEqualTo(oldRevision);
assertThat(file.getNewRevision()).isEqualTo(newRevision);
assertThat(file.getType()).isEqualTo("rename");
assertThat(file.getLanguage()).isEqualTo(language);
}
private DiffResult result(DiffFile... files) {
DiffResult result = mock(DiffResult.class);
when(result.iterator()).thenReturn(Arrays.asList(files).iterator());
@@ -193,6 +206,16 @@ class DiffResultToDiffResultDtoMapperTest {
return file;
}
private DiffFile renamedFile(String newPath, String oldPath, String newRevision, String oldRevision) {
DiffFile file = mock(DiffFile.class);
when(file.getNewPath()).thenReturn(newPath);
when(file.getNewRevision()).thenReturn(newRevision);
when(file.getOldPath()).thenReturn(oldPath);
when(file.getOldRevision()).thenReturn(oldRevision);
when(file.iterator()).thenReturn(emptyIterator());
return file;
}
private Hunk hunk(String rawHeader, int newStart, int newLineCount, int oldStart, int oldLineCount, DiffLine... lines) {
Hunk hunk = mock(Hunk.class);
when(hunk.getRawHeader()).thenReturn(rawHeader);