Skip to content

Commit

Permalink
dup packages
Browse files Browse the repository at this point in the history
  • Loading branch information
astubbs committed Apr 21, 2022
1 parent 055b94d commit 69a29b1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
import io.stubbs.truth.generator.internal.RecursiveClassDiscovery;
import lombok.Getter;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;

import static java.util.Arrays.asList;
Expand All @@ -22,6 +20,7 @@
*
* @author Antony Stubbs
*/
@Slf4j
@Getter
public class SourceClassSets {

Expand Down Expand Up @@ -100,7 +99,17 @@ public void generateAllFoundInPackages(Package... packages) {
}

public void generateAllFoundInPackages(String... packageNames) {
simplePackageNames.addAll(stream(packageNames).collect(toSet()));
// filter sub packages
stream(packageNames).forEach(packageToAdd -> {
Optional<String> matchingSuperPackage = simplePackageNames.stream()
.filter(packageToAdd::startsWith)
.findAny();
if (matchingSuperPackage.isEmpty()) {
simplePackageNames.add(packageToAdd);
} else {
log.info("Skipping package {}, is it is a sub package of {} which is already added", packageToAdd, matchingSuperPackage.get());
}
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
import static io.stubbs.truth.generator.internal.TruthGeneratorTest.TEST_OUTPUT_DIRECTORY;

/**
* Where there are duplicate entries of classes in the target sets
*
* @see SourceClassSets
*/
public class SourceClassSetsTests {

/**
* Where there are duplicate entries of classes in the target sets
*/
// todo use bootstrapped ResultSubject
@Test
public void duplicates() {
public void duplicatesClassInSpecifiedPackage() {
TruthGenerator tg = TruthGeneratorAPI.createDefaultOptions(TEST_OUTPUT_DIRECTORY);
SourceClassSets ss = new SourceClassSets(SourceClassSets.class);

Expand All @@ -33,4 +32,22 @@ public void duplicates() {
assertThat(allGeneratedSystems).containsKey(ThreeSystem.class);
}

@Test
public void duplicatesPackageAndSubPackage() {
TruthGenerator tg = TruthGeneratorAPI.createDefaultOptions(TEST_OUTPUT_DIRECTORY);
SourceClassSets ss = new SourceClassSets(SourceClassSets.class);

// the issue
ss.generateFrom(ThreeSystem.class);
ss.generateAllFoundInPackages("io.stubbs.truth.generator",
"io.stubbs.truth.generator.subjects");

// the test
var allGeneratedSystems = tg.generate(ss).getAll();

// will have crashed already if the fix didn't work
assertThat(allGeneratedSystems).containsKey(ThreeSystem.class);
}


}

0 comments on commit 69a29b1

Please sign in to comment.