All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.testvagrant.optimus.commons.filehandlers.TestFeedJsonParser Maven / Gradle / Ivy

Go to download

Optimus Lite API to manage test devices and create appium driver based on platform

There is a newer version: 0.1.7-beta
Show newest version
package com.testvagrant.optimus.commons.filehandlers;

import com.testvagrant.optimus.core.exceptions.TestFeedNotFoundException;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.concurrent.atomic.AtomicReference;

import static com.testvagrant.optimus.commons.filehandlers.ResourcePaths.*;

public class TestFeedJsonParser {

  public static final String[] validPaths =
      new String[] {
        TEST_RESOURCES, TEST_TEST_FEED_RESOURCES, MAIN_RESOURCES, MAIN_TEST_FEED_RESOURCES
      };

  public  T deserialize(String name, Class tClass) {
    try {
      AtomicReference filePath = new AtomicReference<>("");

      for (String path : validPaths) {
        File file = FileFinder.fileFinder(path).find(name, ".json");
        if (file != null && file.exists()) {
          filePath.set(file.getPath());
          break;
        }
      }
      return GsonParser.toInstance().deserialize(new FileReader(filePath.get()), tClass);
    } catch (FileNotFoundException e) {
      throw new TestFeedNotFoundException(name, validPaths);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy