-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CoinGecko to CurrencyConversionManager
- Loading branch information
1 parent
3ceaa8b
commit 5cc76f4
Showing
12 changed files
with
130 additions
and
153 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
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
40 changes: 40 additions & 0 deletions
40
service/src/test/java/org/whispersystems/textsecuregcm/currency/CoinGeckoClientTest.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,40 @@ | ||
package org.whispersystems.textsecuregcm.currency; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import java.io.IOException; | ||
import java.math.BigDecimal; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class CoinGeckoClientTest { | ||
|
||
private static final String RESPONSE_JSON = """ | ||
{ | ||
"mobilecoin": { | ||
"usd": 0.226212 | ||
} | ||
} | ||
"""; | ||
|
||
@Test | ||
void parseResponse() throws JsonProcessingException { | ||
final Map<String, Map<String, BigDecimal>> parsedResponse = CoinGeckoClient.parseResponse(RESPONSE_JSON); | ||
|
||
assertTrue(parsedResponse.containsKey("mobilecoin")); | ||
|
||
assertEquals(1, parsedResponse.get("mobilecoin").size()); | ||
assertEquals(new BigDecimal("0.226212"), parsedResponse.get("mobilecoin").get("usd")); | ||
} | ||
|
||
@Test | ||
void extractConversionRate() throws IOException { | ||
final Map<String, Map<String, BigDecimal>> parsedResponse = CoinGeckoClient.parseResponse(RESPONSE_JSON); | ||
|
||
assertEquals(new BigDecimal("0.226212"), CoinGeckoClient.extractConversionRate(parsedResponse.get("mobilecoin"), "usd")); | ||
assertThrows(IOException.class, () -> CoinGeckoClient.extractConversionRate(parsedResponse.get("mobilecoin"), "CAD")); | ||
} | ||
} |
Oops, something went wrong.