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
/
ComparatorUtilTest.java
157 lines (137 loc) · 6.6 KB
/
ComparatorUtilTest.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* Copyright 2014, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/
package org.zanata.util;
import org.junit.Test;
import org.zanata.common.LocaleId;
import org.zanata.common.ProjectType;
import org.zanata.model.*;
import java.util.Date;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Damian Jansen
* <a href="mailto:djansen@redhat.com">djansen@redhat.com</a>
*/
public class ComparatorUtilTest {
@Test
public void HLocaleNameCompare() throws Exception {
HLocale hLocale1 = new HLocale();
hLocale1.setLocaleId(new LocaleId("alpha"));
HLocale hLocale2 = new HLocale();
hLocale2.setLocaleId(new LocaleId("bravo"));
assertThat(ComparatorUtil.LOCALE_COMPARATOR
.compare(hLocale1, hLocale1)).isEqualTo(0);
assertThat(ComparatorUtil.LOCALE_COMPARATOR
.compare(hLocale2, hLocale1)).isGreaterThan(0);
assertThat(ComparatorUtil.LOCALE_COMPARATOR
.compare(hLocale1, hLocale2)).isLessThan(0);
}
@Test
public void HPersonNameCompare() throws Exception {
HPerson hPerson1 = new HPerson();
hPerson1.setName("alpha");
HPerson hPerson2 = new HPerson();
hPerson2.setName("bravo");
assertThat(ComparatorUtil.PERSON_NAME_COMPARATOR
.compare(hPerson1, hPerson1)).isEqualTo(0);
assertThat(ComparatorUtil.PERSON_NAME_COMPARATOR
.compare(hPerson2, hPerson1)).isGreaterThan(0);
assertThat(ComparatorUtil.PERSON_NAME_COMPARATOR
.compare(hPerson1, hPerson2)).isLessThan(0);
}
@Test
public void HProjectDateCompare() throws Exception {
HProject hProject1 = new HProject();
hProject1.setCreationDate(new Date(10));
HProject hProject2 = new HProject();
hProject2.setCreationDate(new Date(1));
assertThat(ComparatorUtil.PROJECT_CREATION_DATE_COMPARATOR
.compare(hProject2, hProject1)).isEqualTo(1);
assertThat(ComparatorUtil.PROJECT_CREATION_DATE_COMPARATOR
.compare(hProject1, hProject2)).isEqualTo(-1);
assertThat(ComparatorUtil.PROJECT_CREATION_DATE_COMPARATOR
.compare(hProject1, hProject1)).isEqualTo(0);
}
@Test
public void HProjectIterationProjectNameCompare() throws Exception {
HProject hProject1 = new HProject();
hProject1.setName("alpha");
HProject hProject2 = new HProject();
hProject2.setName("bravo");
HProject hProject3 = new HProject();
hProject3.setName("BRAVO");
HProjectIteration hProjectIteration1 = new HProjectIteration();
hProjectIteration1.setProject(hProject1);
HProjectIteration hProjectIteration2 = new HProjectIteration();
hProjectIteration2.setProject(hProject2);
HProjectIteration hProjectIteration3 = new HProjectIteration();
hProjectIteration3.setProject(hProject3);
assertThat(ComparatorUtil.VERSION_PROJECT_NAME_COMPARATOR
.compare(hProjectIteration1, hProjectIteration1)).isEqualTo(0);
assertThat(ComparatorUtil.VERSION_PROJECT_NAME_COMPARATOR
.compare(hProjectIteration2, hProjectIteration3)).isEqualTo(0);
assertThat(ComparatorUtil.VERSION_PROJECT_NAME_COMPARATOR
.compare(hProjectIteration1, hProjectIteration3)).isEqualTo(-1);
assertThat(ComparatorUtil.VERSION_PROJECT_NAME_COMPARATOR
.compare(hProjectIteration3, hProjectIteration1)).isEqualTo(1);
}
@Test
public void HProjectIterationDateCompare() throws Exception {
HProjectIteration hProjectIteration1 = new HProjectIteration();
hProjectIteration1.setCreationDate(new Date(10));
HProjectIteration hProjectIteration2 = new HProjectIteration();
hProjectIteration2.setCreationDate(new Date(1));
assertThat(ComparatorUtil.VERSION_CREATION_DATE_COMPARATOR
.compare(hProjectIteration1, hProjectIteration1)).isEqualTo(0);
assertThat(ComparatorUtil.VERSION_CREATION_DATE_COMPARATOR
.compare(hProjectIteration1, hProjectIteration2)).isEqualTo(-1);
assertThat(ComparatorUtil.VERSION_CREATION_DATE_COMPARATOR
.compare(hProjectIteration2, hProjectIteration1)).isEqualTo(1);
}
@Test
public void HAccountRoleCompare() throws Exception {
HAccountRole hAccountRole1 = new HAccountRole();
hAccountRole1.setName("alpha");
HAccountRole hAccountRole2 = new HAccountRole();
hAccountRole2.setName("bravo");
assertThat(ComparatorUtil.ACCOUNT_ROLE_COMPARATOR
.compare(hAccountRole1, hAccountRole2)).isEqualTo(-1);
assertThat(ComparatorUtil.ACCOUNT_ROLE_COMPARATOR
.compare(hAccountRole2, hAccountRole1)).isEqualTo(1);
assertThat(ComparatorUtil.ACCOUNT_ROLE_COMPARATOR
.compare(hAccountRole1, hAccountRole1)).isEqualTo(0);
}
@Test
public void ProjectTypeCompare() throws Exception {
ProjectType projectType1 = ProjectType.File;
ProjectType projectType2 = ProjectType.Gettext;
ProjectType projectType3 = null;
assertThat(ComparatorUtil.PROJECT_TYPE_COMPARATOR
.compare(projectType1, projectType1)).isEqualTo(0);
assertThat(ComparatorUtil.PROJECT_TYPE_COMPARATOR
.compare(projectType1, projectType2)).isEqualTo(-1);
assertThat(ComparatorUtil.PROJECT_TYPE_COMPARATOR
.compare(projectType2, projectType1)).isEqualTo(1);
assertThat(ComparatorUtil.PROJECT_TYPE_COMPARATOR
.compare(projectType1, projectType3)).isEqualTo(1);
assertThat(ComparatorUtil.PROJECT_TYPE_COMPARATOR
.compare(projectType3, projectType1)).isEqualTo(-1);
}
}