<commit_before>package rjson;

import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.junit.Assert;
import org.junit.Test;

import rjson.domain.ObjectWithFinal;
import rjson.domain.ObjectWithTransient;
import rjson.domain.Person;
import rjson.printer.Printer;
import rjson.transformer.Transformer;

public class ToJsonTest {	
	@Test public void toJsonNullObject() throws IOException {
		Assert.assertEquals("\"null\"", serializer().toJson(null));
	}
	
	@Test public void toJsonPrimitiveInt() throws IOException {
		Assert.assertEquals("123", serializer().toJson(123));
	}
	
	@Test public void toJsonObjectInt() throws IOException {
		Assert.assertEquals("123", serializer().toJson(new Integer(123)));
	}
	
	@Test public void toJsonPrimitiveFloat() throws IOException {
		Assert.assertEquals("123.45", serializer().toJson(123.45));
	}
	
	@Test public void toJsonObjectFloat() throws IOException {
		Assert.assertEquals("123.45", serializer().toJson(new Float(123.45)));
	}
	
	@Test public void toJsonBigDecimal() throws IOException {
		Assert.assertEquals("123.4560000000000030695446184836328029632568359375", serializer().toJson(new BigDecimal(123.456)));
	}
	
	@Test public void toJsonPrimitiveBoolean() throws IOException {
		Assert.assertEquals("true", serializer().toJson(true));
		Assert.assertEquals("false", serializer().toJson(false));
	}
	
	@Test public void toJsonObjectBoolean() throws IOException {
		Assert.assertEquals("true", serializer().toJson(new Boolean(true)));
		Assert.assertEquals("false", serializer().toJson(new Boolean(false)));
	}
	
	@Test public void toJsonString() throws IOException {
		Assert.assertEquals("\"qwerty\"", serializer().toJson("qwerty"));
	}
	
	@Test public void toJsonStringWithSpecialJsonCharacters() throws IOException {
		Assert.assertEquals("\"q\\[w\\]e\\{r\\}ty\"", serializer().toJson("q[w]e{r}ty"));
	}
	
	@Test public void toJsonDate() {
		Date date = new Date(Long.parseLong("1309814968887"));
		Assert.assertEquals("1309814968887", Rjson.newInstance().toJson(date));
	}
	
	@Test public void toJsonEmptyList() throws IOException {
		String expectedJson = fileAsString("./src/test/java/DATA-java.util.List/empty-list.txt");
		String actualJson = serializer().toJson(new ArrayList<String>());
		Assert.assertEquals(expectedJson, actualJson);
	}
	
	@Test public void toJsonStringList() throws IOException {
		List<String> l = new ArrayList<String>();
		l.add("qwerty");
		l.add("asdfgh");
		
		String expectedJson = fileAsString("./src/test/java/DATA-java.util.List/string-list.txt");
		String actualJson = serializer().toJson(l);
		Assert.assertEquals(expectedJson, actualJson);
	}
	
	@Test public void toJsonEmptyArray() throws IOException {
		String expectedJson = fileAsString("./src/test/java/DATA-java.util.List/empty-list.txt");
		String actualJson = serializer().toJson(new String[] {});
		Assert.assertEquals(expectedJson, actualJson);
	}
	
	@Test public void toJsonStringArray() throws IOException {
		String expectedJson = fileAsString("./src/test/java/DATA-java.util.List/string-list.txt");
		String actualJson = serializer().toJson(new String[] {"qwerty", "asdfgh"});
		Assert.assertEquals(expectedJson, actualJson);
	}
	
	@Test public void toJsonEmptyMap() throws IOException {
		String expectedJson = fileAsString("./src/test/java/DATA-java.util.Map/empty-map.txt");
		String actualJson = serializer().toJson(new HashMap<String, String>());
		Assert.assertEquals(expectedJson, actualJson);
	}
	
	@Test public void toJsonStringStringMap() throws IOException {
		Map<String, String> m = new HashMap<String, String>();
		m.put("key1", "qwerty");
		m.put("key2", "asdfgh");
		
		String expectedJson = fileAsString("./src/test/java/DATA-java.util.Map/string-string-map.txt");
		String actualJson = serializer().toJson(m);
		Assert.assertEquals(expectedJson, actualJson);
	}
	
	@Test public void toJsonAComplexObject() throws IOException {
		String expectedJson = fileAsString("./src/test/java/DATA-rjson.domain.Person/fully-loaded-person-object.txt");
		String actualJson = serializer().toJson(Person.getFullyLoadedInstance());
		Assert.assertEquals(expectedJson, actualJson);
	}
	
	@Test public void toJsonAPartialComplexObject() throws IOException {
		String expectedJson = fileAsString("./src/test/java/DATA-rjson.domain.Person/partial-person-object-1.txt");
		String actualJson = serializer().toJson(Person.getPartialInstance1());
		Assert.assertEquals(expectedJson, actualJson);
	}
	
	@Test public void toJsonRespectsTransient() throws IOException {
		String expectedJson = fileAsString("./src/test/java/DATA-rjson.domain.ObjectWithTransient/default.txt");
		String actualJson = serializer().toJson(new ObjectWithTransient());
		Assert.assertEquals(expectedJson, actualJson);
	}
	
	@Test public void toJsonRespectsFinal() throws IOException {
		String expectedJson = fileAsString("./src/test/java/DATA-rjson.domain.ObjectWithFinal/default.txt");
		String actualJson = serializer().toJson(new ObjectWithFinal());
		Assert.assertEquals(expectedJson, actualJson);
	}
	
	private Rjson serializer() {
		Transformer ignoreDateTransformer = new Transformer() {
			public boolean canHandle(Object object) {
				if(object instanceof java.util.Date)
					return true;
				return false;
			}
			public void transform(Object object, Printer printer, Rjson rjson) {
				return;
			}
		};
		return Rjson.newInstance().andIgnoreModifiers().and(ignoreDateTransformer);
	}
	
	private String fileAsString(String file) throws IOException {
		return FileUtils.readFileToString(new File(file));
	}
}<commit_msg>Changed the order of ignoremodifiers and with Transformer to make it more readable<commit_after>package rjson;

import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.junit.Assert;
import org.junit.Test;

import rjson.domain.ObjectWithFinal;
import rjson.domain.ObjectWithTransient;
import rjson.domain.Person;
import rjson.printer.Printer;
import rjson.transformer.Transformer;

public class ToJsonTest {	
	@Test public void toJsonNullObject() throws IOException {
		Assert.assertEquals("\"null\"", serializer().toJson(null));
	}
	
	@Test public void toJsonPrimitiveInt() throws IOException {
		Assert.assertEquals("123", serializer().toJson(123));
	}
	
	@Test public void toJsonObjectInt() throws IOException {
		Assert.assertEquals("123", serializer().toJson(new Integer(123)));
	}
	
	@Test public void toJsonPrimitiveFloat() throws IOException {
		Assert.assertEquals("123.45", serializer().toJson(123.45));
	}
	
	@Test public void toJsonObjectFloat() throws IOException {
		Assert.assertEquals("123.45", serializer().toJson(new Float(123.45)));
	}
	
	@Test public void toJsonBigDecimal() throws IOException {
		Assert.assertEquals("123.4560000000000030695446184836328029632568359375", serializer().toJson(new BigDecimal(123.456)));
	}
	
	@Test public void toJsonPrimitiveBoolean() throws IOException {
		Assert.assertEquals("true", serializer().toJson(true));
		Assert.assertEquals("false", serializer().toJson(false));
	}
	
	@Test public void toJsonObjectBoolean() throws IOException {
		Assert.assertEquals("true", serializer().toJson(new Boolean(true)));
		Assert.assertEquals("false", serializer().toJson(new Boolean(false)));
	}
	
	@Test public void toJsonString() throws IOException {
		Assert.assertEquals("\"qwerty\"", serializer().toJson("qwerty"));
	}
	
	@Test public void toJsonStringWithSpecialJsonCharacters() throws IOException {
		Assert.assertEquals("\"q\\[w\\]e\\{r\\}ty\"", serializer().toJson("q[w]e{r}ty"));
	}
	
	@Test public void toJsonDate() {
		Date date = new Date(Long.parseLong("1309814968887"));
		Assert.assertEquals("1309814968887", Rjson.newInstance().toJson(date));
	}
	
	@Test public void toJsonEmptyList() throws IOException {
		String expectedJson = fileAsString("./src/test/java/DATA-java.util.List/empty-list.txt");
		String actualJson = serializer().toJson(new ArrayList<String>());
		Assert.assertEquals(expectedJson, actualJson);
	}
	
	@Test public void toJsonStringList() throws IOException {
		List<String> l = new ArrayList<String>();
		l.add("qwerty");
		l.add("asdfgh");
		
		String expectedJson = fileAsString("./src/test/java/DATA-java.util.List/string-list.txt");
		String actualJson = serializer().toJson(l);
		Assert.assertEquals(expectedJson, actualJson);
	}
	
	@Test public void toJsonEmptyArray() throws IOException {
		String expectedJson = fileAsString("./src/test/java/DATA-java.util.List/empty-list.txt");
		String actualJson = serializer().toJson(new String[] {});
		Assert.assertEquals(expectedJson, actualJson);
	}
	
	@Test public void toJsonStringArray() throws IOException {
		String expectedJson = fileAsString("./src/test/java/DATA-java.util.List/string-list.txt");
		String actualJson = serializer().toJson(new String[] {"qwerty", "asdfgh"});
		Assert.assertEquals(expectedJson, actualJson);
	}
	
	@Test public void toJsonEmptyMap() throws IOException {
		String expectedJson = fileAsString("./src/test/java/DATA-java.util.Map/empty-map.txt");
		String actualJson = serializer().toJson(new HashMap<String, String>());
		Assert.assertEquals(expectedJson, actualJson);
	}
	
	@Test public void toJsonStringStringMap() throws IOException {
		Map<String, String> m = new HashMap<String, String>();
		m.put("key1", "qwerty");
		m.put("key2", "asdfgh");
		
		String expectedJson = fileAsString("./src/test/java/DATA-java.util.Map/string-string-map.txt");
		String actualJson = serializer().toJson(m);
		Assert.assertEquals(expectedJson, actualJson);
	}
	
	@Test public void toJsonAComplexObject() throws IOException {
		String expectedJson = fileAsString("./src/test/java/DATA-rjson.domain.Person/fully-loaded-person-object.txt");
		String actualJson = serializer().toJson(Person.getFullyLoadedInstance());
		Assert.assertEquals(expectedJson, actualJson);
	}
	
	@Test public void toJsonAPartialComplexObject() throws IOException {
		String expectedJson = fileAsString("./src/test/java/DATA-rjson.domain.Person/partial-person-object-1.txt");
		String actualJson = serializer().toJson(Person.getPartialInstance1());
		Assert.assertEquals(expectedJson, actualJson);
	}
	
	@Test public void toJsonRespectsTransient() throws IOException {
		String expectedJson = fileAsString("./src/test/java/DATA-rjson.domain.ObjectWithTransient/default.txt");
		String actualJson = serializer().toJson(new ObjectWithTransient());
		Assert.assertEquals(expectedJson, actualJson);
	}
	
	@Test public void toJsonRespectsFinal() throws IOException {
		String expectedJson = fileAsString("./src/test/java/DATA-rjson.domain.ObjectWithFinal/default.txt");
		String actualJson = serializer().toJson(new ObjectWithFinal());
		Assert.assertEquals(expectedJson, actualJson);
	}
	
	private Rjson serializer() {
		Transformer ignoreDateTransformer = new Transformer() {
			public boolean canHandle(Object object) {
				if(object instanceof java.util.Date)
					return true;
				return false;
			}
			public void transform(Object object, Printer printer, Rjson rjson) {
				return;
			}
		};
		return Rjson.newInstance().with(ignoreDateTransformer).andIgnoreModifiers();
	}
	
	private String fileAsString(String file) throws IOException {
		return FileUtils.readFileToString(new File(file));
	}
}
{'fraction_non_alphanumeric': 0.13735314443676572, 'fraction_numerical': 0.020214236351071183, 'mean_word_length': 5.514912774338773, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '230713', 'n_tokens_mistral': 3807, 'n_tokens_neox': 3424, 'n_words': 690}