This repository has been archived by the owner on Jul 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump json from 20180813 to 20200518 (#321)
* Bump json from 20180813 to 20200518 Bumps [json](https://github.com/douglascrockford/JSON-java) from 20180813 to 20200518. - [Release notes](https://github.com/douglascrockford/JSON-java/releases) - [Commits](https://github.com/douglascrockford/JSON-java/commits) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> * fix new json version conflicts * fix failing build * PR comment * fix failing test * fix sonarcloud code smeels * fix build Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: Constantin Costescu <constantineugen.costescu@gmail.com>
- Loading branch information
1 parent
f9fb954
commit b275790
Showing
10 changed files
with
123 additions
and
16 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
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
41 changes: 41 additions & 0 deletions
41
src/main/java/org/proshin/finapi/primitives/BigDecimalOf.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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2020 Roman Proshin | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.proshin.finapi.primitives; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.function.Supplier; | ||
import org.cactoos.text.FormattedText; | ||
import org.json.JSONObject; | ||
import org.proshin.finapi.primitives.optional.OptionalBigDecimalOf; | ||
|
||
public final class BigDecimalOf implements Supplier<BigDecimal> { | ||
|
||
private final OptionalBigDecimalOf origin; | ||
private final String field; | ||
|
||
public BigDecimalOf(final JSONObject origin, final String name) { | ||
this.origin = new OptionalBigDecimalOf(origin, name); | ||
this.field = name; | ||
} | ||
|
||
@Override | ||
public BigDecimal get() { | ||
return this.origin.get() | ||
.orElseThrow(() -> new IllegalStateException( | ||
new FormattedText("Field '%s' cannot be null", this.field).toString() | ||
)); | ||
} | ||
} |
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
60 changes: 60 additions & 0 deletions
60
src/test/java/org/proshin/finapi/primitives/BigDecimalOfTest.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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2018 Roman Proshin | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.proshin.finapi.primitives; | ||
|
||
import java.math.BigDecimal; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public final class BigDecimalOfTest { | ||
|
||
@Test | ||
public void testJsonDouble() { | ||
assertThat(new BigDecimalOf(new JSONObject().put("key", -12.34), "key").get()) | ||
.isEqualTo(new BigDecimal("-12.34")); | ||
} | ||
|
||
@Test | ||
public void testJsonInt() { | ||
assertThat(new BigDecimalOf(new JSONObject().put("key", -12), "key").get()) | ||
.isEqualTo(new BigDecimal("-12")); | ||
} | ||
|
||
@Test | ||
public void testJsonString() { | ||
assertThat(new BigDecimalOf(new JSONObject().put("key", "-12.34"), "key").get()) | ||
.isEqualTo(new BigDecimal("-12.34")); | ||
} | ||
|
||
@Test | ||
public void testNullValue() { | ||
final BigDecimalOf bigDecimalOf = new BigDecimalOf(new JSONObject(), "key"); | ||
assertThatThrownBy(bigDecimalOf::get) | ||
.isInstanceOf(IllegalStateException.class) | ||
.hasMessage("Field 'key' cannot be null"); | ||
} | ||
|
||
@Test | ||
public void testInvalidValue() { | ||
final BigDecimalOf bigDecimalOf = new BigDecimalOf(new JSONObject().put("key", "abc"), "key"); | ||
assertThatThrownBy(bigDecimalOf::get) | ||
.isInstanceOf(JSONException.class) | ||
.hasMessage("JSONObject[\"key\"] is not a number."); | ||
} | ||
} |