Skip to content

Commit

Permalink
REFACTOR: (#10)
Browse files Browse the repository at this point in the history
* REFACTOR:
* Changed `public` to `protected` modifiers of the abstract class constructors
* Recurrent strings were extracted to constants
* Simplified methods
* Anonymous classes changed to lambdas to improve readability
* Javadoc link corrected
* Little visual formatting
* Javadoc corrections
  • Loading branch information
kamenkov authored May 15, 2023
1 parent 865c18e commit ca6aeef
Show file tree
Hide file tree
Showing 39 changed files with 254 additions and 230 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public ComponentReference(String identifier, String integrationIdentifier) {
}

@Override
public void init(F integrationFeatures) {/*do nothing: referenced component will be inited by it's own integration*/}
public void init(F integrationFeatures) {/*do nothing: referenced component will be inited by its own integration*/}

@Override
public String getIdentifier() {
Expand Down Expand Up @@ -77,5 +77,5 @@ private Integration<? extends IntegrationFeatures> getIntegration() {
}

@Override
public void close() {/*do nothing: referenced component will be closed by it's own integration*/}
public void close() {/*do nothing: referenced component will be closed by its own integration*/}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
import com.fasterxml.jackson.annotation.JsonTypeInfo;

/**
* The interface indicating an an entity which as an identifier and can be (de)serialized by fasterxml.jackson
* Uses default {@link JsonTypeInfo.As.PROPERTY} include for (de)serialization
* The interface indicating an entity which as an identifier and can be (de)serialized by fasterxml.jackson
* Uses default {@link JsonTypeInfo.As#PROPERTY} include for (de)serialization
*/
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
public interface Identifiable {
/**
* The entity identifier, unique within functional unit
* (i.e. a TestSplitter in integration among other TestSplitters in this integration, an Integration among other integrations in run etc.)
* (i.e. a TestSplitter in integration among other TestSplitters in this integration,
* an Integration among other integrations in run etc.)
*
* @return String entity identifier
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static void register(Integration<?> integration, ClassLoader classLoader)
/**
* Returns the list of all integrations
*
* @return full list of instantiated integrations integrations
* @return full list of instantiated integrations
*/
public static List<Integration<?>> getIntegrations() {
return Collections.unmodifiableList(new ArrayList<>(CONTEXTS.keySet()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.fasterxml.jackson.annotation.JsonIgnoreType;

/**
* This interface represents the features instantiated per {@link Integration> instance and then passed to each integration component
* This interface represents the features instantiated per {@link Integration} instance and then passed to each integration component
* e.g. jira/teamcity/http client, DB connection etc.
*/
@JsonIgnoreType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.List;

/**
* A component processing (complementing, decoding, splitting etc) specified tests
* A component processing (complementing, decoding, splitting etc.) specified tests
*/
public interface TestProcessor<F extends IntegrationFeatures> extends IntegrationComponent<F> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.List;

/**
* A component processing (complementing, decoding, splitting etc) specified tests runs
* A component processing (complementing, decoding, splitting etc.) specified tests runs
*/
public interface TestRunProcessor<F extends IntegrationFeatures> extends IntegrationComponent<F> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public abstract class AttributedEntity implements Identifiable {

protected AttributedEntity() {}

public AttributedEntity(String identifier, Attributes attributes) {
protected AttributedEntity(String identifier, Attributes attributes) {
this.identifier = identifier;
this.attributes = attributes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private static Map<String, Set<String>> copyAttribute(Map<String, LinkedHashSet<
}

public static final class Builder {
private LinkedHashMap<String, LinkedHashMap<String, LinkedHashSet<String>>> attributes = new LinkedHashMap<>();
private final LinkedHashMap<String, LinkedHashMap<String, LinkedHashSet<String>>> attributes = new LinkedHashMap<>();

private Builder() {}

Expand Down Expand Up @@ -259,7 +259,7 @@ public Builder mergeAttribute(String attributeKey, String valueKey, String value
}

/**
* Removes the existing attribute by it's key
* Removes the existing attribute by its key
*
* @param attributeKey key of attribute to remove
* @return updated instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public String toString() {

public static final class Builder {
private String identifier;
private Set<Test> tests = new HashSet<>();
private Attributes.Builder attributes = Attributes.newBuilder();
private final Set<Test> tests = new HashSet<>();
private final Attributes.Builder attributes = Attributes.newBuilder();

private Builder() {}

Expand All @@ -79,12 +79,12 @@ public Builder addTests(Collection<Test> tests) {
}

public Builder putAttributes(Attributes attributes) {
this.attributes.putAttributes(attributes).build();
this.attributes.putAttributes(attributes);
return this;
}

public Builder mergeAttributes(Attributes attributes) {
this.attributes.mergeAttributes(attributes).build();
this.attributes.mergeAttributes(attributes);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

/**
* {@link AttributePredicate} which tests whether the {@link Attributes} has a single value
* with key matching the specified regex {@link attributeKeyRegex} and value key matching the specified regex {@link attributeValueKeyRegex}
* with key matching the specified regex {@link #attributeKeyRegex} and value key matching the specified regex {@link #attributeValueKeyRegex}
*/
public class AttributeHasSingleValue implements AttributePredicate {
@JsonProperty(required = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* An implementation of {@link AttributePredicate} which tests whether the {@link Attributes} has a single key matching the specified regex {@link attributeKeyRegex}
* An implementation of {@link AttributePredicate} which tests whether the {@link Attributes} has a single key matching the specified regex {@link #attributeKeyRegex}
*/
public class AttributeIsPresent implements AttributePredicate {
@JsonProperty(required = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

/**
* An implementation of {@link AttributePredicate} which tests whether the {@link Attributes} has a value key
* matching the specified regex {@link attributeValueKeyRegex} with key matching the specified regex {@link attributeKeyRegex}
* matching the specified regex {@link #attributeValueKeyRegex} with key matching the specified regex {@link #attributeKeyRegex}
*/
public class AttributeValueKeyIsPresent implements AttributePredicate {
@JsonProperty(required = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

/**
* An implementation of {@link AttributePredicate} which tests whether the {@link Attributes} has a value
* matching the specified regex {@link valueRegex} with a value key matching the specified regex {@link attributeValueKeyRegex}
* and key matching the specified regex {@link attributeKeyRegex}
* matching the specified regex {@link #valueRegex} with a value key matching the specified regex {@link #attributeValueKeyRegex}
* and key matching the specified regex {@link #attributeKeyRegex}
*/
public class AttributeValueMatches implements AttributePredicate {
@JsonProperty(required = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

/**
* An implementation of {@link AttributePredicate} which tests whether the {@link Attributes} has values
* contains {@link attributeValues} (according to {@link Modifier specified})
* with a value key matching the specified regex {@link attributeValueKeyRegex}
* and key matching the specified regex {@link attributeKeyRegex}.
* contains {@link #attributeValues} (according to {@link Modifier specified})
* with a value key matching the specified regex {@link #attributeValueKeyRegex}
* and key matching the specified regex {@link #attributeKeyRegex}.
*/
public class AttributeValueSetContains implements AttributePredicate {
/**
* Enum specifying the checked relation between a set of attribute values and the specified collection of values:
* either the set of attribute values contains {@link ALL}, {@link ANY} or {@link EXACTLY} the same values as specified
* either the set of attribute values contains {@link #ALL}, {@link #ANY} or {@link #EXACTLY} the same values as specified
*/
public enum Modifier {
ALL(Set::containsAll),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/**
* This implementation of {@link ValuesExtractor} can be initiated by both {@link Test} and {@link TestRun}
* for extracting from {@link Attributes} a TestAttribute key matching specified {@link attributeKeyRegex}
* for extracting from {@link Attributes} a TestAttribute key matching specified {@link #attributeKeyRegex}
*/
public class AttributeKeyValuesExtractor implements TestRunValuesExtractor, TestValuesExtractor {
@JsonProperty(required = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/**
* This implementation of {@link ValuesExtractor} can be initiated by both {@link Test} and {@link TestRun}
* for extracting from {@link Attributes} a single TestAttribute value
* under specified {@link attributeKey} and {@link attributeValueKey}
* under specified {@link #attributeKey} and {@link #attributeValueKey}
*/
public class AttributeValuesExtractor implements TestRunValuesExtractor, TestValuesExtractor {
@JsonProperty(required = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

/**
* This implementation of {@link TestRunValuesExtractor} and {@link TestValuesExtractor}
* creating a String consisted of specified blocks. Each block is specified by it's String header and ValuesExtractor providing block body
* initiated with the same Test/TestRun as arguments.
* creating a String consisted of specified blocks. Each block is specified by its String header
* and ValuesExtractor providing block body initiated with the same Test/TestRun as arguments.
*/
public class BlockFormattingValuesExtractor implements TestRunValuesExtractor, TestValuesExtractor {
@JsonProperty(required = true)
Expand All @@ -37,11 +37,13 @@ public class BlockFormattingValuesExtractor implements TestRunValuesExtractor, T
@JsonProperty(defaultValue = "false")
private boolean showEmptyBlocks = false;

private BlockFormattingValuesExtractor() {}
private BlockFormattingValuesExtractor() {
}

public BlockFormattingValuesExtractor(List<Pair<String, ValuesExtractor>> blockExtractors, String headerSeparator, String blockSeparator,
boolean showEmptyBlocks)
{
public BlockFormattingValuesExtractor(List<Pair<String, ValuesExtractor>> blockExtractors,
String headerSeparator,
String blockSeparator,
boolean showEmptyBlocks) {
this.blockExtractors = blockExtractors;
this.headerSeparator = headerSeparator;
this.blockSeparator = blockSeparator;
Expand All @@ -68,11 +70,11 @@ public String getTestValue(Test t) {
return getValue(t, TestValuesExtractor.class, TestValuesExtractor::getTestValue);
}

private <T, C extends ValuesExtractor> String getValue(T t, Class<C> extractorClass, BiFunction<C, T, String> extractoeFunction) {
private <T, C extends ValuesExtractor> String getValue(T t, Class<C> extractorClass, BiFunction<C, T, String> extractorFunction) {
return blockExtractors.stream()
.map(p -> Pair.of(p.getKey(), getTypedSupplier(p.getValue(), extractorClass)))
.filter(e -> e.getValue() != null)
.map(e -> Pair.of(e.getKey(), extractoeFunction.apply(e.getValue(), t)))
.map(e -> Pair.of(e.getKey(), extractorFunction.apply(e.getValue(), t)))
.filter(e -> showEmptyBlocks || !isEffectivelyBlank(e.getValue()))
.map(e -> getJoiner(headerSeparator).apply(e))
.collect(Collectors.joining(blockSeparator));
Expand All @@ -90,7 +92,10 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BlockFormattingValuesExtractor that = (BlockFormattingValuesExtractor) o;
return showEmptyBlocks == that.showEmptyBlocks && Objects.equals(blockExtractors, that.blockExtractors) && Objects.equals(headerSeparator, that.headerSeparator) && Objects.equals(blockSeparator, that.blockSeparator);
return showEmptyBlocks == that.showEmptyBlocks
&& Objects.equals(blockExtractors, that.blockExtractors)
&& Objects.equals(headerSeparator, that.headerSeparator)
&& Objects.equals(blockSeparator, that.blockSeparator);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import java.util.Set;

/**
* This implementation of {@link ValuesExtractor} stores and returns a constant value independent from initialization
* This implementation of {@link ValuesExtractor} stores and returns a constant value independent of initialization
*/
public class ConstantValuesExtractor implements TestRunValuesExtractor, TestValuesExtractor {
@JsonProperty(required = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

/**
* This implementation of {@link ValuesExtractor} can be initiated by {@link Test}
* Returns a test case description consisted of Actions (defined by {@link actionRegex}) and Results (defined by {@link resultRegex}).
* Each action leading to result is followed by additional row like 'Check result (1)' (format specified by {@link checkResultFormat})
* Returns a test case description consisted of Actions (defined by {@link #actionRegex}) and Results (defined by {@link #resultRegex}).
* Each action leading to result is followed by additional row like 'Check result (1)' (format specified by {@link #checkResultFormat})
* referencing the result row number in 'Results' block
* Each result starts with reference to action like 'After step (1) - ...'
* Each action and result start with {@link rowStartTemplate} providing row enumeration in target environment (e.g. '# " for Jira).
* Each action and result start with {@link #rowStartTemplate} providing row enumeration in target environment (e.g. '# " for Jira).
*/
public class EnumeratingTestDescriptionFormatter implements TestValuesExtractor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

/**
* This implementation of {@link TestRunValuesExtractor} and {@link TestValuesExtractor}
* creating a formatted String (see {@link String#format(String, Object...)}) based on {@link formatString}
* creating a formatted String (see {@link String#format(String, Object...)}) based on {@link #formatString}
* and a list of other {@link TestRunValuesExtractor} and {@link TestValuesExtractor} initiated with the same Test/TestRun as arguments
*/
public class FormattingValuesExtractor implements TestRunValuesExtractor, TestValuesExtractor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

/**
* This implementation of {@link TestRunValuesExtractor} for creating a value consisting of {@link Test#toRunnerString()}
* values of tests in TestRun joined by {@link valuesSeparator}
* values of tests in TestRun joined by {@link #valuesSeparator}
*/
public class TestsToStringValuesExtractor implements TestRunValuesExtractor {
@JsonProperty(required = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ private void forEachComponent(Consumer<IntegrationComponent<F>> consumer) {
.forEach(consumer);
}

public static abstract class Builder<I extends IntegrationImpl<I, F, B>, F extends IntegrationFeatures, B extends Builder<I, F, B>> {
public abstract static class Builder<I extends IntegrationImpl<I, F, B>, F extends IntegrationFeatures, B extends Builder<I, F, B>> {
protected String identifier;
protected boolean runnable;
protected List<TestExtractor<F>> testExtractors = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public abstract class FileTestExtractor<F extends IntegrationFeatures> implement

protected FileTestExtractor() {}

public FileTestExtractor(String identifier, List<String> testLocations) {
protected FileTestExtractor(String identifier, List<String> testLocations) {
this.identifier = identifier;
this.testLocations = testLocations;
}
Expand Down Expand Up @@ -68,7 +68,9 @@ public List<Test> get() {
long start = System.currentTimeMillis();
List<Path> paths = FileUtils.listFilePathsRecursively(getFilePattern(), Arguments.checkNotEmpty(testLocations, "testLocations"));
log.info("Collected {} file paths from specified locations {} by pattern '{}'", paths.size(), getFilePattern(), testLocations);
log.trace("Collected paths:\n\t{}", paths.stream().map(Path::toString).collect(Collectors.joining("\n\t")));
if (log.isTraceEnabled()) {
log.trace("Collected paths:\n\t{}", paths.stream().map(Path::toString).collect(Collectors.joining("\n\t")));
}

List<Test> tests = paths
.stream()
Expand All @@ -77,7 +79,9 @@ public List<Test> get() {
.flatMap(Collection::stream)
.collect(Collectors.toList());
log.info("Extracted {} tests from {} files in {} millis", tests.size(), paths.size(), System.currentTimeMillis() - start);
log.trace("Extracted tests: {}\n\t", tests.stream().map(Test::getIdentifier).collect(Collectors.joining("\n\t")));
if (log.isTraceEnabled()) {
log.trace("Extracted tests: {}\n\t", tests.stream().map(Test::getIdentifier).collect(Collectors.joining("\n\t")));
}
return tests;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Implementation of TestFilter based on checking {@link Test.attributes} by specified {@link AttributePredicate}
* Implementation of TestFilter based on checking {@link Test#getAttributes()} by specified {@link AttributePredicate}
*/
public class AttributesFilter<F extends IntegrationFeatures> extends DefaultTestFilter<F> {
@JsonProperty(required = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public List<Test> filter(List<Test> tests) {
/**
* Evaluates this filter on the specified test.
*
* @param test test to check
* @param test test to check
* @return true if test matches specified filter attributes
*/
protected abstract boolean matches(Test test);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
* Implementation of {@link TestSplitter} based on a single attribute value under specified key and attribute key
Expand Down Expand Up @@ -65,9 +66,10 @@ public List<TestRun> split(Collection<Test> tests) {
Iterator<Test> iterator = unsplit.iterator();
while (iterator.hasNext()) {
Test test = iterator.next();
if (predicate.test(test.getAttributes())) {
//noinspection OptionalGetWithoutIsPresent : checked by predicate
split.computeIfAbsent(test.getAttributes().getSingleAttributeValue(attributeKey, attributeValueKey).get(),
Attributes attributes = test.getAttributes();
Optional<String> singleAttributeValue = attributes.getSingleAttributeValue(attributeKey, attributeValueKey);
if (predicate.test(attributes) && singleAttributeValue.isPresent()) {
split.computeIfAbsent(singleAttributeValue.get(),
k -> new ArrayList<>()).add(test);
iterator.remove();
}
Expand Down
Loading

0 comments on commit ca6aeef

Please sign in to comment.