Skip to content

Commit bbbe4b5

Browse files
authored
introduce new lambda step api (fixes allure-framework#232, via allure-framework#282)
1 parent 55f9494 commit bbbe4b5

15 files changed

Lines changed: 984 additions & 277 deletions

File tree

allure-java-commons/src/main/java/io/qameta/allure/Allure.java

Lines changed: 411 additions & 8 deletions
Large diffs are not rendered by default.

allure-java-commons/src/main/java/io/qameta/allure/util/AspectUtils.java

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22

33
import io.qameta.allure.model.Parameter;
44
import org.aspectj.lang.reflect.MethodSignature;
5-
import org.slf4j.Logger;
6-
import org.slf4j.LoggerFactory;
75

8-
import java.util.Arrays;
96
import java.util.HashMap;
107
import java.util.List;
118
import java.util.Map;
12-
import java.util.Objects;
139
import java.util.Optional;
1410
import java.util.stream.Collectors;
1511
import java.util.stream.IntStream;
@@ -21,8 +17,6 @@
2117
*/
2218
public final class AspectUtils {
2319

24-
private static final Logger LOGGER = LoggerFactory.getLogger(AspectUtils.class);
25-
2620
private AspectUtils() {
2721
throw new IllegalStateException("Do not instance");
2822
}
@@ -50,44 +44,16 @@ public static Map<String, Object> getParametersMap(final MethodSignature signatu
5044
public static List<Parameter> getParameters(final MethodSignature signature, final Object... args) {
5145
return IntStream.range(0, args.length).mapToObj(index -> {
5246
final String name = signature.getParameterNames()[index];
53-
final String value = objectToString(args[index]);
47+
final String value = ObjectUtils.toString(args[index]);
5448
return new Parameter().setName(name).setValue(value);
5549
}).collect(Collectors.toList());
5650
}
5751

58-
@SuppressWarnings({
59-
"CyclomaticComplexity",
60-
"ReturnCount",
61-
"PMD.NcssCount",
62-
"PMD.CyclomaticComplexity"
63-
})
52+
/**
53+
* @deprecated use {@link ObjectUtils#toString(Object)} instead.
54+
*/
55+
@Deprecated
6456
public static String objectToString(final Object object) {
65-
try {
66-
if (Objects.nonNull(object) && object.getClass().isArray()) {
67-
if (object instanceof Object[]) {
68-
return Arrays.toString((Object[]) object);
69-
} else if (object instanceof long[]) {
70-
return Arrays.toString((long[]) object);
71-
} else if (object instanceof short[]) {
72-
return Arrays.toString((short[]) object);
73-
} else if (object instanceof int[]) {
74-
return Arrays.toString((int[]) object);
75-
} else if (object instanceof char[]) {
76-
return Arrays.toString((char[]) object);
77-
} else if (object instanceof double[]) {
78-
return Arrays.toString((double[]) object);
79-
} else if (object instanceof float[]) {
80-
return Arrays.toString((float[]) object);
81-
} else if (object instanceof boolean[]) {
82-
return Arrays.toString((boolean[]) object);
83-
} else if (object instanceof byte[]) {
84-
return Arrays.toString((byte[]) object);
85-
}
86-
}
87-
return Objects.toString(object);
88-
} catch (Exception e) {
89-
LOGGER.error("Could not convert object to string", e);
90-
return "<NPE>";
91-
}
57+
return ObjectUtils.toString(object);
9258
}
9359
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.qameta.allure.util;
2+
3+
/**
4+
* @author charlie (Dmitry Baev).
5+
*/
6+
public final class ExceptionUtils {
7+
8+
private ExceptionUtils() {
9+
throw new IllegalStateException("Do not instance");
10+
}
11+
12+
@SuppressWarnings("unchecked")
13+
public static <T extends Throwable> void sneakyThrow(final Throwable throwable) throws T {
14+
throw (T) throwable;
15+
}
16+
}

allure-java-commons/src/main/java/io/qameta/allure/util/NamingUtils.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import java.util.stream.Stream;
1515
import java.util.stream.StreamSupport;
1616

17-
import static io.qameta.allure.util.AspectUtils.objectToString;
1817
import static org.joor.Reflect.on;
1918

2019
/**
@@ -77,6 +76,6 @@ private static String extractProperties(final Object object, final String[] part
7776
final Object child = on(object).get(parts[index]);
7877
return extractProperties(child, parts, index + 1);
7978
}
80-
return objectToString(object);
79+
return ObjectUtils.toString(object);
8180
}
8281
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package io.qameta.allure.util;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
6+
import java.util.Arrays;
7+
import java.util.Objects;
8+
9+
/**
10+
* @author charlie (Dmitry Baev).
11+
*/
12+
public final class ObjectUtils {
13+
14+
private static final Logger LOGGER = LoggerFactory.getLogger(ObjectUtils.class);
15+
16+
/**
17+
* Do not instance.
18+
*/
19+
private ObjectUtils() {
20+
throw new IllegalStateException("do not instance");
21+
}
22+
23+
/**
24+
* Returns string representation of given object. Pretty prints arrays.
25+
*
26+
* @param object the given object.
27+
* @return the string representation of given object.
28+
*/
29+
@SuppressWarnings({
30+
"CyclomaticComplexity",
31+
"ReturnCount",
32+
"PMD.NcssCount",
33+
"PMD.CyclomaticComplexity"
34+
})
35+
public static String toString(final Object object) {
36+
try {
37+
if (Objects.nonNull(object) && object.getClass().isArray()) {
38+
if (object instanceof Object[]) {
39+
return Arrays.toString((Object[]) object);
40+
} else if (object instanceof long[]) {
41+
return Arrays.toString((long[]) object);
42+
} else if (object instanceof short[]) {
43+
return Arrays.toString((short[]) object);
44+
} else if (object instanceof int[]) {
45+
return Arrays.toString((int[]) object);
46+
} else if (object instanceof char[]) {
47+
return Arrays.toString((char[]) object);
48+
} else if (object instanceof double[]) {
49+
return Arrays.toString((double[]) object);
50+
} else if (object instanceof float[]) {
51+
return Arrays.toString((float[]) object);
52+
} else if (object instanceof boolean[]) {
53+
return Arrays.toString((boolean[]) object);
54+
} else if (object instanceof byte[]) {
55+
return Arrays.toString((byte[]) object);
56+
}
57+
}
58+
return Objects.toString(object);
59+
} catch (Exception e) {
60+
LOGGER.error("Could not convert object to string", e);
61+
return "<NPE>";
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)