diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fedb5e..b7d56ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog ## [Unreleased] +### Changed +- Client version updated on [5.2.1](https://github.com/reportportal/client-java/releases/tag/5.2.1), by @HardNorth +- Spock dependency marked as `implementation` to force users specify their own versions, by @HardNorth +### Removed +- Unused code, by @HardNorth ## [5.1.4] ### Changed diff --git a/build.gradle b/build.gradle index 96ee2e8..c8dda24 100644 --- a/build.gradle +++ b/build.gradle @@ -39,14 +39,14 @@ repositories { } dependencies { - api "com.epam.reportportal:client-java:5.1.24" + api "com.epam.reportportal:client-java:5.2.1" api "com.epam.reportportal:commons-model:5.0.0" - api "org.spockframework:spock-core:${spock_version}" api 'com.google.code.findbugs:jsr305:3.0.2' + + implementation "org.spockframework:spock-core:${spock_version}" implementation 'org.slf4j:slf4j-api:2.0.7' testImplementation 'org.codehaus.groovy:groovy:2.5.14' - testImplementation 'com.epam.reportportal:agent-java-test-utils:0.0.2' testImplementation 'org.aspectj:aspectjweaver:1.9.19' @@ -54,14 +54,15 @@ dependencies { testImplementation "org.mockito:mockito-core:${mockito_version}" testImplementation "org.mockito:mockito-inline:${mockito_version}" testImplementation "org.mockito:mockito-junit-jupiter:${mockito_version}" - testImplementation 'ch.qos.logback:logback-classic:1.3.8' - testImplementation 'com.epam.reportportal:logger-java-logback:5.1.6' + testImplementation 'ch.qos.logback:logback-classic:1.3.12' + testImplementation 'com.epam.reportportal:logger-java-logback:5.2.0' testImplementation ("org.junit.platform:junit-platform-runner:${junit5_launcher_version}") { exclude module: 'junit' } testImplementation "org.junit.jupiter:junit-jupiter-api:${junit5_version}" testImplementation "org.junit.jupiter:junit-jupiter-params:${junit5_version}" testImplementation "org.junit.jupiter:junit-jupiter-engine:${junit5_version}" + testImplementation 'com.squareup.okhttp3:okhttp:4.12.0' } test { diff --git a/src/main/java/com/epam/reportportal/spock/LaunchContextImpl.java b/src/main/java/com/epam/reportportal/spock/LaunchContextImpl.java index e7a6836..f967aeb 100644 --- a/src/main/java/com/epam/reportportal/spock/LaunchContextImpl.java +++ b/src/main/java/com/epam/reportportal/spock/LaunchContextImpl.java @@ -15,7 +15,6 @@ */ package com.epam.reportportal.spock; -import com.google.common.collect.Lists; import io.reactivex.Maybe; import org.spockframework.runtime.model.FeatureInfo; import org.spockframework.runtime.model.IterationInfo; @@ -23,6 +22,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Objects; @@ -93,24 +93,24 @@ public NodeFootprint findIterationFootprint(IterationInfo iterati } @Override - public Iterable findIterationFootprints(final FeatureInfo featureInfo) { + Iterable findIterationFootprints(final FeatureInfo featureInfo) { return ofNullable(findSpecFootprint(featureInfo.getSpec())).map(s -> s.getFeature(featureInfo)) .map(Feature::getAllTrackedIteration) .orElse(null); } @Override - public Specification findSpecFootprint(final SpecInfo specInfo) { + Specification findSpecFootprint(final SpecInfo specInfo) { return findValueInRegistry(specFootprintsRegistry, specInfo); } @Override - public Iterable findAllUnpublishedSpecFootprints() { + Iterable findAllUnpublishedSpecFootprints() { return specFootprintsRegistry.values().stream().filter(IS_NOT_PUBLISHED).collect(Collectors.toList()); } @Override - public RuntimePointer getRuntimePointerForSpec(SpecInfo specInfo) { + RuntimePointer getRuntimePointerForSpec(SpecInfo specInfo) { return findValueInRegistry(runtimePointersRegistry, specInfo); } @@ -131,7 +131,7 @@ private static class Specification extends NodeFootprint { private List features; - Specification(SpecInfo nodeInfo, Maybe id) { + Specification(@Nonnull SpecInfo nodeInfo, Maybe id) { super(nodeInfo, id); } @@ -154,7 +154,7 @@ private Feature getFeature(final FeatureInfo featureInfo) { private List getAllTrackedFeatures() { if (features == null) { - features = Lists.newArrayList(); + features = new ArrayList<>(); } return features; } @@ -174,7 +174,7 @@ boolean hasDescendants() { private List getAllTrackedIteration() { if (iterations == null) { - iterations = Lists.newArrayList(); + iterations = new ArrayList<>(); } return iterations; } diff --git a/src/main/java/com/epam/reportportal/spock/NodeFootprint.java b/src/main/java/com/epam/reportportal/spock/NodeFootprint.java index 014c30a..4e24d7e 100644 --- a/src/main/java/com/epam/reportportal/spock/NodeFootprint.java +++ b/src/main/java/com/epam/reportportal/spock/NodeFootprint.java @@ -19,38 +19,25 @@ import org.spockframework.runtime.model.MethodInfo; import org.spockframework.runtime.model.NodeInfo; +import javax.annotation.Nonnull; +import java.lang.reflect.AnnotatedElement; +import java.util.ArrayList; import java.util.List; import java.util.NoSuchElementException; import java.util.function.Predicate; -import static com.google.common.collect.Lists.newArrayList; -import static com.google.common.collect.Lists.newArrayListWithCapacity; - /** * Abstract entity for the representation of the metadata for the reportable * Spock test item (specification, iteration, etc.) * * @author Dzmitry Mikhievich */ -public abstract class NodeFootprint extends ReportableItemFootprint { - - /* - * Approximate fixtures count, which should match most cases. This is - * a kind of "happy medium" between memory consumption and potential - * performance drawback on arrays coping - */ - private static final int APPROXIMATE_CAPACITY = 4; - +public abstract class NodeFootprint> extends ReportableItemFootprint { private final List> fixtures; - NodeFootprint(T nodeInfo, Maybe id) { + NodeFootprint(@Nonnull T nodeInfo, Maybe id) { super(nodeInfo, id); - fixtures = newArrayListWithCapacity(APPROXIMATE_CAPACITY); - } - - ReportableItemFootprint findFixtureFootprint(final MethodInfo fixture) { - Predicate> criteria = createFixtureMatchPredicate(fixture); - return getFixtures().stream().filter(criteria).findAny().orElseThrow(NoSuchElementException::new); + fixtures = new ArrayList<>(); } /** @@ -70,7 +57,7 @@ void addFixtureFootprint(FixtureFootprint footprint) { } List> getFixtures() { - return newArrayList(fixtures); + return new ArrayList<>(fixtures); } private static Predicate> createFixtureMatchPredicate(final MethodInfo fixture) { diff --git a/src/main/java/com/epam/reportportal/spock/NodeInfoUtils.java b/src/main/java/com/epam/reportportal/spock/NodeInfoUtils.java index b5f0d6d..7efe68c 100644 --- a/src/main/java/com/epam/reportportal/spock/NodeInfoUtils.java +++ b/src/main/java/com/epam/reportportal/spock/NodeInfoUtils.java @@ -39,7 +39,7 @@ */ final class NodeInfoUtils { static final String INHERITED_FIXTURE_NAME_TEMPLATE = "%s:%s"; - private static final String LINE_SEPARATOR = System.getProperty("line.separator"); + private static final String LINE_SEPARATOR = System.lineSeparator(); private static final String BLOCK_SPLITTER = ": "; private static final String CONJUNCTION_KEYWORD = "And"; diff --git a/src/main/java/com/epam/reportportal/spock/ReportPortalSpockExtension.java b/src/main/java/com/epam/reportportal/spock/ReportPortalSpockExtension.java index de342bd..ad01c84 100644 --- a/src/main/java/com/epam/reportportal/spock/ReportPortalSpockExtension.java +++ b/src/main/java/com/epam/reportportal/spock/ReportPortalSpockExtension.java @@ -35,6 +35,7 @@ public ReportPortalSpockExtension(ReportPortalSpockListener listener) { reportingRunListener = listener; } + @SuppressWarnings("unused") public ReportPortalSpockExtension() { this(new ReportPortalSpockListener()); } @@ -42,6 +43,7 @@ public ReportPortalSpockExtension() { @Override public void start() { LOGGER.info("\"LAUNCHING\" the test run"); + //noinspection ReactiveStreamsUnusedPublisher reportingRunListener.startLaunch(); } diff --git a/src/main/java/com/epam/reportportal/spock/ReportPortalSpockListener.java b/src/main/java/com/epam/reportportal/spock/ReportPortalSpockListener.java index 1404a55..5e707e9 100644 --- a/src/main/java/com/epam/reportportal/spock/ReportPortalSpockListener.java +++ b/src/main/java/com/epam/reportportal/spock/ReportPortalSpockListener.java @@ -30,8 +30,6 @@ import com.epam.ta.reportportal.ws.model.StartTestItemRQ; import com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ; import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ; -import com.google.common.base.Throwables; -import com.google.common.collect.ImmutableMap; import io.reactivex.Maybe; import org.apache.commons.lang3.tuple.Pair; import org.codehaus.groovy.runtime.StackTraceUtils; @@ -54,8 +52,8 @@ import static com.epam.reportportal.listeners.ItemStatus.*; import static com.epam.reportportal.spock.NodeInfoUtils.*; import static com.epam.reportportal.spock.ReportableItemFootprint.IS_NOT_PUBLISHED; -import static com.google.common.base.Strings.isNullOrEmpty; import static java.util.Optional.ofNullable; +import static org.apache.commons.lang3.StringUtils.isNotBlank; import static org.spockframework.runtime.model.MethodKind.*; /** @@ -70,24 +68,22 @@ public class ReportPortalSpockListener extends AbstractRunListener { private static final Method DISPLAY_NAME_METHOD = Arrays.stream(ITERATION_METHODS) .filter(m -> "getDisplayName".equals(m.getName())) .findAny() - .orElseGet( - () -> Arrays.stream(ITERATION_METHODS) - .filter(m -> "getName".equals(m.getName())) - .findAny() - .orElseThrow(() -> new IllegalStateException("Unknown Spock version.")) - ); + .orElseGet(() -> Arrays.stream(ITERATION_METHODS) + .filter(m -> "getName".equals(m.getName())) + .findAny() + .orElseThrow(() -> new IllegalStateException("Unknown Spock version."))); private final MemoizingSupplier launch; // stores the bindings of Spock method kinds to the RP-specific notation - private static final Map ITEM_TYPES_REGISTRY = ImmutableMap.builder() - .put(SPEC_EXECUTION, "TEST") - .put(SETUP_SPEC, "BEFORE_CLASS") - .put(SETUP, "BEFORE_METHOD") - .put(FEATURE, "STEP") - .put(CLEANUP, "AFTER_METHOD") - .put(CLEANUP_SPEC, "AFTER_CLASS") - .build(); + private static final Map ITEM_TYPES_REGISTRY = Collections.unmodifiableMap(new HashMap() {{ + put(SPEC_EXECUTION, "TEST"); + put(SETUP_SPEC, "BEFORE_CLASS"); + put(SETUP, "BEFORE_METHOD"); + put(FEATURE, "STEP"); + put(CLEANUP, "AFTER_METHOD"); + put(CLEANUP_SPEC, "AFTER_CLASS"); + }}); private ListenerParameters launchParameters; private final AbstractLaunchContext launchContext; @@ -96,7 +92,7 @@ public class ReportPortalSpockListener extends AbstractRunListener { protected StartLaunchRQ buildStartLaunchRq(ListenerParameters parameters) { StartLaunchRQ startLaunchRQ = new StartLaunchRQ(); startLaunchRQ.setName(parameters.getLaunchName()); - if (!isNullOrEmpty(parameters.getDescription())) { + if (isNotBlank(parameters.getDescription())) { startLaunchRQ.setDescription(parameters.getDescription()); } startLaunchRQ.setStartTime(Calendar.getInstance().getTime()); @@ -131,6 +127,10 @@ public ReportPortalSpockListener(@Nonnull Supplier launch) { this(launch, new LaunchContextImpl()); } + void handleRpException(ReportPortalException rpException, String message) { + LOGGER.error(message, rpException); + } + public Maybe startLaunch() { if (launchContext.tryStartLaunch()) { try { @@ -394,7 +394,7 @@ protected void reportFeatureStart(@Nonnull Maybe parentId, @Nonnull Feat } public void reportFixtureError(@Nonnull SpecInfo spec, @Nullable FeatureInfo feature, @Nullable IterationInfo iteration, - @Nonnull ErrorInfo error) { + @Nonnull ErrorInfo error) { MethodInfo method = error.getMethod(); NodeFootprint ownerFootprint = findFixtureOwner(spec, feature, iteration, error.getMethod()); MethodKind kind = method.getKind(); @@ -483,29 +483,9 @@ public void finishLaunch() { } } - void handleRpException(ReportPortalException rpException, String message) { - handleException(rpException, message); - } - - /** - * Logs error in case of {@link ReportPortalException} or propagates exception exactly as-is, if - * and only if it is an instance of {@link RuntimeException} or {@link Error}. - */ - private void handleException(Exception exception, String message) { - if (exception instanceof ReportPortalException) { - if (LOGGER != null) { - LOGGER.error(message, exception); - } else { - System.out.println(exception.getMessage()); - } - } else { - Throwables.throwIfUnchecked(exception); - } - } - @SuppressWarnings("rawtypes") protected NodeFootprint findFixtureOwner(SpecInfo spec, FeatureInfo feature, IterationInfo iteration, - MethodInfo fixture) { + MethodInfo fixture) { MethodKind kind = fixture.getKind(); if (kind.isSpecScopedFixtureMethod()) { return launchContext.findSpecFootprint(spec); diff --git a/src/main/java/com/epam/reportportal/spock/ReportableItemFootprint.java b/src/main/java/com/epam/reportportal/spock/ReportableItemFootprint.java index 218acd2..dbc49a1 100644 --- a/src/main/java/com/epam/reportportal/spock/ReportableItemFootprint.java +++ b/src/main/java/com/epam/reportportal/spock/ReportableItemFootprint.java @@ -19,16 +19,16 @@ import io.reactivex.Maybe; import org.spockframework.runtime.model.NodeInfo; +import javax.annotation.Nonnull; import java.util.Optional; import java.util.function.Predicate; -import static com.google.common.base.Preconditions.checkArgument; - /** * Base entity which stores the reporting metadata for the Spock test elements * * @author Dzmitry Mikhievich */ +@SuppressWarnings("rawtypes") public abstract class ReportableItemFootprint { static final Predicate IS_NOT_PUBLISHED = input -> input != null && !input.isPublished(); @@ -39,8 +39,7 @@ public abstract class ReportableItemFootprint { private ItemStatus status; private boolean published = false; - ReportableItemFootprint(T item, Maybe id) { - checkArgument(item != null, "Node info shouldn't be null"); + ReportableItemFootprint(@Nonnull T item, Maybe id) { this.id = id; this.item = item; } @@ -69,9 +68,5 @@ boolean isPublished() { return published; } - String getItemName() { - return getItem().getName(); - } - abstract boolean hasDescendants(); } diff --git a/src/main/java/com/epam/reportportal/spock/utils/SystemAttributesFetcher.java b/src/main/java/com/epam/reportportal/spock/utils/SystemAttributesFetcher.java index b168251..7877ea1 100644 --- a/src/main/java/com/epam/reportportal/spock/utils/SystemAttributesFetcher.java +++ b/src/main/java/com/epam/reportportal/spock/utils/SystemAttributesFetcher.java @@ -27,7 +27,7 @@ public class SystemAttributesFetcher { private static final String PROPS_FILE = "agent.properties"; private SystemAttributesFetcher() { - // static only + throw new RuntimeException("No instances should exist for the class!"); } private static ItemAttributesRQ skippedIssue(Boolean skippedAnIssue) { diff --git a/src/test/java/com/epam/reportportal/spock/NodeInfoUtilsTest.java b/src/test/java/com/epam/reportportal/spock/NodeInfoUtilsTest.java index 18cf301..ebedba1 100644 --- a/src/test/java/com/epam/reportportal/spock/NodeInfoUtilsTest.java +++ b/src/test/java/com/epam/reportportal/spock/NodeInfoUtilsTest.java @@ -15,7 +15,6 @@ */ package com.epam.reportportal.spock; -import com.google.common.collect.Lists; import org.apache.commons.lang3.RandomStringUtils; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -114,6 +113,7 @@ private static Iterable parametersForFixtureDescription() { when(inheritedFixtureInfo.getName()).thenReturn(inheritedFixtureName); SpecInfo parent = mock(SpecInfo.class); when(inheritedFixtureInfo.getParent()).thenReturn(parent); + //noinspection rawtypes when(parent.getReflection()).thenReturn(((Class) FixtureSource.class)); String expectedInheritedName = format(INHERITED_FIXTURE_NAME_TEMPLATE, FixtureSource.class.getSimpleName(), inheritedFixtureName); @@ -137,6 +137,7 @@ public void getFixtureDisplayName_fixtureIsNull() { public void getSpecIdentifier_specInfoIsNotNull() { Class bearingClass = getClass(); SpecInfo specInfoMock = mock(SpecInfo.class); + //noinspection rawtypes when((Class) specInfoMock.getReflection()).thenReturn(bearingClass); String identifier = NodeInfoUtils.getSpecIdentifier(specInfoMock); @@ -154,7 +155,7 @@ private static final class FixtureSource { } private static Collection generateBlockTexts(int count) { - Collection texts = Lists.newArrayListWithCapacity(count); + Collection texts = new ArrayList<>(); for (int i = 0; i < count; i++) { texts.add(RandomStringUtils.randomAlphabetic(40)); }