-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bumped all - before Selenium 4 (#73)
- Loading branch information
Showing
43 changed files
with
935 additions
and
3,010 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 50 additions & 56 deletions
106
...e-module/src/main/java/com/capgemini/mrchecker/test/core/utils/datadriven/JsonDriven.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,62 @@ | ||
package com.capgemini.mrchecker.test.core.utils.datadriven; | ||
|
||
import com.capgemini.mrchecker.test.core.logger.BFLogger; | ||
import com.google.gson.GsonBuilder; | ||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonParser; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.io.Reader; | ||
|
||
import com.capgemini.mrchecker.test.core.logger.BFLogger; | ||
|
||
import io.cucumber.messages.internal.com.google.gson.GsonBuilder; | ||
import io.cucumber.messages.internal.com.google.gson.JsonArray; | ||
import io.cucumber.messages.internal.com.google.gson.JsonParser; | ||
|
||
/** | ||
* @author is an utility to handle JSON deserialization boilerplate for JParamRunner data driven cases. It has no state, | ||
* therefore is not instantiable nor extendible. | ||
* therefore is not instantiable nor extendible. | ||
*/ | ||
public final class JsonDriven { | ||
|
||
private JsonDriven() { | ||
// NOP | ||
} | ||
|
||
/** | ||
* @param <T> | ||
* is inferred from class, has no meaning, just suppresses warnings | ||
* @param filename | ||
* of json file | ||
* @param clazz | ||
* of deserialized object, typically some form of container (array) for test configuration | ||
* @return deserialized object array | ||
*/ | ||
public static <T> T provide(String filename, Class<T> clazz) { | ||
return new GsonBuilder().create() | ||
.fromJson(fileToJson(filename), clazz); | ||
} | ||
|
||
public static <T> T provide(Reader reader, Class<T> clazz) { | ||
return new GsonBuilder().create() | ||
.fromJson(readerToJson(reader), clazz); | ||
} | ||
|
||
/** | ||
* @param fileName | ||
* fileName | ||
* @return json from file or empty object when parsing file failed | ||
*/ | ||
private static JsonArray fileToJson(String fileName) { | ||
try (Reader reader = new FileReader(fileName)) { | ||
return readerToJson(reader); | ||
} catch (FileNotFoundException e) { | ||
BFLogger.logError("Json file not found: " + fileName); | ||
} catch (IOException e) { | ||
BFLogger.logError("Json file could not be read: " + fileName); | ||
} | ||
return new JsonArray(); | ||
} | ||
|
||
/** | ||
* @param reader | ||
* reader | ||
* @return json from reader | ||
*/ | ||
private static JsonArray readerToJson(Reader reader) { | ||
return new JsonParser().parse(reader) | ||
.getAsJsonArray(); | ||
} | ||
|
||
private JsonDriven() { | ||
// NOP | ||
} | ||
|
||
/** | ||
* @param <T> is inferred from class, has no meaning, just suppresses warnings | ||
* @param filename of json file | ||
* @param clazz of deserialized object, typically some form of container (array) for test configuration | ||
* @return deserialized object array | ||
*/ | ||
public static <T> T provide(String filename, Class<T> clazz) { | ||
return new GsonBuilder().create() | ||
.fromJson(fileToJson(filename), clazz); | ||
} | ||
|
||
public static <T> T provide(Reader reader, Class<T> clazz) { | ||
return new GsonBuilder().create() | ||
.fromJson(readerToJson(reader), clazz); | ||
} | ||
|
||
/** | ||
* @param fileName fileName | ||
* @return json from file or empty object when parsing file failed | ||
*/ | ||
private static JsonArray fileToJson(String fileName) { | ||
try (Reader reader = new FileReader(fileName)) { | ||
return readerToJson(reader); | ||
} catch (FileNotFoundException e) { | ||
BFLogger.logError("Json file not found: " + fileName); | ||
} catch (IOException e) { | ||
BFLogger.logError("Json file could not be read: " + fileName); | ||
} | ||
return new JsonArray(); | ||
} | ||
|
||
/** | ||
* @param reader reader | ||
* @return json from reader | ||
*/ | ||
private static JsonArray readerToJson(Reader reader) { | ||
return new JsonParser().parse(reader) | ||
.getAsJsonArray(); | ||
} | ||
} |
Oops, something went wrong.