mirror of
https://github.com/correl/mage.git
synced 2024-12-25 19:25:41 +00:00
Rafactor: removed old junit
This commit is contained in:
parent
004c2ba0c3
commit
8e74cc1d6a
1 changed files with 11 additions and 13 deletions
|
@ -2,13 +2,11 @@ package com.anygo.ws.json;
|
||||||
|
|
||||||
import com.xmage.ws.util.json.JSONParser;
|
import com.xmage.ws.util.json.JSONParser;
|
||||||
import com.xmage.ws.util.json.JSONValidationException;
|
import com.xmage.ws.util.json.JSONValidationException;
|
||||||
import junit.framework.Assert;
|
|
||||||
import net.minidev.json.JSONArray;
|
|
||||||
import net.minidev.json.JSONObject;
|
import net.minidev.json.JSONObject;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author noxx
|
* @author noxx
|
||||||
*/
|
*/
|
||||||
public class TestJSONParser {
|
public class TestJSONParser {
|
||||||
|
@ -47,30 +45,30 @@ public class TestJSONParser {
|
||||||
public void testQueryForJSONArray() throws Exception {
|
public void testQueryForJSONArray() throws Exception {
|
||||||
JSONParser parser = new JSONParser();
|
JSONParser parser = new JSONParser();
|
||||||
parser.parseJSON("{\"test\" : [\"1\", \"2\", \"3\"]}");
|
parser.parseJSON("{\"test\" : [\"1\", \"2\", \"3\"]}");
|
||||||
Assert.assertTrue(parser.getJSONArray("test") instanceof JSONArray);
|
Assert.assertNotNull(parser.getJSONArray("test"));
|
||||||
Assert.assertEquals("1", parser.getJSONArray("test").get(0));
|
Assert.assertEquals("1", parser.getJSONArray("test").get(0));
|
||||||
|
|
||||||
parser = new JSONParser();
|
parser = new JSONParser();
|
||||||
parser.parseJSON("{\"test\" : [1,2,3]}");
|
parser.parseJSON("{\"test\" : [1,2,3]}");
|
||||||
Assert.assertTrue(parser.getJSONArray("test") instanceof JSONArray);
|
Assert.assertNotNull(parser.getJSONArray("test"));
|
||||||
Assert.assertFalse(parser.isHitCache());
|
Assert.assertFalse(parser.isHitCache());
|
||||||
Assert.assertEquals(2, parser.getJSONArray("test").get(1));
|
Assert.assertEquals(2, parser.getJSONArray("test").get(1));
|
||||||
Assert.assertTrue(parser.isHitCache());
|
Assert.assertTrue(parser.isHitCache());
|
||||||
|
|
||||||
Assert.assertTrue(parser.getJSONArray("test") instanceof JSONArray);
|
Assert.assertNotNull(parser.getJSONArray("test"));
|
||||||
Assert.assertEquals(2, parser.getJSONArray("test").get(1));
|
Assert.assertEquals(2, parser.getJSONArray("test").get(1));
|
||||||
Assert.assertTrue(parser.isHitCache());
|
Assert.assertTrue(parser.isHitCache());
|
||||||
|
|
||||||
parser = new JSONParser();
|
parser = new JSONParser();
|
||||||
parser.parseJSON("{\"test\" : [{second_level: \"3\"}, {\"third_level\" : 2}]}");
|
parser.parseJSON("{\"test\" : [{second_level: \"3\"}, {\"third_level\" : 2}]}");
|
||||||
Assert.assertTrue(parser.getJSONArray("test") instanceof JSONArray);
|
Assert.assertNotNull(parser.getJSONArray("test"));
|
||||||
Assert.assertTrue(parser.getJSONArray("test").get(0) instanceof JSONObject);
|
Assert.assertTrue(parser.getJSONArray("test").get(0) instanceof JSONObject);
|
||||||
Assert.assertEquals(2, parser.getInt("test[1].third_level"));
|
Assert.assertEquals(2, parser.getInt("test[1].third_level"));
|
||||||
Assert.assertEquals("3", parser.getString("test[0].second_level"));
|
Assert.assertEquals("3", parser.getString("test[0].second_level"));
|
||||||
|
|
||||||
parser = new JSONParser();
|
parser = new JSONParser();
|
||||||
parser.parseJSON("{\"test\" : [{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{2:3},{4:5}]}");
|
parser.parseJSON("{\"test\" : [{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{2:3},{4:5}]}");
|
||||||
Assert.assertTrue(parser.getJSONArray("test") instanceof JSONArray);
|
Assert.assertNotNull(parser.getJSONArray("test"));
|
||||||
Assert.assertEquals(5, parser.getInt("test[10].4"));
|
Assert.assertEquals(5, parser.getInt("test[10].4"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,9 +87,9 @@ public class TestJSONParser {
|
||||||
Assert.assertEquals(2, parser.getInt("test.internal.level"));
|
Assert.assertEquals(2, parser.getInt("test.internal.level"));
|
||||||
Assert.assertFalse("No cache should have been used", parser.isHitCache());
|
Assert.assertFalse("No cache should have been used", parser.isHitCache());
|
||||||
|
|
||||||
Assert.assertTrue(parser.getJSON("test") instanceof JSONObject);
|
Assert.assertNotNull(parser.getJSON("test"));
|
||||||
Assert.assertFalse("No cache should have been used", parser.isHitCache());
|
Assert.assertFalse("No cache should have been used", parser.isHitCache());
|
||||||
Assert.assertTrue(parser.getJSON("test.internal") instanceof JSONObject);
|
Assert.assertNotNull(parser.getJSON("test.internal"));
|
||||||
Assert.assertFalse("No cache should have been used", parser.isHitCache());
|
Assert.assertFalse("No cache should have been used", parser.isHitCache());
|
||||||
|
|
||||||
parser = new JSONParser();
|
parser = new JSONParser();
|
||||||
|
@ -100,9 +98,9 @@ public class TestJSONParser {
|
||||||
Assert.assertEquals(2, parser.getInt("test.internal.level"));
|
Assert.assertEquals(2, parser.getInt("test.internal.level"));
|
||||||
Assert.assertFalse("No cache should have been used", parser.isHitCache());
|
Assert.assertFalse("No cache should have been used", parser.isHitCache());
|
||||||
|
|
||||||
Assert.assertTrue(parser.getJSON("test") instanceof JSONObject);
|
Assert.assertNotNull(parser.getJSON("test"));
|
||||||
Assert.assertTrue("Cache should have been used this time!", parser.isHitCache());
|
Assert.assertTrue("Cache should have been used this time!", parser.isHitCache());
|
||||||
Assert.assertTrue(parser.getJSON("test.internal") instanceof JSONObject);
|
Assert.assertNotNull(parser.getJSON("test.internal"));
|
||||||
Assert.assertTrue("Cache should have been used this time!", parser.isHitCache());
|
Assert.assertTrue("Cache should have been used this time!", parser.isHitCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +135,7 @@ public class TestJSONParser {
|
||||||
private void testError(JSONParser parser, String jsonToTest) throws Exception {
|
private void testError(JSONParser parser, String jsonToTest) throws Exception {
|
||||||
try {
|
try {
|
||||||
parser.parseJSON(jsonToTest);
|
parser.parseJSON(jsonToTest);
|
||||||
Assert.assertTrue("Should have thrown an exception", false);
|
Assert.fail("Should have thrown an exception");
|
||||||
} catch (JSONValidationException j) {
|
} catch (JSONValidationException j) {
|
||||||
// ok
|
// ok
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue