Skip to content

Commit

Permalink
Reduce diff for easier code review
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkEWaite committed Jul 1, 2023
1 parent 080cfb8 commit fd64d80
Showing 1 changed file with 26 additions and 31 deletions.
57 changes: 26 additions & 31 deletions src/test/java/jenkins/plugins/git/GitSCMFileSystemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -404,43 +404,38 @@ public void create_SCMFileSystem_from_tag() throws Exception {
assertEquals("modified", getFileContent(fs, "dir/subdir/file", "modified"));
}

public static List<UserRemoteConfig> createRepoListWithRefspec(String url, String refspec) {
List<UserRemoteConfig> repoList = new ArrayList<>();
repoList.add(new UserRemoteConfig(url, null, refspec, null));
return repoList;
}

public String getFileContent(SCMFileSystem fs, String path, String expectedContent) throws IOException, InterruptedException {
assertThat(fs, notNullValue());
assertThat(fs.getRoot(), notNullValue());
String[] segments = path.split("/");

SCMFile parent = fs.getRoot();
SCMFile file = null;
for (String segment: segments) {
Iterable<SCMFile> children = parent.children();
Iterator<SCMFile> iterator = children.iterator();
if (segment == segments[segments.length - 1]) {
// file
assertThat(iterator.hasNext(), is(true));
SCMFile t = iterator.next();
assertThat(iterator.hasNext(), is(false));
assertThat(t.getName(), is(segment));
assertThat(t.getType(), is(SCMFile.Type.REGULAR_FILE));
file = t;
} else {
// dir
assertThat(iterator.hasNext(), is(true));
SCMFile dir = iterator.next();
assertThat(iterator.hasNext(), is(false));
assertThat(dir.getName(), is(segment));
assertThat(dir.getType(), is(SCMFile.Type.DIRECTORY));
parent = dir;
}
}
Iterable<SCMFile> children = fs.getRoot().children();
Iterator<SCMFile> iterator = children.iterator();
assertThat(iterator.hasNext(), is(true));
SCMFile dir = iterator.next();
assertThat(iterator.hasNext(), is(false));
assertThat(dir.getName(), is("dir"));
assertThat(dir.getType(), is(SCMFile.Type.DIRECTORY));
children = dir.children();
iterator = children.iterator();
assertThat(iterator.hasNext(), is(true));
SCMFile subdir = iterator.next();
assertThat(iterator.hasNext(), is(false));
assertThat(subdir.getName(), is("subdir"));
assertThat(subdir.getType(), is(SCMFile.Type.DIRECTORY));
children = subdir.children();
iterator = children.iterator();
assertThat(iterator.hasNext(), is(true));
SCMFile file = iterator.next();
assertThat(iterator.hasNext(), is(false));
assertThat(file.getName(), is("file"));
return file.contentAsString();
}

public static List<UserRemoteConfig> createRepoListWithRefspec(String url, String refspec) {
List<UserRemoteConfig> repoList = new ArrayList<>();
repoList.add(new UserRemoteConfig(url, null, refspec, null));
return repoList;
}

@Test
public void create_SCMFileSystem_from_commit() throws Exception {
sampleRepo.init();
Expand Down

0 comments on commit fd64d80

Please sign in to comment.