FileSpecBuilder { public static List<IFileSpec> makeFileSpecList(@Nullable List<String> filePaths) { List<IFileSpec> fileSpecs = new ArrayList<>(); if (nonNull(filePaths)) { for (String filePath : filePaths) { if (isNotBlank(filePath)) { IFileSpec fileSpec = new FileSpec(filePath); fileSpecs.add(fileSpec); } } } return fileSpecs; } private  FileSpecBuilder(); static List<IFileSpec> makeFileSpecList(@Nullable List<String> filePaths); static List<IFileSpec> makeFileSpecList(String... filePaths); static List<IFileSpec> getValidFileSpecs(@Nullable List<IFileSpec> fileSpecs); static List<IFileSpec> getInvalidFileSpecs(@Nullable List<IFileSpec> fileSpecs);  }
@Test public void makeFileSpecList_valid_list() throws Exception { String depotFileSpec = " String revision = "#2"; List<String> filePaths = new ArrayList<String>(); filePaths.add(depotFileSpec + revision); filePaths.add(depotFileSpec + "#3,#4"); List<IFileSpec> fileSpecs = FileSpecBuilder.makeFileSpecList(filePaths); assertThat(fileSpecs.size(), is(2)); IFileSpec fileSpec1 = fileSpecs.get(0); assertThat(fileSpec1.getOriginalPathString(), is(depotFileSpec)); assertThat(fileSpec1.getStartRevision(), is(-1)); assertThat(fileSpec1.getEndRevision(), is(2)); IFileSpec fileSpec2 = fileSpecs.get(1); assertThat(fileSpec2.getOriginalPathString(), is(depotFileSpec)); assertThat(fileSpec2.getStartRevision(), is(3)); assertThat(fileSpec2.getEndRevision(), is(4)); }
@Test public void makeFileSpecList_non_empty_path_string() throws Exception { String depotFileSpec = " List<IFileSpec> fileSpecs = FileSpecBuilder.makeFileSpecList(depotFileSpec); assertThat(fileSpecs.size(), is(1)); assertThat(fileSpecs.get(0).getOriginalPathString(), is(depotFileSpec)); }
@Test public void makeFileSpecList_non_empty_path_string_and_has_space() throws Exception { String depotFileSpec = " List<IFileSpec> fileSpecs = FileSpecBuilder.makeFileSpecList(depotFileSpec); assertThat(fileSpecs.size(), is(1)); assertThat(fileSpecs.get(0).getOriginalPathString(), is(depotFileSpec)); }
@Test public void makeFileSpecList_blank_path_string() throws Exception { String depotFileSpec = ""; List<IFileSpec> fileSpecs = FileSpecBuilder.makeFileSpecList(depotFileSpec); assertThat(fileSpecs.size(), is(0)); depotFileSpec = StringUtils.SPACE; fileSpecs = FileSpecBuilder.makeFileSpecList(depotFileSpec); assertThat(fileSpecs.size(), is(0)); }
@Test public void makeFileSpecList_null_path_string() throws Exception { List<IFileSpec> fileSpecs = FileSpecBuilder.makeFileSpecList(); assertThat(fileSpecs.size(), is(0)); }
@Test public void makeFileSpecList_hasRevisionAnnotations() throws Exception { String depotFileSpec = " String revision = "#2"; List<IFileSpec> fileSpecs = FileSpecBuilder.makeFileSpecList(depotFileSpec + revision); assertThat(fileSpecs.size(), is(1)); IFileSpec fileSpec = fileSpecs.get(0); assertThat(fileSpec.getOriginalPathString(), is(depotFileSpec)); assertThat(fileSpec.getStartRevision(), is(-1)); assertThat(fileSpec.getEndRevision(), is(2)); }
@Test public void makeFileSpecList_valid_list() throws Exception { String depotFileSpec = " String revision = "#2"; List<String> filePaths = ImmutableList.of(depotFileSpec + revision, depotFileSpec + "#3,#4"); List<IFileSpec> fileSpecs = FileSpecBuilder.makeFileSpecList(filePaths); assertThat(fileSpecs.size(), is(2)); IFileSpec fileSpec1 = fileSpecs.get(0); assertThat(fileSpec1.getOriginalPathString(), is(depotFileSpec)); assertThat(fileSpec1.getStartRevision(), is(-1)); assertThat(fileSpec1.getEndRevision(), is(2)); IFileSpec fileSpec2 = fileSpecs.get(1); assertThat(fileSpec2.getOriginalPathString(), is(depotFileSpec)); assertThat(fileSpec2.getStartRevision(), is(3)); assertThat(fileSpec2.getEndRevision(), is(4)); }
@Test public void testFileSpecWithAtAnnotation() throws Exception { String annotatedLabel = "@15"; List<IFileSpec> spec = FileSpecBuilder.makeFileSpecList(annotatedLabel); assertThat(spec.size(), is(1)); assertThat(spec.get(0).getAnnotatedPreferredPathString(), is(annotatedLabel)); }
@Test public void testFileSpecWithSharpAnnotation() throws Exception { String annotatedLabel = "#15"; List<IFileSpec> spec = FileSpecBuilder.makeFileSpecList(annotatedLabel); assertThat(spec.size(), is(1)); assertThat(spec.get(0).getAnnotatedPreferredPathString(), is(annotatedLabel)); }