-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from johnjaylward/PopulateMapMoreStrict
Populate map more strict
- Loading branch information
Showing
22 changed files
with
560 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.json.junit.data; | ||
|
||
/** | ||
* test class for verifying write errors. | ||
* @author John Aylward | ||
* | ||
*/ | ||
public class BrokenToString { | ||
@Override | ||
public String toString() { | ||
throw new IllegalStateException("Something went horribly wrong!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* | ||
*/ | ||
package org.json.junit.data; | ||
|
||
import java.io.Closeable; | ||
import java.io.IOException; | ||
import java.lang.reflect.InvocationTargetException; | ||
|
||
import org.json.JSONObject; | ||
|
||
/** | ||
* Object for testing the exception handling in {@link JSONObject#populateMap}. | ||
* | ||
* @author John Aylward | ||
*/ | ||
public class ExceptionalBean { | ||
/** | ||
* @return a closeable. | ||
*/ | ||
public Closeable getCloseable() { | ||
// anonymous inner class did not work... | ||
return new MyCloseable(); | ||
} | ||
|
||
/** | ||
* @return Nothing really. Just can't be void. | ||
* @throws IllegalAccessException | ||
* always thrown | ||
*/ | ||
public int getIllegalAccessException() throws IllegalAccessException { | ||
throw new IllegalAccessException("Yup, it's illegal"); | ||
} | ||
|
||
/** | ||
* @return Nothing really. Just can't be void. | ||
* @throws IllegalArgumentException | ||
* always thrown | ||
*/ | ||
public int getIllegalArgumentException() throws IllegalArgumentException { | ||
throw new IllegalArgumentException("Yup, it's illegal"); | ||
} | ||
|
||
/** | ||
* @return Nothing really. Just can't be void. | ||
* @throws InvocationTargetException | ||
* always thrown | ||
*/ | ||
public int getInvocationTargetException() throws InvocationTargetException { | ||
throw new InvocationTargetException(new Exception("Yup, it's illegal")); | ||
} | ||
|
||
/** My closeable class. */ | ||
public static final class MyCloseable implements Closeable { | ||
|
||
/** | ||
* @return a string | ||
*/ | ||
@SuppressWarnings("unused") | ||
public String getString() { | ||
return "Yup, it's closeable"; | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
throw new IOException("Closing is too hard!"); | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/test/java/org/json/junit/Fraction.java → ...st/java/org/json/junit/data/Fraction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package org.json.junit; | ||
package org.json.junit.data; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.BigInteger; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package org.json.junit.data; | ||
|
||
import java.io.StringReader; | ||
|
||
/** | ||
* | ||
* @author John Aylward | ||
* | ||
* @param <T> | ||
* 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; | ||
} | ||
|
||
/** */ | ||
private T genericValue; | ||
/** to be used by the calling test to see how often the getter is called */ | ||
public int genericGetCounter; | ||
/** to be used by the calling test to see how often the setter is called */ | ||
public int genericSetCounter; | ||
|
||
/** @return the genericValue */ | ||
public T getGenericValue() { | ||
this.genericGetCounter++; | ||
return this.genericValue; | ||
} | ||
|
||
/** | ||
* @param genericValue | ||
* generic value to set | ||
*/ | ||
public void setGenericValue(T genericValue) { | ||
this.genericSetCounter++; | ||
this.genericValue = genericValue; | ||
} | ||
|
||
@Override | ||
public Integer getIntKey() { | ||
return Integer.valueOf(42); | ||
} | ||
|
||
@Override | ||
public Double getDoubleKey() { | ||
return Double.valueOf(4.2); | ||
} | ||
|
||
@Override | ||
public String getStringKey() { | ||
return "MyString Key"; | ||
} | ||
|
||
@Override | ||
public String getEscapeStringKey() { | ||
return "\"My String with \"s"; | ||
} | ||
|
||
@Override | ||
public Boolean isTrueKey() { | ||
return Boolean.TRUE; | ||
} | ||
|
||
@Override | ||
public Boolean isFalseKey() { | ||
return Boolean.FALSE; | ||
} | ||
|
||
@Override | ||
public StringReader getStringReaderKey() { | ||
return new StringReader("Some String Value in a reader"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* | ||
*/ | ||
package org.json.junit.data; | ||
|
||
/** | ||
* @author john | ||
* | ||
*/ | ||
public class GenericBeanInt extends GenericBean<Integer> { | ||
/** */ | ||
final char a = 'A'; | ||
|
||
/** @return the a */ | ||
public char getA() { | ||
return a; | ||
} | ||
|
||
/** | ||
* Should not be beanable | ||
* | ||
* @return false | ||
*/ | ||
public boolean getable() { | ||
return false; | ||
} | ||
|
||
/** | ||
* @param genericValue | ||
* the value to initiate with. | ||
*/ | ||
public GenericBeanInt(Integer genericValue) { | ||
super(genericValue); | ||
} | ||
|
||
/** override to generate a bridge method */ | ||
@Override | ||
public Integer getGenericValue() { | ||
return super.getGenericValue(); | ||
} | ||
|
||
} |
Oops, something went wrong.