This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
/
StatisticsServiceTest.java
61 lines (52 loc) · 2.15 KB
/
StatisticsServiceTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package org.zanata.rest.editor.service;
import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.Response;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.zanata.common.LocaleId;
import org.zanata.common.TransUnitCount;
import org.zanata.common.TransUnitWords;
import org.zanata.dao.DocumentDAO;
import org.zanata.model.HDocument;
import org.zanata.rest.dto.stats.ContainerTranslationStatistics;
import org.zanata.rest.dto.stats.TranslationStatistics;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
public class StatisticsServiceTest {
private StatisticsService service;
@Mock
private DocumentDAO documentDAO;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
service = new StatisticsService(documentDAO);
}
@Test
public void getDocumentStatisticsWillReturnNotFoundIfDocumentNotFound() {
when(documentDAO.getByProjectIterationAndDocId("a", "1", "authors"))
.thenReturn(null);
Response response =
service.getDocumentStatistics("a", "1", "authors", "de");
assertThat(response.getStatus()).isEqualTo(404);
}
@Test
public void getDocumentStatisticsWillReturnResult() {
HDocument document = new HDocument();
document.setId(1L);
when(documentDAO.getByProjectIterationAndDocId("a", "1", "authors"))
.thenReturn(document);
ContainerTranslationStatistics statistics =
new ContainerTranslationStatistics();
statistics.addStats(new TranslationStatistics(new TransUnitWords(10, 0,
0, 10, 0), "de"));
statistics.addStats(new TranslationStatistics(new TransUnitCount(5, 0,
0, 10, 0), "de"));
when(documentDAO.getStatistics(1L, LocaleId.DE)).thenReturn(statistics);
Response response =
service.getDocumentStatistics("a", "1", "authors", "de");
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getEntity()).isInstanceOf(GenericEntity.class);
}
}