Skip to content

Commit

Permalink
[MPH-183] Do not print same location twice and rename test methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Giovds committed Mar 29, 2024
1 parent 3073624 commit 3f989f6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public String toString(InputLocation location) {

StringBuilder p = new StringBuilder();

while (importedFrom != null) {
while (importedFrom != null
&& !source.toString().equals(importedFrom.getSource().toString())) {
p.append(" from ").append(importedFrom.getSource().getModelId());
importedFrom = getImportedFrom(importedFrom);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public class ImportedFromLocationFormatterTest {

@Test
public void testImportedFromNullToString() {
public void testImportedFromSingleLocation() {
// Arrange
final MavenProject project = new MavenProject();
final ImportedFromLocationFormatter formatter = new ImportedFromLocationFormatterMock(project);
Expand All @@ -47,7 +47,28 @@ public void testImportedFromNullToString() {
}

@Test
public void testImportedFromNotNullToString() {
public void testImportedFromDifferentLocation() {
// Arrange
final InputSource importedFromSource = new InputSource();
importedFromSource.setModelId("org.example:MPG-183-bom2:1-SNAPSHOT");
final InputLocation importedFrom = new InputLocation(7, 5, importedFromSource);

final MavenProject project = new MavenProject();
final ImportedFromLocationFormatter formatter = new ImportedFromLocationFormatterMock(project, importedFrom);

final InputSource source = new InputSource();
source.setModelId("org.example:MPG-183-bom1:1-SNAPSHOT");
final InputLocation location = new InputLocation(7, 5, source);

// Act
final String result = formatter.toString(location);

// Assert
assertEquals("}org.example:MPG-183-bom1:1-SNAPSHOT, line 7 from org.example:MPG-183-bom2:1-SNAPSHOT", result);
}

@Test
public void testImportedFromDoNotPrintSameLocationTwice() {
// Arrange
final InputSource importedFromSource = new InputSource();
importedFromSource.setModelId("org.example:MPG-183-bom:1-SNAPSHOT");
Expand All @@ -57,18 +78,18 @@ public void testImportedFromNotNullToString() {
final ImportedFromLocationFormatter formatter = new ImportedFromLocationFormatterMock(project, importedFrom);

final InputSource source = new InputSource();
source.setModelId("org.example:MPG-183-project:1-SNAPSHOT");
source.setModelId("org.example:MPG-183-bom:1-SNAPSHOT");
final InputLocation location = new InputLocation(7, 5, source);

// Act
final String result = formatter.toString(location);

// Assert
assertEquals("}org.example:MPG-183-project:1-SNAPSHOT, line 7 from org.example:MPG-183-bom:1-SNAPSHOT", result);
assertEquals("}org.example:MPG-183-bom:1-SNAPSHOT, line 7", result);
}

@Test
public void testMultipleImportedFromToString() {
public void testImportedFromMultiLevelPrintsWithFrom() {
// Arrange
final ImportedFromLocationFormatter formatter = createMultiImportedFromFormatter();

Expand Down

0 comments on commit 3f989f6

Please sign in to comment.