() {
39 | @Override
40 | public T createInstance(Type type) {
41 | return instance;
42 | }
43 | };
44 | }
45 |
46 | @SuppressWarnings("unchecked")
47 | public void apply() {
48 | final Gson gson = new GsonBuilder()
49 | .registerTypeAdapter(instance.getClass(), creator)
50 | .create();
51 | try {
52 | String json = f != null ? Files.readFile(f) : this.json;
53 | instance = (T) gson.fromJson(json, instance.getClass());
54 | } catch (IOException e) {
55 | e.printStackTrace();
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/com/aventstack/extentreports/gherkin/GherkinDialect.java:
--------------------------------------------------------------------------------
1 | package com.aventstack.extentreports.gherkin;
2 |
3 | import java.util.List;
4 | import java.util.Map;
5 |
6 | import lombok.Getter;
7 | import lombok.ToString;
8 |
9 | /**
10 | *
11 | * Modified version of GherkinKeyword.java from cucumber/gherkin. Source url:
12 | * https://raw.githubusercontent.com/cucumber/cucumber/master/gherkin/java/src/main/java/gherkin/GherkinDialect.java
13 | *
14 | *
15 | * Gherkin source is licensed under the MIT License
16 | *
17 | */
18 | @Getter
19 | @ToString
20 | public class GherkinDialect {
21 | private final Map> keywords;
22 | private String language;
23 |
24 | public GherkinDialect(String language, Map> keywords) {
25 | keywords.remove("name");
26 | keywords.remove("native");
27 | this.language = language;
28 | this.keywords = keywords;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/com/aventstack/extentreports/gherkin/model/And.java:
--------------------------------------------------------------------------------
1 | package com.aventstack.extentreports.gherkin.model;
2 |
3 | import java.io.Serializable;
4 |
5 | public class And implements IGherkinFormatterModel, Serializable {
6 | private static final long serialVersionUID = 8543289653944756660L;
7 | private static final String VALUE = "And";
8 |
9 | public static String getGherkinName() {
10 | return VALUE;
11 | }
12 |
13 | @Override
14 | public String toString() {
15 | return getGherkinName();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/aventstack/extentreports/gherkin/model/Asterisk.java:
--------------------------------------------------------------------------------
1 | package com.aventstack.extentreports.gherkin.model;
2 |
3 | import java.io.Serializable;
4 |
5 | public class Asterisk implements IGherkinFormatterModel, Serializable {
6 | private static final long serialVersionUID = 7251419811428200133L;
7 | private static final String VALUE = "*";
8 |
9 | public static String getGherkinName() {
10 | return VALUE;
11 | }
12 |
13 | @Override
14 | public String toString() {
15 | return getGherkinName();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/aventstack/extentreports/gherkin/model/Background.java:
--------------------------------------------------------------------------------
1 | package com.aventstack.extentreports.gherkin.model;
2 |
3 | import java.io.Serializable;
4 |
5 | public class Background implements IGherkinFormatterModel, Serializable {
6 | private static final long serialVersionUID = -955371501488725151L;
7 | private static final String VALUE = "Background";
8 |
9 | public static String getGherkinName() {
10 | return VALUE;
11 | }
12 |
13 | @Override
14 | public String toString() {
15 | return getGherkinName();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/aventstack/extentreports/gherkin/model/But.java:
--------------------------------------------------------------------------------
1 | package com.aventstack.extentreports.gherkin.model;
2 |
3 | import java.io.Serializable;
4 |
5 | public class But implements IGherkinFormatterModel, Serializable {
6 | private static final long serialVersionUID = 3420514631996827220L;
7 | private static final String VALUE = "But";
8 |
9 | public static String getGherkinName() {
10 | return VALUE;
11 | }
12 |
13 | @Override
14 | public String toString() {
15 | return getGherkinName();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/aventstack/extentreports/gherkin/model/Feature.java:
--------------------------------------------------------------------------------
1 | package com.aventstack.extentreports.gherkin.model;
2 |
3 | import java.io.Serializable;
4 |
5 | public class Feature implements IGherkinFormatterModel, Serializable {
6 | private static final long serialVersionUID = -4719215211721789414L;
7 | private static final String VALUE = "Feature";
8 |
9 | public static String getGherkinName() {
10 | return VALUE;
11 | }
12 |
13 | @Override
14 | public String toString() {
15 | return getGherkinName();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/aventstack/extentreports/gherkin/model/GherkinEntity.java:
--------------------------------------------------------------------------------
1 | package com.aventstack.extentreports.gherkin.model;
2 |
3 | import java.io.Serializable;
4 |
5 | public abstract class GherkinEntity implements Serializable {
6 | private static final long serialVersionUID = 725203884274843593L;
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/aventstack/extentreports/gherkin/model/Given.java:
--------------------------------------------------------------------------------
1 | package com.aventstack.extentreports.gherkin.model;
2 |
3 | import java.io.Serializable;
4 |
5 | public class Given implements IGherkinFormatterModel, Serializable {
6 | private static final long serialVersionUID = 939197985263690070L;
7 | private static final String VALUE = "Given";
8 |
9 | public static String getGherkinName() {
10 | return VALUE;
11 | }
12 |
13 | @Override
14 | public String toString() {
15 | return getGherkinName();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/aventstack/extentreports/gherkin/model/IGherkinFormatterModel.java:
--------------------------------------------------------------------------------
1 | package com.aventstack.extentreports.gherkin.model;
2 |
3 | import java.io.Serializable;
4 |
5 | public interface IGherkinFormatterModel extends Serializable {
6 | }
7 |
--------------------------------------------------------------------------------
/src/main/java/com/aventstack/extentreports/gherkin/model/Scenario.java:
--------------------------------------------------------------------------------
1 | package com.aventstack.extentreports.gherkin.model;
2 |
3 | import java.io.Serializable;
4 |
5 | public class Scenario implements IGherkinFormatterModel, Serializable {
6 | private static final long serialVersionUID = 7401124129196617280L;
7 | private static final String VALUE = "Scenario";
8 |
9 | public static String getGherkinName() {
10 | return VALUE;
11 | }
12 |
13 | @Override
14 | public String toString() {
15 | return getGherkinName();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/aventstack/extentreports/gherkin/model/ScenarioOutline.java:
--------------------------------------------------------------------------------
1 | package com.aventstack.extentreports.gherkin.model;
2 |
3 | import java.io.Serializable;
4 |
5 | public class ScenarioOutline implements IGherkinFormatterModel, Serializable {
6 | private static final long serialVersionUID = -2058398543903906031L;
7 | private static final String VALUE = "Scenario Outline";
8 |
9 | public static String getGherkinName() {
10 | return VALUE;
11 | }
12 |
13 | @Override
14 | public String toString() {
15 | return getGherkinName();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/aventstack/extentreports/gherkin/model/Then.java:
--------------------------------------------------------------------------------
1 | package com.aventstack.extentreports.gherkin.model;
2 |
3 | import java.io.Serializable;
4 |
5 | public class Then implements IGherkinFormatterModel, Serializable {
6 | private static final long serialVersionUID = 2493591502473169772L;
7 | private static final String VALUE = "Then";
8 |
9 | public static String getGherkinName() {
10 | return VALUE;
11 | }
12 |
13 | @Override
14 | public String toString() {
15 | return getGherkinName();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/aventstack/extentreports/gherkin/model/When.java:
--------------------------------------------------------------------------------
1 | package com.aventstack.extentreports.gherkin.model;
2 |
3 | import java.io.Serializable;
4 |
5 | public class When implements IGherkinFormatterModel, Serializable {
6 | private static final long serialVersionUID = 8337259741948416898L;
7 | private static final String VALUE = "When";
8 |
9 | public static String getGherkinName() {
10 | return VALUE;
11 | }
12 |
13 | @Override
14 | public String toString() {
15 | return getGherkinName();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/aventstack/extentreports/io/BufferedWriterWriter.java:
--------------------------------------------------------------------------------
1 | package com.aventstack.extentreports.io;
2 |
3 | import java.io.BufferedWriter;
4 | import java.io.File;
5 | import java.io.FileWriter;
6 | import java.util.logging.Level;
7 | import java.util.logging.Logger;
8 |
9 | public class BufferedWriterWriter {
10 |
11 | private static class WriterInstance {
12 | static final BufferedWriterWriter INSTANCE = new BufferedWriterWriter();
13 |
14 | private WriterInstance() {
15 | }
16 | }
17 |
18 | static final Logger logger = Logger.getLogger(BufferedWriterWriter.class.getName());
19 |
20 | private BufferedWriterWriter() {
21 | }
22 |
23 | public synchronized void write(final File f, String text) {
24 | try (BufferedWriter writer = new BufferedWriter(new FileWriter(f))) {
25 | writer.write(text);
26 | } catch (Exception e) {
27 | logger.log(Level.SEVERE, f.getPath(), e);
28 | }
29 | }
30 |
31 | public static BufferedWriterWriter getInstance() {
32 | return WriterInstance.INSTANCE;
33 | }
34 |
35 | }
--------------------------------------------------------------------------------
/src/main/java/com/aventstack/extentreports/markuputils/CodeBlock.java:
--------------------------------------------------------------------------------
1 | package com.aventstack.extentreports.markuputils;
2 |
3 | import java.io.IOException;
4 | import java.util.HashMap;
5 | import java.util.Map;
6 | import java.util.concurrent.atomic.AtomicInteger;
7 |
8 | import com.google.gson.Gson;
9 |
10 | import freemarker.template.Template;
11 | import freemarker.template.TemplateException;
12 | import lombok.AllArgsConstructor;
13 | import lombok.Builder;
14 | import lombok.Getter;
15 | import lombok.ToString;
16 |
17 | @Getter
18 | @Builder
19 | @AllArgsConstructor
20 | @ToString
21 | class CodeBlock extends MarkupTemplate implements Markup {
22 |
23 | private static final long serialVersionUID = -5532095355983830164L;
24 | private static final AtomicInteger id = new AtomicInteger(0);
25 | private static final String CODEBLOCK_TEMPLATE = "codeblock.ftl";
26 | private static final String CODEBLOCK_JSON_TEMPLATE = "codeblock.json.ftl";
27 | private static Template codeblock;
28 | private static Template codeblockJson;
29 | private String code;
30 | private CodeLanguage lang;
31 | private Object jsonObject;
32 |
33 | static {
34 | try {
35 | codeblock = ft.createTemplate(CODEBLOCK_TEMPLATE);
36 | codeblockJson = ft.createTemplate(CODEBLOCK_JSON_TEMPLATE);
37 | } catch (Exception e) {
38 | e.printStackTrace();
39 | }
40 | }
41 |
42 | @Override
43 | public String getMarkup() {
44 | if (code == null && jsonObject == null)
45 | return "";
46 | if (jsonObject != null)
47 | code = new Gson().toJson(jsonObject);
48 | int index = 0;
49 | Template t = codeblock;
50 | if (lang == CodeLanguage.JSON) {
51 | index = id.getAndIncrement();
52 | t = codeblockJson;
53 | }
54 | Map map = new HashMap<>();
55 | map.put("code", code);
56 | map.put("index", index);
57 | try {
58 | return ft.getSource(t, map);
59 | } catch (TemplateException e) {
60 | e.printStackTrace();
61 | } catch (IOException e) {
62 | e.printStackTrace();
63 | }
64 | return null;
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/com/aventstack/extentreports/markuputils/CodeLanguage.java:
--------------------------------------------------------------------------------
1 | package com.aventstack.extentreports.markuputils;
2 |
3 | /**
4 | * List of supported languages that will be prettified on output
5 | */
6 | public enum CodeLanguage {
7 | XML, JSON
8 | }
9 |
--------------------------------------------------------------------------------
/src/main/java/com/aventstack/extentreports/markuputils/ExtentColor.java:
--------------------------------------------------------------------------------
1 | package com.aventstack.extentreports.markuputils;
2 |
3 | public enum ExtentColor {
4 | RED,
5 | PINK,
6 | PURPLE,
7 | INDIGO,
8 | BLUE,
9 | CYAN,
10 | TEAL,
11 | GREEN,
12 | LIME,
13 | YELLOW,
14 | AMBER,
15 | ORANGE,
16 | BROWN,
17 | GREY,
18 | WHITE,
19 | BLACK,
20 | TRANSPARENT
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/com/aventstack/extentreports/markuputils/HtmlList.java:
--------------------------------------------------------------------------------
1 | package com.aventstack.extentreports.markuputils;
2 |
3 | import java.util.Arrays;
4 | import java.util.Collection;
5 | import java.util.List;
6 | import java.util.Map;
7 | import java.util.Set;
8 |
9 | abstract class HtmlList {
10 | @SuppressWarnings("unchecked")
11 | protected String getList(Object object, ListType listType) {
12 | final StringBuilder sb = new StringBuilder();
13 | sb.append("<" + listType.toString().toLowerCase() + ">");
14 | if (object instanceof Map) {
15 | for (Map.Entry