1
0
Fork 0
mirror of https://github.com/ethauvin/JSON-java.git synced 2025-06-17 07:50:52 -07:00

Updates javadocs

This commit is contained in:
John J. Aylward 2017-07-09 18:19:27 -04:00
parent 7bc8f41023
commit e94783f91b
6 changed files with 91 additions and 15 deletions

View file

@ -2590,6 +2590,9 @@ public class JSONObjectTest {
assertTrue("Map should have 2 elements", map.size() == 2);
}
/**
* test that validates a singleton can be serialized as a bean.
*/
@Test
public void testSingletonBean() {
final JSONObject jo = new JSONObject(Singleton.getInstance());
@ -2609,6 +2612,10 @@ public class JSONObjectTest {
assertEquals(0, jo.get("someInt"));
assertEquals(null, jo.opt("someString"));
}
/**
* test that validates a singleton can be serialized as a bean.
*/
@Test
public void testSingletonEnumBean() {
final JSONObject jo = new JSONObject(SingletonEnum.getInstance());
@ -2629,6 +2636,9 @@ public class JSONObjectTest {
assertEquals(null, jo.opt("someString"));
}
/**
* Test to validate that a generic class can be serialized as a bean.
*/
@Test
public void testGenericBean() {
GenericBean<Integer> bean = new GenericBean<>(42);
@ -2640,6 +2650,9 @@ public class JSONObjectTest {
assertEquals(0, bean.genericSetCounter);
}
/**
* Test to validate that a generic class can be serialized as a bean.
*/
@Test
public void testGenericIntBean() {
GenericBeanInt bean = new GenericBeanInt(42);
@ -2651,6 +2664,9 @@ public class JSONObjectTest {
assertEquals(0, bean.genericSetCounter);
}
/**
* Test to verify <code>key</code> limitations in the JSONObject bean serializer.
*/
@Test
public void testWierdListBean() {
WeirdList bean = new WeirdList(42, 43, 44);
@ -2660,7 +2676,8 @@ public class JSONObjectTest {
// getInt(int) should also be ignored based on parameter count
// add(Integer) should be ignore as it doesn't start with get/is and also has a parameter
// getALL should be mapped
assertEquals("Expected 1 key to mapped "+jo.keySet().toString(), 1, jo.length());
assertEquals("Expected 1 key to be mapped. Instead found: "+jo.keySet().toString(),
1, jo.length());
assertNotNull(jo.get("ALL"));
}
}

View file

@ -10,6 +10,10 @@ import java.io.StringReader;
* generic number value
*/
public class GenericBean<T extends Number & Comparable<T>> implements MyBean {
/**
* @param genericValue
* value to initiate with
*/
public GenericBean(T genericValue) {
super();
this.genericValue = genericValue;
@ -28,7 +32,10 @@ public class GenericBean<T extends Number & Comparable<T>> implements MyBean {
return this.genericValue;
}
/** sets the generic value */
/**
* @param genericValue
* generic value to set
*/
public void setGenericValue(T genericValue) {
this.genericSetCounter++;
this.genericValue = genericValue;

View file

@ -11,17 +11,24 @@ public class GenericBeanInt extends GenericBean<Integer> {
/** */
final char a = 'A';
/** return the a */
/** @return the a */
public char getA() {
return a;
}
/** return false. should not be beanable */
/**
* Should not be beanable
*
* @return false
*/
public boolean getable() {
return false;
}
/** */
/**
* @param genericValue
* the value to initiate with.
*/
public GenericBeanInt(Integer genericValue) {
super(genericValue);
}

View file

@ -36,7 +36,12 @@ public final class Singleton {
return someInt;
}
/** sets someInt */
/**
* sets someInt.
*
* @param someInt
* the someInt to set
*/
public void setSomeInt(int someInt) {
this.someInt = someInt;
}
@ -46,7 +51,12 @@ public final class Singleton {
return someString;
}
/** sets someString */
/**
* sets someString.
*
* @param someString
* the someString to set
*/
public void setSomeString(String someString) {
this.someString = someString;
}

View file

@ -7,6 +7,9 @@ package org.json.junit.data;
*
*/
public enum SingletonEnum {
/**
* the singleton instance.
*/
INSTANCE;
/** */
private int someInt;
@ -32,7 +35,12 @@ public enum SingletonEnum {
return someInt;
}
/** sets someInt */
/**
* sets someInt.
*
* @param someInt
* the someInt to set
*/
public void setSomeInt(int someInt) {
this.someInt = someInt;
}
@ -42,7 +50,12 @@ public enum SingletonEnum {
return someString;
}
/** sets someString */
/**
* sets someString.
*
* @param someString
* the someString to set
*/
public void setSomeString(String someString) {
this.someString = someString;
}

View file

@ -14,31 +14,53 @@ public class WeirdList {
/** */
private final List<Integer> list = new ArrayList<>();
/**
* @param vals
*/
public WeirdList(Integer... vals) {
this.list.addAll(Arrays.asList(vals));
}
/** gets a copy of the list */
/**
* @return a copy of the list
*/
public List<Integer> get() {
return new ArrayList<>(this.list);
}
/** gets a copy of the list */
/**
* @return a copy of the list
*/
public List<Integer> getALL() {
return new ArrayList<>(this.list);
}
/** get an index */
/**
* get a value at an index.
*
* @param i
* index to get
* @return the value at the index
*/
public Integer get(int i) {
return this.list.get(i);
}
/** get an index */
/**
* get a value at an index.
*
* @param i
* index to get
* @return the value at the index
*/
public int getInt(int i) {
return this.list.get(i);
}
/** adds a new value to the end of the list */
/**
* @param value
* new value to add to the end of the list
*/
public void add(Integer value) {
this.list.add(value);
}