This repository has been archived by the owner on Nov 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
reemuru
committed
Jul 27, 2021
1 parent
2ebc0fd
commit e4e0503
Showing
6 changed files
with
94 additions
and
26 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
68 changes: 68 additions & 0 deletions
68
src/test/java/org/hiahatf/mass/service/rate/RateServiceTest.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,5 +1,73 @@ | ||
package org.hiahatf.mass.service.rate; | ||
|
||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.google.common.net.HttpHeaders; | ||
|
||
import org.hiahatf.mass.services.rate.RateService; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.platform.runner.JUnitPlatform; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import io.netty.handler.codec.http.HttpHeaderValues; | ||
import okhttp3.mockwebserver.MockResponse; | ||
import okhttp3.mockwebserver.MockWebServer; | ||
|
||
/** | ||
* Tests for Rate Service | ||
*/ | ||
@ExtendWith(MockitoExtension.class) | ||
@RunWith(JUnitPlatform.class) | ||
public class RateServiceTest { | ||
|
||
public static MockWebServer mockBackEnd; | ||
private ObjectMapper objectMapper = new ObjectMapper(); | ||
private RateService rateService; | ||
|
||
@BeforeAll | ||
static void setUp() throws IOException { | ||
mockBackEnd = new MockWebServer(); | ||
mockBackEnd.start(); | ||
} | ||
|
||
@AfterAll | ||
static void tearDown() throws IOException { | ||
mockBackEnd.shutdown(); | ||
} | ||
|
||
@BeforeEach | ||
void initialize() { | ||
String baseUrl = String.format("http://localhost:%s", | ||
mockBackEnd.getPort()); | ||
rateService = new RateService(baseUrl); | ||
} | ||
|
||
@Test | ||
@DisplayName("Rate Service Test") | ||
public void getRateTest() throws JsonProcessingException { | ||
String expectedRate = "{\"BTC\":\"0.00777\"}"; | ||
HashMap<String,String> res = new HashMap<>(); | ||
res.put("BTC", "0.00777"); | ||
mockBackEnd.enqueue(new MockResponse() | ||
.setBody(objectMapper.writeValueAsString(res)) | ||
.addHeader(HttpHeaders.CONTENT_TYPE, | ||
HttpHeaderValues.APPLICATION_JSON.toString())); | ||
|
||
rateService.updateMoneroRate(); | ||
String testRate = rateService.getMoneroRate(); | ||
assertEquals(expectedRate, testRate); | ||
} | ||
|
||
} |