<commit_before>package org.openprovenance.prov.json;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import javax.xml.bind.JAXBException;

import org.openprovenance.prov.xml.Document;
import org.openprovenance.prov.xml.DocumentEquality;
import org.openprovenance.prov.xml.Statement;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonIOException;
import com.google.gson.JsonSyntaxException;

/**
 * Round trip testing JavaBean -> PROV-JSON -> JavaBean
 */
public class RoundTripFromJavaTest extends org.openprovenance.prov.xml.RoundTripFromJavaTest
{
	private Gson gson = new GsonBuilder()
							.registerTypeAdapter(Document.class, new ProvDocumentDeserializer())
							.registerTypeAdapter(Document.class, new ProvDocumentSerializer())
							.setPrettyPrinting()
							.create();
	
	public RoundTripFromJavaTest(String testName) {
		super(testName);
	}

	@Override
	public String extension() {
		return ".json";
	}

	@Override
	public void makeDocAndTest(Statement stment, String file, Statement[] opt, boolean check)
			throws JAXBException {
		Document d1 = pFactory.newDocument();
		d1.getEntityOrActivityOrWasGeneratedBy().add(stment);
		updateNamespaces(d1);
		file = file + extension();

		try {
			writeJSONDocument(d1, file);
			Document d2 = readJSONDocument(file);
			if (check) {
				assertTrue(DocumentEquality.check(d1, d2));
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	protected Document readJSONDocument(String file) throws JsonSyntaxException, JsonIOException, FileNotFoundException {
		Document doc = gson.fromJson(new BufferedReader(new FileReader(file)), Document.class);
		return doc;
	}
	
	protected void writeJSONDocument(Document doc, String file) throws IOException {
		BufferedWriter writer = new BufferedWriter(new FileWriter(file));
		gson.toJson(doc, writer);
		writer.close();
	}

}<commit_msg>Updated to use the latest RoundTripFromJava class from prov-xml<commit_after>package org.openprovenance.prov.json;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;

import org.openprovenance.prov.xml.Document;
import org.openprovenance.prov.xml.UncheckedTestException;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

/**
 * Round trip testing JavaBean -> PROV-JSON -> JavaBean
 */
public class RoundTripFromJavaTest extends org.openprovenance.prov.xml.RoundTripFromJavaTest
{
	private Gson gson = new GsonBuilder()
							.registerTypeAdapter(Document.class, new ProvDocumentDeserializer())
							.registerTypeAdapter(Document.class, new ProvDocumentSerializer())
							.setPrettyPrinting()
							.create();
	
	public RoundTripFromJavaTest(String testName) {
		super(testName);
	}

	@Override
	public String extension() {
		return ".json";
	}
	
	public boolean checkTest(String name) {
		return !(name.contains("member2") || name.contains("member3"));
	}

	
	@Override
	public Document readDocument(String file) {
		try {
			Document doc = gson.fromJson(new BufferedReader(new FileReader(file)), Document.class);
			return doc;
		} catch (Exception e) {
			throw new UncheckedTestException(e);
		}
	}

	@Override
	public void writeDocument(Document doc, String file) {
		try {
			BufferedWriter writer = new BufferedWriter(new FileWriter(file));
			gson.toJson(doc, writer);
			writer.close();
		} catch (Exception e) {
			throw new UncheckedTestException(e);
		}
	}

}
{'fraction_non_alphanumeric': 0.10697546181417149, 'fraction_numerical': 0.0024813895781637717, 'mean_word_length': 4.767885532591415, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 9}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3143793', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1111, 'n_words': 244}