This repository has been archived by the owner on Sep 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: after a merge that contained conflicting files, the commit wind…
…ow is shown and contains a preformed commit message detailing the conflicting files
- Loading branch information
Showing
4 changed files
with
249 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
gui/src/test/java/de/adito/git/gui/actions/MergeActionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package de.adito.git.gui.actions; | ||
|
||
import de.adito.git.api.IRepository; | ||
import de.adito.git.api.data.IBranch; | ||
import de.adito.git.api.data.IRepositoryState; | ||
import de.adito.git.api.data.diff.IMergeData; | ||
import io.reactivex.rxjava3.core.Observable; | ||
import lombok.NonNull; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.TestInstance; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Stream; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
/** | ||
* Tests for the MergeAction class | ||
* | ||
* @author m.kaspera, 09.08.2023 | ||
*/ | ||
class MergeActionTest | ||
{ | ||
|
||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
@Nested | ||
class CreateSuggestedCommitMessage | ||
{ | ||
|
||
/** | ||
* @param pCurrentBranch Name of the current branch | ||
* @param pMergeBranch Name of the branch that is merged into the current one | ||
* @param pFilePaths List with conflicting filePaths | ||
*/ | ||
@ParameterizedTest | ||
@MethodSource("suggestedCommitMessageSource") | ||
void doesMessageContainNecessaryInfos(@NonNull String pCurrentBranch, @NonNull String pMergeBranch, @NonNull List<String> pFilePaths) | ||
{ | ||
IRepository repository = createMockRepo(pCurrentBranch); | ||
|
||
IBranch mergeBranch = mock(IBranch.class); | ||
when(mergeBranch.getSimpleName()).thenReturn(pMergeBranch); | ||
|
||
List<IMergeData> mergeData = new ArrayList<>(); | ||
pFilePaths.forEach(pFilePath -> { | ||
IMergeData data = mock(IMergeData.class); | ||
when(data.getFilePath()).thenReturn(pFilePath); | ||
mergeData.add(data); | ||
}); | ||
|
||
String suggestedCommitMessage = MergeAction.createSuggestedCommitMessage(repository, mergeBranch, mergeData); | ||
|
||
pFilePaths.forEach(filePath -> assertTrue(suggestedCommitMessage.contains(filePath))); | ||
assertAll(() -> assertEquals(pFilePaths.isEmpty(), !suggestedCommitMessage.contains("\n")), | ||
// check if the branch names are mentioned in the message | ||
() -> assertTrue(suggestedCommitMessage.contains(pCurrentBranch)), | ||
() -> assertTrue(suggestedCommitMessage.contains(pMergeBranch))); | ||
} | ||
|
||
/** | ||
* create a mocked repository | ||
* | ||
* @param pCurrentBranch Name of the current branch | ||
* @return Mocked IRepository that returns a mocked repositoryState that as the current Branch set (mocked again) | ||
*/ | ||
@NonNull | ||
private IRepository createMockRepo(@NonNull String pCurrentBranch) | ||
{ | ||
IRepository repository = mock(IRepository.class); | ||
IRepositoryState repositoryState = mock(IRepositoryState.class); | ||
IBranch currentBranch = mock(IBranch.class); | ||
|
||
when(repository.getRepositoryState()).thenReturn(Observable.just(Optional.of(repositoryState))); | ||
when(repositoryState.getCurrentBranch()).thenReturn(currentBranch); | ||
when(currentBranch.getSimpleName()).thenReturn(pCurrentBranch); | ||
return repository; | ||
} | ||
|
||
/** | ||
* @return Stream of Arguments for the doesMessageContainConflictingFiles test | ||
*/ | ||
public Stream<Arguments> suggestedCommitMessageSource() | ||
{ | ||
return Stream.of(Arguments.of("main", "dev", List.of()), | ||
Arguments.of("main", "dev", List.of("entity/org/process/test.js")), | ||
Arguments.of("main", "dev", List.of("package.json", "")), | ||
Arguments.of("main", "dev", List.of("package.json", "entity/org/org_entity.aod"))); | ||
} | ||
|
||
} | ||
|
||
} |