/
GitConfigNodeTransformerTest.java
68 lines (53 loc) · 3.35 KB
/
GitConfigNodeTransformerTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.synopsys.integration.detectable.detectables.git.parsing.model;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import com.synopsys.integration.detectable.detectables.git.parsing.parse.GitConfigNodeTransformer;
class GitConfigNodeTransformerTest {
@Test
void createGitConfig() {
//#region Create GitConfigNodes
// The core node should be ignored by the transformation.
final Map<String, String> coreProperties = new HashMap<>();
coreProperties.put("repositoryformatversion", "0");
coreProperties.put("filemode", "true");
final GitConfigNode coreNode = new GitConfigNode("core", coreProperties);
final Map<String, String> remoteProperties = new HashMap<>();
remoteProperties.put("url", "https://github.com/blackducksoftware/synopsys-detect.git");
remoteProperties.put("fetch", "+refs/heads/*:refs/remotes/origin/");
final GitConfigNode remoteNode = new GitConfigNode("remote", "origin", remoteProperties);
final Map<String, String> branchProperties = new HashMap<>();
branchProperties.put("remote", "origin");
branchProperties.put("merge", "refs/heads/master");
final GitConfigNode branchNode = new GitConfigNode("branch", "master", branchProperties);
final Map<String, String> anotherBranchProperties = new HashMap<>();
anotherBranchProperties.put("remote", "origin");
anotherBranchProperties.put("merge", "refs/heads/another-branch");
final GitConfigNode anotherBranch = new GitConfigNode("branch", "another-branch", anotherBranchProperties);
final List<GitConfigNode> gitConfigNodes = new ArrayList<>();
gitConfigNodes.add(coreNode);
gitConfigNodes.add(remoteNode);
gitConfigNodes.add(branchNode);
gitConfigNodes.add(anotherBranch);
//#endregion Create GitConfigNodes
final GitConfigNodeTransformer gitConfigNodeTransformer = new GitConfigNodeTransformer();
final GitConfig gitConfig = gitConfigNodeTransformer.createGitConfig(gitConfigNodes);
Assertions.assertEquals(1, gitConfig.getGitConfigRemotes().size());
final GitConfigRemote gitConfigRemote = gitConfig.getGitConfigRemotes().get(0);
Assertions.assertEquals("origin", gitConfigRemote.getName());
Assertions.assertEquals("https://github.com/blackducksoftware/synopsys-detect.git", gitConfigRemote.getUrl());
Assertions.assertEquals("+refs/heads/*:refs/remotes/origin/", gitConfigRemote.getFetch());
Assertions.assertEquals(2, gitConfig.getGitConfigBranches().size());
final GitConfigBranch gitConfigBranch1 = gitConfig.getGitConfigBranches().get(0);
Assertions.assertEquals("master", gitConfigBranch1.getName());
Assertions.assertEquals("origin", gitConfigBranch1.getRemoteName());
Assertions.assertEquals("refs/heads/master", gitConfigBranch1.getMerge());
final GitConfigBranch gitConfigAnotherBranch = gitConfig.getGitConfigBranches().get(1);
Assertions.assertEquals("another-branch", gitConfigAnotherBranch.getName());
Assertions.assertEquals("origin", gitConfigAnotherBranch.getRemoteName());
Assertions.assertEquals("refs/heads/another-branch", gitConfigAnotherBranch.getMerge());
}
}