|
| 1 | +package com.hepsiburada.streamreader.generator; |
| 2 | + |
| 3 | + |
| 4 | +import com.hepsiburada.streamreader.model.BrowsingHistory; |
| 5 | +import com.hepsiburada.streamreader.model.Event; |
| 6 | +import com.hepsiburada.streamreader.model.submodel.EventContext; |
| 7 | +import com.hepsiburada.streamreader.model.submodel.EventProperties; |
| 8 | +import com.hepsiburada.streamreader.service.ProductService; |
| 9 | +import org.junit.Assert; |
| 10 | +import org.junit.Before; |
| 11 | +import org.junit.Test; |
| 12 | +import org.junit.runner.RunWith; |
| 13 | +import org.mockito.Mock; |
| 14 | +import org.mockito.Mockito; |
| 15 | +import org.springframework.test.context.junit4.SpringRunner; |
| 16 | + |
| 17 | +import java.sql.Timestamp; |
| 18 | +import java.util.List; |
| 19 | + |
| 20 | +@RunWith(SpringRunner.class) |
| 21 | +public class BrowsingHistoryGeneratorTest { |
| 22 | + |
| 23 | + @Mock |
| 24 | + private ProductService productService; |
| 25 | + |
| 26 | + private int userId = 1; |
| 27 | + private int productId = 10; |
| 28 | + private int categoryId = 3; |
| 29 | + |
| 30 | + @Before |
| 31 | + public void setUp() { |
| 32 | + |
| 33 | + List<?> category_id_list = List.of("categoryid-" + categoryId); |
| 34 | + Mockito.doReturn(category_id_list) |
| 35 | + .when(productService).getCategoryId("product-" + productId); |
| 36 | + |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void generator_test() { |
| 41 | + |
| 42 | + Event event = new Event("eventid", "messageid", "user-" + userId, new EventProperties("product-" + productId), new EventContext("mobile"), 1111L); |
| 43 | + |
| 44 | + BrowsingHistoryGenerator generator = new BrowsingHistoryGenerator(event, productService); |
| 45 | + BrowsingHistory history = generator.generate(); |
| 46 | + |
| 47 | + Assert.assertEquals(history.getCategoryId(), categoryId); |
| 48 | + Assert.assertEquals(history.getProductId(), productId); |
| 49 | + Assert.assertEquals(history.getUserId(), userId); |
| 50 | + Assert.assertEquals(history.getTimestamp(), new Timestamp(event.getTimestamp())); |
| 51 | + |
| 52 | + } |
| 53 | + |
| 54 | +} |
0 commit comments