Skip to content

Commit

Permalink
Remove CodeDeltaException.java.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Jan 9, 2023
1 parent e4e15f2 commit a4c74b9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*
* @author Florian Orendi
*/
public class CodeDeltaCalculator {
class CodeDeltaCalculator {
static final String AMBIGUOUS_PATHS_ERROR =
"Failed to map SCM paths with coverage report paths due to ambiguous fully qualified names";
static final String AMBIGUOUS_OLD_PATHS_ERROR =
Expand Down Expand Up @@ -62,7 +62,7 @@ public class CodeDeltaCalculator {
* @param scm
* The selected SCM
*/
public CodeDeltaCalculator(final Run<?, ?> build, final FilePath workspace,
CodeDeltaCalculator(final Run<?, ?> build, final FilePath workspace,
final TaskListener listener, final String scm) {
this.build = build;
this.workspace = workspace;
Expand Down Expand Up @@ -114,11 +114,11 @@ public Set<FileChanges> getCoverageRelevantChanges(final Delta delta) {
* logger
*
* @return the created mapping of code changes
* @throws CodeDeltaException
* @throws IllegalStateException
* when creating the mapping failed due to ambiguous paths
*/
public Map<String, FileChanges> mapScmChangesToReportPaths(
final Set<FileChanges> changes, final Node root, final FilteredLog log) throws CodeDeltaException {
final Set<FileChanges> changes, final Node root, final FilteredLog log) throws IllegalStateException {
Set<String> reportPaths = new HashSet<>(root.getFiles());
Set<String> scmPaths = changes.stream().map(FileChanges::getFileName).collect(Collectors.toSet());

Expand Down Expand Up @@ -149,12 +149,12 @@ public Map<String, FileChanges> mapScmChangesToReportPaths(
*
* @return the created mapping whose keys are the currently used paths and whose values are the paths before the
* modifications
* @throws CodeDeltaException
* @throws IllegalStateException
* if the SCM path mapping is ambiguous
*/
public Map<String, String> createOldPathMapping(final Node root, final Node referenceRoot,
final Map<String, FileChanges> changes, final FilteredLog log)
throws CodeDeltaException {
throws IllegalStateException {
Set<String> oldReportPaths = new HashSet<>(referenceRoot.getFiles());
// mapping between reference and current file paths which initially contains the SCM paths with renamings
Map<String, String> oldPathMapping = changes.entrySet().stream()
Expand All @@ -171,7 +171,7 @@ public Map<String, String> createOldPathMapping(final Node root, final Node refe
oldPathMapping.replace(reportPath, oldReportPath);
});
if (!newReportPathsWithRename.equals(oldPathMapping.keySet())) {
throw new CodeDeltaException(AMBIGUOUS_OLD_PATHS_ERROR);
throw new IllegalStateException(AMBIGUOUS_OLD_PATHS_ERROR);
}

// adding the paths, which exist in both trees and contain no changes, to the mapping
Expand Down Expand Up @@ -219,16 +219,16 @@ private Map<String, String> getScmToReportPathMapping(
* @param log
* The log
*
* @throws CodeDeltaException
* @throws IllegalStateException
* when ambiguous paths has been detected
*/
private void verifyScmToReportPathMapping(final Map<String, String> pathMapping, final FilteredLog log)
throws CodeDeltaException {
throws IllegalStateException {
List<String> notEmptyValues = pathMapping.values().stream()
.filter(path -> !path.isEmpty())
.collect(Collectors.toList());
if (notEmptyValues.size() != new HashSet<>(notEmptyValues).size()) {
throw new CodeDeltaException(AMBIGUOUS_PATHS_ERROR);
throw new IllegalStateException(AMBIGUOUS_PATHS_ERROR);
}
log.logInfo("Successfully mapped SCM paths to coverage report paths");
}
Expand Down Expand Up @@ -266,11 +266,11 @@ private void removeMissingReferences(final Map<String, String> oldPathMapping, f
* @param log
* The log
*
* @throws CodeDeltaException
* @throws IllegalStateException
* when the mapping is ambiguous
*/
static void verifyOldPathMapping(final Map<String, String> oldPathMapping, final FilteredLog log)
throws CodeDeltaException {
throws IllegalStateException {
Set<String> duplicates = StreamEx.of(oldPathMapping.values())
.distinct(2)
.collect(Collectors.toSet());
Expand All @@ -286,7 +286,7 @@ static void verifyOldPathMapping(final Map<String, String> oldPathMapping, final
.collect(Collectors.joining("," + System.lineSeparator()));
String errorMessage =
CODE_DELTA_TO_COVERAGE_DATA_MISMATCH_ERROR_TEMPLATE + System.lineSeparator() + mismatches;
throw new CodeDeltaException(errorMessage);
throw new IllegalStateException(errorMessage);
}
log.logInfo("Successfully verified that the coverage data matches with the code delta");
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ private void createDeltaReports(final Node rootNode, final FilteredLog log, fina
log.logInfo("Obtaining coverage delta for files...");
fileChangesProcessor.attachFileCoverageDeltas(rootNode, referenceRoot, oldPathMapping);
}
catch (CodeDeltaException e) {
catch (IllegalStateException exception) {
log.logError("An error occurred while processing code and coverage changes:");
log.logError("-> Message: " + e.getMessage());
log.logError("-> Message: " + exception.getMessage());
log.logError("-> Skipping calculating change coverage and indirect coverage changes");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void shouldGetCoverageRelevantChanges() {
}

@Test
void shouldMapScmChangesToReportPaths() throws CodeDeltaException {
void shouldMapScmChangesToReportPaths() throws IllegalStateException {
CodeDeltaCalculator codeDeltaCalculator = createCodeDeltaCalculator();
Delta delta = createDeltaWithStubbedFileChanges();
Set<FileChanges> changes = codeDeltaCalculator.getCoverageRelevantChanges(delta);
Expand All @@ -99,7 +99,7 @@ void shouldMapScmChangesToReportPaths() throws CodeDeltaException {
}

@Test
void shouldCreateEmptyMappingWithoutChanges() throws CodeDeltaException {
void shouldCreateEmptyMappingWithoutChanges() throws IllegalStateException {
CodeDeltaCalculator codeDeltaCalculator = createCodeDeltaCalculator();
Node tree = createStubbedCoverageTree();
FilteredLog log = createFilteredLog();
Expand All @@ -109,7 +109,7 @@ void shouldCreateEmptyMappingWithoutChanges() throws CodeDeltaException {
}

@Test
void shouldNotMapScmChangesWithAmbiguousPaths() throws CodeDeltaException {
void shouldNotMapScmChangesWithAmbiguousPaths() throws IllegalStateException {
CodeDeltaCalculator codeDeltaCalculator = createCodeDeltaCalculator();
FilteredLog log = createFilteredLog();

Expand All @@ -123,12 +123,12 @@ void shouldNotMapScmChangesWithAmbiguousPaths() throws CodeDeltaException {
when(tree.getFiles()).thenReturn(List.of(path));

assertThatThrownBy(() -> codeDeltaCalculator.mapScmChangesToReportPaths(changes, tree, log))
.isInstanceOf(CodeDeltaException.class)
.isInstanceOf(IllegalStateException.class)
.hasMessage(AMBIGUOUS_PATHS_ERROR);
}

@Test
void shouldCreateOldPathMapping() throws CodeDeltaException {
void shouldCreateOldPathMapping() throws IllegalStateException {
CodeDeltaCalculator codeDeltaCalculator = createCodeDeltaCalculator();
FilteredLog log = createFilteredLog();
Node tree = createStubbedCoverageTree();
Expand All @@ -146,7 +146,7 @@ void shouldCreateOldPathMapping() throws CodeDeltaException {
}

@Test
void shouldNotCreateOldPathMappingWithMissingReferenceNodes() throws CodeDeltaException {
void shouldNotCreateOldPathMappingWithMissingReferenceNodes() throws IllegalStateException {
CodeDeltaCalculator codeDeltaCalculator = createCodeDeltaCalculator();
FilteredLog log = createFilteredLog();

Expand Down Expand Up @@ -175,7 +175,7 @@ void shouldNotCreateOldPathMappingWithCodeDeltaMismatches() {
changes.put(REPORT_PATH_MODIFY, createFileChanges(REPORT_PATH_MODIFY, OLD_SCM_PATH_RENAME, FileEditType.RENAME));

assertThatThrownBy(() -> codeDeltaCalculator.createOldPathMapping(tree, referenceTree, changes, log))
.isInstanceOf(CodeDeltaException.class)
.isInstanceOf(IllegalStateException.class)
.hasMessageStartingWith(CODE_DELTA_TO_COVERAGE_DATA_MISMATCH_ERROR_TEMPLATE)
.hasMessageContainingAll(
String.format("new: '%s' - former: '%s',", REPORT_PATH_RENAME, OLD_REPORT_PATH_RENAME),
Expand Down

0 comments on commit a4c74b9

Please sign in to comment.