|
@@ -1,14 +1,20 @@
|
|
|
package service;
|
|
package service;
|
|
|
|
|
|
|
|
import com.danielbohry.stocks.App;
|
|
import com.danielbohry.stocks.App;
|
|
|
|
|
+import com.danielbohry.stocks.domain.Quote;
|
|
|
import com.danielbohry.stocks.repository.StockRepository;
|
|
import com.danielbohry.stocks.repository.StockRepository;
|
|
|
import com.danielbohry.stocks.service.StockService;
|
|
import com.danielbohry.stocks.service.StockService;
|
|
|
import org.junit.jupiter.api.AfterEach;
|
|
import org.junit.jupiter.api.AfterEach;
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
import org.springframework.test.context.ContextConfiguration;
|
|
import org.springframework.test.context.ContextConfiguration;
|
|
|
|
|
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
+
|
|
|
@SpringBootTest
|
|
@SpringBootTest
|
|
|
@ContextConfiguration(classes = {App.class})
|
|
@ContextConfiguration(classes = {App.class})
|
|
|
public class StockServiceTest {
|
|
public class StockServiceTest {
|
|
@@ -23,9 +29,30 @@ public class StockServiceTest {
|
|
|
service = new StockService(repository);
|
|
service = new StockService(repository);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @AfterEach
|
|
|
|
|
- public void teardown() {
|
|
|
|
|
- repository.deleteAll();
|
|
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void shouldGetStockByCode() {
|
|
|
|
|
+ //given
|
|
|
|
|
+ String code = "AAPL";
|
|
|
|
|
+ Quote expected = new Quote(code, "Apple Inc.", null, null);
|
|
|
|
|
+
|
|
|
|
|
+ //when
|
|
|
|
|
+ Quote result = service.getByCode(code);
|
|
|
|
|
+
|
|
|
|
|
+ //then
|
|
|
|
|
+ assertEquals(expected.getCode(), result.getCode());
|
|
|
|
|
+ assertEquals(expected.getName(), result.getName());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void shouldGetStockByName() {
|
|
|
|
|
+ //given
|
|
|
|
|
+ String name = "West";
|
|
|
|
|
+
|
|
|
|
|
+ //when
|
|
|
|
|
+ List<Quote> result = service.get(name);
|
|
|
|
|
+
|
|
|
|
|
+ //then
|
|
|
|
|
+ assertEquals(19, result.size());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|