Skip to content

Commit 59ac42e

Browse files
authored
Merge pull request #44 from reportportal/develop
Release
2 parents 0e2cf6d + d972a55 commit 59ac42e

File tree

11 files changed

+57
-86
lines changed

11 files changed

+57
-86
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Changelog
22

33
## [Unreleased]
4+
### Changed
5+
- Client version updated on [5.2.1](https://github.com/reportportal/client-java/releases/tag/5.2.1), by @HardNorth
6+
- Spock dependency marked as `implementation` to force users specify their own versions, by @HardNorth
7+
### Removed
8+
- Unused code, by @HardNorth
49

510
## [5.1.4]
611
### Changed

build.gradle

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,30 @@ repositories {
3939
}
4040

4141
dependencies {
42-
api "com.epam.reportportal:client-java:5.1.24"
42+
api "com.epam.reportportal:client-java:5.2.1"
4343
api "com.epam.reportportal:commons-model:5.0.0"
44-
api "org.spockframework:spock-core:${spock_version}"
4544
api 'com.google.code.findbugs:jsr305:3.0.2'
45+
46+
implementation "org.spockframework:spock-core:${spock_version}"
4647
implementation 'org.slf4j:slf4j-api:2.0.7'
4748

4849
testImplementation 'org.codehaus.groovy:groovy:2.5.14'
49-
5050
testImplementation 'com.epam.reportportal:agent-java-test-utils:0.0.2'
5151

5252
testImplementation 'org.aspectj:aspectjweaver:1.9.19'
5353
testImplementation 'org.hamcrest:hamcrest-core:2.2'
5454
testImplementation "org.mockito:mockito-core:${mockito_version}"
5555
testImplementation "org.mockito:mockito-inline:${mockito_version}"
5656
testImplementation "org.mockito:mockito-junit-jupiter:${mockito_version}"
57-
testImplementation 'ch.qos.logback:logback-classic:1.3.8'
58-
testImplementation 'com.epam.reportportal:logger-java-logback:5.1.6'
57+
testImplementation 'ch.qos.logback:logback-classic:1.3.12'
58+
testImplementation 'com.epam.reportportal:logger-java-logback:5.2.0'
5959
testImplementation ("org.junit.platform:junit-platform-runner:${junit5_launcher_version}") {
6060
exclude module: 'junit'
6161
}
6262
testImplementation "org.junit.jupiter:junit-jupiter-api:${junit5_version}"
6363
testImplementation "org.junit.jupiter:junit-jupiter-params:${junit5_version}"
6464
testImplementation "org.junit.jupiter:junit-jupiter-engine:${junit5_version}"
65+
testImplementation 'com.squareup.okhttp3:okhttp:4.12.0'
6566
}
6667

6768
test {

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=agent-java-spock
2-
version=5.1.5-SNAPSHOT
2+
version=5.2.0-SNAPSHOT
33
description=Spock integration agent for Report Portal
44
spock_version=2.3-groovy-2.5
55
junit5_version=5.9.2

src/main/java/com/epam/reportportal/spock/LaunchContextImpl.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
*/
1616
package com.epam.reportportal.spock;
1717

18-
import com.google.common.collect.Lists;
1918
import io.reactivex.Maybe;
2019
import org.spockframework.runtime.model.FeatureInfo;
2120
import org.spockframework.runtime.model.IterationInfo;
2221
import org.spockframework.runtime.model.SpecInfo;
2322

2423
import javax.annotation.Nonnull;
2524
import javax.annotation.Nullable;
25+
import java.util.ArrayList;
2626
import java.util.List;
2727
import java.util.Map;
2828
import java.util.Objects;
@@ -93,24 +93,24 @@ public NodeFootprint<IterationInfo> findIterationFootprint(IterationInfo iterati
9393
}
9494

9595
@Override
96-
public Iterable<Iteration> findIterationFootprints(final FeatureInfo featureInfo) {
96+
Iterable<Iteration> findIterationFootprints(final FeatureInfo featureInfo) {
9797
return ofNullable(findSpecFootprint(featureInfo.getSpec())).map(s -> s.getFeature(featureInfo))
9898
.map(Feature::getAllTrackedIteration)
9999
.orElse(null);
100100
}
101101

102102
@Override
103-
public Specification findSpecFootprint(final SpecInfo specInfo) {
103+
Specification findSpecFootprint(final SpecInfo specInfo) {
104104
return findValueInRegistry(specFootprintsRegistry, specInfo);
105105
}
106106

107107
@Override
108-
public Iterable<Specification> findAllUnpublishedSpecFootprints() {
108+
Iterable<Specification> findAllUnpublishedSpecFootprints() {
109109
return specFootprintsRegistry.values().stream().filter(IS_NOT_PUBLISHED).collect(Collectors.toList());
110110
}
111111

112112
@Override
113-
public RuntimePointer getRuntimePointerForSpec(SpecInfo specInfo) {
113+
RuntimePointer getRuntimePointerForSpec(SpecInfo specInfo) {
114114
return findValueInRegistry(runtimePointersRegistry, specInfo);
115115
}
116116

@@ -131,7 +131,7 @@ private static class Specification extends NodeFootprint<SpecInfo> {
131131

132132
private List<Feature> features;
133133

134-
Specification(SpecInfo nodeInfo, Maybe<String> id) {
134+
Specification(@Nonnull SpecInfo nodeInfo, Maybe<String> id) {
135135
super(nodeInfo, id);
136136
}
137137

@@ -154,7 +154,7 @@ private Feature getFeature(final FeatureInfo featureInfo) {
154154

155155
private List<Feature> getAllTrackedFeatures() {
156156
if (features == null) {
157-
features = Lists.newArrayList();
157+
features = new ArrayList<>();
158158
}
159159
return features;
160160
}
@@ -174,7 +174,7 @@ boolean hasDescendants() {
174174

175175
private List<Iteration> getAllTrackedIteration() {
176176
if (iterations == null) {
177-
iterations = Lists.newArrayList();
177+
iterations = new ArrayList<>();
178178
}
179179
return iterations;
180180
}

src/main/java/com/epam/reportportal/spock/NodeFootprint.java

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,25 @@
1919
import org.spockframework.runtime.model.MethodInfo;
2020
import org.spockframework.runtime.model.NodeInfo;
2121

22+
import javax.annotation.Nonnull;
23+
import java.lang.reflect.AnnotatedElement;
24+
import java.util.ArrayList;
2225
import java.util.List;
2326
import java.util.NoSuchElementException;
2427
import java.util.function.Predicate;
2528

26-
import static com.google.common.collect.Lists.newArrayList;
27-
import static com.google.common.collect.Lists.newArrayListWithCapacity;
28-
2929
/**
3030
* Abstract entity for the representation of the metadata for the reportable
3131
* <i>Spock</i> test item (specification, iteration, etc.)
3232
*
3333
* @author Dzmitry Mikhievich
3434
*/
35-
public abstract class NodeFootprint<T extends NodeInfo> extends ReportableItemFootprint<T> {
36-
37-
/*
38-
* Approximate fixtures count, which should match most cases. This is
39-
* a kind of "happy medium" between memory consumption and potential
40-
* performance drawback on arrays coping
41-
*/
42-
private static final int APPROXIMATE_CAPACITY = 4;
43-
35+
public abstract class NodeFootprint<T extends NodeInfo<?, ? extends AnnotatedElement>> extends ReportableItemFootprint<T> {
4436
private final List<ReportableItemFootprint<MethodInfo>> fixtures;
4537

46-
NodeFootprint(T nodeInfo, Maybe<String> id) {
38+
NodeFootprint(@Nonnull T nodeInfo, Maybe<String> id) {
4739
super(nodeInfo, id);
48-
fixtures = newArrayListWithCapacity(APPROXIMATE_CAPACITY);
49-
}
50-
51-
ReportableItemFootprint<MethodInfo> findFixtureFootprint(final MethodInfo fixture) {
52-
Predicate<ReportableItemFootprint<MethodInfo>> criteria = createFixtureMatchPredicate(fixture);
53-
return getFixtures().stream().filter(criteria).findAny().orElseThrow(NoSuchElementException::new);
40+
fixtures = new ArrayList<>();
5441
}
5542

5643
/**
@@ -70,7 +57,7 @@ void addFixtureFootprint(FixtureFootprint footprint) {
7057
}
7158

7259
List<ReportableItemFootprint<MethodInfo>> getFixtures() {
73-
return newArrayList(fixtures);
60+
return new ArrayList<>(fixtures);
7461
}
7562

7663
private static Predicate<ReportableItemFootprint<MethodInfo>> createFixtureMatchPredicate(final MethodInfo fixture) {

src/main/java/com/epam/reportportal/spock/NodeInfoUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
*/
4040
final class NodeInfoUtils {
4141
static final String INHERITED_FIXTURE_NAME_TEMPLATE = "%s:%s";
42-
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
42+
private static final String LINE_SEPARATOR = System.lineSeparator();
4343
private static final String BLOCK_SPLITTER = ": ";
4444
private static final String CONJUNCTION_KEYWORD = "And";
4545

src/main/java/com/epam/reportportal/spock/ReportPortalSpockExtension.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ public ReportPortalSpockExtension(ReportPortalSpockListener listener) {
3535
reportingRunListener = listener;
3636
}
3737

38+
@SuppressWarnings("unused")
3839
public ReportPortalSpockExtension() {
3940
this(new ReportPortalSpockListener());
4041
}
4142

4243
@Override
4344
public void start() {
4445
LOGGER.info("\"LAUNCHING\" the test run");
46+
//noinspection ReactiveStreamsUnusedPublisher
4547
reportingRunListener.startLaunch();
4648
}
4749

src/main/java/com/epam/reportportal/spock/ReportPortalSpockListener.java

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
import com.epam.ta.reportportal.ws.model.StartTestItemRQ;
3131
import com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ;
3232
import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ;
33-
import com.google.common.base.Throwables;
34-
import com.google.common.collect.ImmutableMap;
3533
import io.reactivex.Maybe;
3634
import org.apache.commons.lang3.tuple.Pair;
3735
import org.codehaus.groovy.runtime.StackTraceUtils;
@@ -54,8 +52,8 @@
5452
import static com.epam.reportportal.listeners.ItemStatus.*;
5553
import static com.epam.reportportal.spock.NodeInfoUtils.*;
5654
import static com.epam.reportportal.spock.ReportableItemFootprint.IS_NOT_PUBLISHED;
57-
import static com.google.common.base.Strings.isNullOrEmpty;
5855
import static java.util.Optional.ofNullable;
56+
import static org.apache.commons.lang3.StringUtils.isNotBlank;
5957
import static org.spockframework.runtime.model.MethodKind.*;
6058

6159
/**
@@ -70,24 +68,22 @@ public class ReportPortalSpockListener extends AbstractRunListener {
7068
private static final Method DISPLAY_NAME_METHOD = Arrays.stream(ITERATION_METHODS)
7169
.filter(m -> "getDisplayName".equals(m.getName()))
7270
.findAny()
73-
.orElseGet(
74-
() -> Arrays.stream(ITERATION_METHODS)
75-
.filter(m -> "getName".equals(m.getName()))
76-
.findAny()
77-
.orElseThrow(() -> new IllegalStateException("Unknown Spock version."))
78-
);
71+
.orElseGet(() -> Arrays.stream(ITERATION_METHODS)
72+
.filter(m -> "getName".equals(m.getName()))
73+
.findAny()
74+
.orElseThrow(() -> new IllegalStateException("Unknown Spock version.")));
7975

8076
private final MemoizingSupplier<Launch> launch;
8177

8278
// stores the bindings of Spock method kinds to the RP-specific notation
83-
private static final Map<MethodKind, String> ITEM_TYPES_REGISTRY = ImmutableMap.<MethodKind, String>builder()
84-
.put(SPEC_EXECUTION, "TEST")
85-
.put(SETUP_SPEC, "BEFORE_CLASS")
86-
.put(SETUP, "BEFORE_METHOD")
87-
.put(FEATURE, "STEP")
88-
.put(CLEANUP, "AFTER_METHOD")
89-
.put(CLEANUP_SPEC, "AFTER_CLASS")
90-
.build();
79+
private static final Map<MethodKind, String> ITEM_TYPES_REGISTRY = Collections.unmodifiableMap(new HashMap<MethodKind, String>() {{
80+
put(SPEC_EXECUTION, "TEST");
81+
put(SETUP_SPEC, "BEFORE_CLASS");
82+
put(SETUP, "BEFORE_METHOD");
83+
put(FEATURE, "STEP");
84+
put(CLEANUP, "AFTER_METHOD");
85+
put(CLEANUP_SPEC, "AFTER_CLASS");
86+
}});
9187

9288
private ListenerParameters launchParameters;
9389
private final AbstractLaunchContext launchContext;
@@ -96,7 +92,7 @@ public class ReportPortalSpockListener extends AbstractRunListener {
9692
protected StartLaunchRQ buildStartLaunchRq(ListenerParameters parameters) {
9793
StartLaunchRQ startLaunchRQ = new StartLaunchRQ();
9894
startLaunchRQ.setName(parameters.getLaunchName());
99-
if (!isNullOrEmpty(parameters.getDescription())) {
95+
if (isNotBlank(parameters.getDescription())) {
10096
startLaunchRQ.setDescription(parameters.getDescription());
10197
}
10298
startLaunchRQ.setStartTime(Calendar.getInstance().getTime());
@@ -131,6 +127,10 @@ public ReportPortalSpockListener(@Nonnull Supplier<Launch> launch) {
131127
this(launch, new LaunchContextImpl());
132128
}
133129

130+
void handleRpException(ReportPortalException rpException, String message) {
131+
LOGGER.error(message, rpException);
132+
}
133+
134134
public Maybe<String> startLaunch() {
135135
if (launchContext.tryStartLaunch()) {
136136
try {
@@ -394,7 +394,7 @@ protected void reportFeatureStart(@Nonnull Maybe<String> parentId, @Nonnull Feat
394394
}
395395

396396
public void reportFixtureError(@Nonnull SpecInfo spec, @Nullable FeatureInfo feature, @Nullable IterationInfo iteration,
397-
@Nonnull ErrorInfo error) {
397+
@Nonnull ErrorInfo error) {
398398
MethodInfo method = error.getMethod();
399399
NodeFootprint<?> ownerFootprint = findFixtureOwner(spec, feature, iteration, error.getMethod());
400400
MethodKind kind = method.getKind();
@@ -483,29 +483,9 @@ public void finishLaunch() {
483483
}
484484
}
485485

486-
void handleRpException(ReportPortalException rpException, String message) {
487-
handleException(rpException, message);
488-
}
489-
490-
/**
491-
* Logs error in case of {@link ReportPortalException} or propagates exception exactly as-is, if
492-
* and only if it is an instance of {@link RuntimeException} or {@link Error}.
493-
*/
494-
private void handleException(Exception exception, String message) {
495-
if (exception instanceof ReportPortalException) {
496-
if (LOGGER != null) {
497-
LOGGER.error(message, exception);
498-
} else {
499-
System.out.println(exception.getMessage());
500-
}
501-
} else {
502-
Throwables.throwIfUnchecked(exception);
503-
}
504-
}
505-
506486
@SuppressWarnings("rawtypes")
507487
protected NodeFootprint<? extends NodeInfo> findFixtureOwner(SpecInfo spec, FeatureInfo feature, IterationInfo iteration,
508-
MethodInfo fixture) {
488+
MethodInfo fixture) {
509489
MethodKind kind = fixture.getKind();
510490
if (kind.isSpecScopedFixtureMethod()) {
511491
return launchContext.findSpecFootprint(spec);

src/main/java/com/epam/reportportal/spock/ReportableItemFootprint.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@
1919
import io.reactivex.Maybe;
2020
import org.spockframework.runtime.model.NodeInfo;
2121

22+
import javax.annotation.Nonnull;
2223
import java.util.Optional;
2324
import java.util.function.Predicate;
2425

25-
import static com.google.common.base.Preconditions.checkArgument;
26-
2726
/**
2827
* Base entity which stores the reporting metadata for the <i>Spock</i> test elements
2928
*
3029
* @author Dzmitry Mikhievich
3130
*/
31+
@SuppressWarnings("rawtypes")
3232
public abstract class ReportableItemFootprint<T extends NodeInfo> {
3333

3434
static final Predicate<ReportableItemFootprint> IS_NOT_PUBLISHED = input -> input != null && !input.isPublished();
@@ -39,8 +39,7 @@ public abstract class ReportableItemFootprint<T extends NodeInfo> {
3939
private ItemStatus status;
4040
private boolean published = false;
4141

42-
ReportableItemFootprint(T item, Maybe<String> id) {
43-
checkArgument(item != null, "Node info shouldn't be null");
42+
ReportableItemFootprint(@Nonnull T item, Maybe<String> id) {
4443
this.id = id;
4544
this.item = item;
4645
}
@@ -69,9 +68,5 @@ boolean isPublished() {
6968
return published;
7069
}
7170

72-
String getItemName() {
73-
return getItem().getName();
74-
}
75-
7671
abstract boolean hasDescendants();
7772
}

src/main/java/com/epam/reportportal/spock/utils/SystemAttributesFetcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class SystemAttributesFetcher {
2727
private static final String PROPS_FILE = "agent.properties";
2828

2929
private SystemAttributesFetcher() {
30-
// static only
30+
throw new RuntimeException("No instances should exist for the class!");
3131
}
3232

3333
private static ItemAttributesRQ skippedIssue(Boolean skippedAnIssue) {

0 commit comments

Comments
 (0)