Package com.box.boxjavalibv2.testutils

Source Code of com.box.boxjavalibv2.testutils.TestUtils

package com.box.boxjavalibv2.testutils;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;

import com.box.boxjavalibv2.BoxConfigBuilder;
import com.box.boxjavalibv2.IBoxConfig;
import com.box.boxjavalibv2.dao.BoxObject;
import com.box.boxjavalibv2.jsonparsing.BoxJSONParser;
import com.box.boxjavalibv2.jsonparsing.BoxResourceHub;
import com.box.boxjavalibv2.jsonparsing.IBoxJSONParser;
import com.box.restclientv2.exceptions.BoxRestException;

public class TestUtils {

    public static File createTempFile(String fileContent) throws IOException {
        File tmp = File.createTempFile("tmp", "tmp");
        FileUtils.writeStringToFile(tmp, fileContent);
        return tmp;
    }

    @SuppressWarnings({"unchecked", "rawtypes"})
    public static BoxObject getFromJSON(String json, Class cls) throws BoxRestException {
        BoxJSONParser jsonParser = new BoxJSONParser(new BoxResourceHub());
        return jsonParser.parseIntoBoxObjectQuietly(json, (Class<BoxObject>) cls);
    }

    public static IBoxConfig getConfig() {
        BoxConfigBuilder builder = new BoxConfigBuilder();
        return builder.build();
    }

    public static IBoxJSONParser getJsonParser() {
        return new BoxJSONParser(new BoxResourceHub());
    }
}
TOP

Related Classes of com.box.boxjavalibv2.testutils.TestUtils

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.