-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathPropertyManager.java
56 lines (49 loc) · 2.08 KB
/
PropertyManager.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.nordstrom.automation.testng;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.testng.ITestResult;
/**
* This utility class provides basic management for properties associated with specific tests.
* <ul>
* <li>{@link #extractAttributes(ITestResult)} extracts the attribute collection from the specified test result
* into a {@link Map}.</li>
* <li>{@link #injectAttributes(Map, ITestResult)} injects the entries of the specified {@link Map} into the
* attribute collection of the specified test result.</li>
* </ul>
*/
public final class PropertyManager {
private PropertyManager() {
throw new AssertionError("PropertyManager is a static utility class that cannot be instantiated.");
}
/**
* Extract the attribute collection from the specified test result into a {@link Map}.
*
* @param testResult test result object
* @return map of test result attributes
*/
public static Map<String, Object> extractAttributes(ITestResult testResult) {
Map<String, Object> result = new HashMap<>();
for (String thisName : testResult.getAttributeNames()) {
result.put(thisName, testResult.getAttribute(thisName));
}
return result;
}
/**
* Inject the entries of the specified {@link Map} into the attribute collection of the specified test result.
*
* @param attributes map of test result attributes
* @param testResult test result object
*/
public static void injectAttributes(Map<String, Object> attributes, ITestResult testResult) {
if (attributes != null) {
for (Entry<String, Object> thisEntry : attributes.entrySet()) {
if (thisEntry.getValue() instanceof TrackedObject) {
((TrackedObject<?>) thisEntry.getValue()).addRef(testResult);
} else {
testResult.setAttribute(thisEntry.getKey(), thisEntry.getValue());
}
}
}
}
}