Skip to content

Commit 8363464

Browse files
committed
stream-reader generator test
1 parent e8532a0 commit 8363464

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

stream-reader/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@
5050
<artifactId>spring-kafka-test</artifactId>
5151
<scope>test</scope>
5252
</dependency>
53+
<dependency>
54+
<groupId>org.junit.vintage</groupId>
55+
<artifactId>junit-vintage-engine</artifactId>
56+
<scope>test</scope>
57+
<exclusions>
58+
<exclusion>
59+
<groupId>org.hamcrest</groupId>
60+
<artifactId>hamcrest-core</artifactId>
61+
</exclusion>
62+
</exclusions>
63+
</dependency>
5364
</dependencies>
5465

5566
<build>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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

Comments
 (0)