Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verifies BigDecimal support does not have a regression #532

Merged
merged 2 commits into from Jun 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/test/java/org/json/junit/JSONObjectTest.java
Expand Up @@ -35,6 +35,7 @@ of this software and associated documentation files (the "Software"), to deal
import static org.mockito.Mockito.when;

import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import java.math.BigDecimal;
Expand All @@ -55,6 +56,7 @@ of this software and associated documentation files (the "Software"), to deal
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONPointerException;
import org.json.JSONTokener;
import org.json.XML;
import org.json.junit.data.BrokenToString;
import org.json.junit.data.ExceptionalBean;
Expand Down Expand Up @@ -3079,6 +3081,23 @@ public void testWierdListBean() {
assertNotNull(jo.get("ALL"));
}

/**
* Sample test case from https://github.com/stleary/JSON-java/issues/531
* which verifies that no regression in double/BigDecimal support is present.
*/
public void testObjectToBigDecimal() {
double value = 1412078745.01074;
Reader reader = new StringReader("[{\"value\": " + value + "}]");
JSONTokener tokener = new JSONTokener(reader);
JSONArray array = new JSONArray(tokener);
JSONObject jsonObject = array.getJSONObject(0);

BigDecimal current = jsonObject.getBigDecimal("value");
BigDecimal wantedValue = BigDecimal.valueOf(value);

assertEquals(current, wantedValue);
}

/**
* Tests the exception portions of populateMap.
*/
Expand Down