Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
161 lines (137 loc) · 6.84 KB

File metadata and controls

161 lines (137 loc) · 6.84 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
158
159
160
161
/*
* Copyright (C) 2014-2015 Stichting Mapcode Foundation (http://www.mapcode.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mapcode;
import com.mapcode.Territory.AlphaCodeFormat;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
@SuppressWarnings({"OverlyBroadThrowsClause", "ProhibitedExceptionDeclared"})
public class TerritoryTest {
private static final Logger LOG = LoggerFactory.getLogger(TerritoryTest.class);
@Test(expected = UnknownTerritoryException.class)
public void emptyTerritoryCodeTest() throws Exception {
LOG.info("emptyCodeTest");
Territory.fromString("");
}
@Test
public void checkFullName() throws Exception {
LOG.info("checkFullName");
assertEquals(Territory.AAA, Territory.fromString("International"));
assertEquals(Territory.AAA, Territory.fromString("Worldwide"));
assertEquals(Territory.AAA, Territory.fromString("Earth"));
assertEquals(Territory.NLD, Territory.fromString("Netherlands"));
assertEquals(Territory.CN_XZ, Territory.fromString("Xizang"));
assertEquals(Territory.CN_XZ, Territory.fromString("Tibet"));
}
@Test
public void checkDash() throws Exception {
LOG.info("checkDash");
assertEquals(Territory.IN_MN, Territory.fromString("IND-MN"));
assertEquals(Territory.IN_MN, Territory.fromString("IND_MN"));
assertEquals(Territory.US_MN, Territory.fromString("USA-MN"));
assertEquals(Territory.US_MN, Territory.fromString("USA_MN"));
assertEquals(Territory.COD, Territory.fromString("Congo-Kinshasa"));
assertEquals(Territory.US_IN, Territory.fromString("United States of America-IN"));
assertEquals(Territory.US_IN, Territory.fromString("United States of America IN"));
}
@Test
public void disambiguateMNTest1() throws Exception {
LOG.info("disambiguateMNTest2");
final Territory territory0 = Territory.fromString("IND-MN");
final Territory territory1 = Territory.fromString("IN-MN");
final Territory territory2 = Territory.fromString("MN", Territory.IND);
final Territory territory3 = Territory.fromString("MN", Territory.USA);
assertEquals(territory0, territory1);
assertEquals(territory1, territory2);
assertNotEquals(territory2, territory3);
}
@Test(expected = UnknownTerritoryException.class)
public void disambiguateMNTest2() throws Exception {
LOG.info("disambiguateMNTest2");
Territory.fromString("MN", Territory.RUS);
}
@Test
public void testTerritoryFromString() throws Exception {
LOG.info("testTerritoryFromString");
// Accept ISO-style codes.
assertEquals(Territory.NLD, Territory.fromString("NLD"));
assertEquals(Territory.ARG, Territory.fromString("ARG"));
assertEquals(Territory.ASM, Territory.fromString("US-AS"));
assertEquals(Territory.ASM, Territory.fromString("USA-AS"));
assertEquals(Territory.RUS, Territory.fromString("RU"));
assertEquals(Territory.CHN, Territory.fromString("CN"));
assertEquals(Territory.AUS, Territory.fromString("AU"));
assertEquals(Territory.US_IN, Territory.fromString("IN"));
assertEquals(Territory.US_IN, Territory.fromString("US-IN"));
assertEquals(Territory.US_IN, Territory.fromString("USA-IN"));
assertEquals(Territory.RU_IN, Territory.fromString("RUS-IN"));
assertEquals(Territory.IN_BR, Territory.fromString("BR"));
assertEquals(Territory.IN_AS, Territory.fromString("AS"));
// Accept long and short.
assertEquals(Territory.USA, Territory.fromString("USA"));
assertEquals(Territory.USA, Territory.fromString("US"));
for (final Territory territory : Territory.values()) {
assertEquals(territory, Territory.fromString(territory.toString()));
}
}
@Test(expected = UnknownTerritoryException.class)
public void testTerritoryFromStringIncorrectDash1() throws Exception {
LOG.info("testTerritoryFromStringIncorrectDash1");
// Issue: https://github.com/mapcode-foundation/mapcode-java/issues/23
assertEquals(Territory.AAA, Territory.fromString("CHE-GR")); // Exception must be thrown.
}
@Test(expected = UnknownTerritoryException.class)
public void testTerritoryFromStringIncorrectDash2() throws Exception {
LOG.info("testTerritoryFromStringIncorrectDash2");
assertEquals(Territory.AAA, Territory.fromString("USA-NLD")); // Exception must be thrown.
}
@Test(expected = UnknownTerritoryException.class)
public void testTerritoryFromStringNumeric() throws Exception {
LOG.info("testTerritoryFromStringNumeric");
// No longer support: numeric codes.
assertEquals(Territory.AAA, Territory.fromString("0")); // Exception must be thrown.
}
@Test
public void checkAlphabet() throws Exception {
LOG.info("checkAlphabet");
assertEquals(Territory.NLD, Territory.fromString("NLD"));
assertEquals(Territory.NLD, Territory.fromString("\u039d\u039b\u0394"));
assertEquals(Territory.NLD, Territory.fromString("\u0417\u041b\u0414"));
assertEquals("NLD", Territory.NLD.toAlphaCode(AlphaCodeFormat.INTERNATIONAL));
assertEquals("NLD", Territory.NLD.toAlphaCode(AlphaCodeFormat.INTERNATIONAL, Alphabet.ROMAN));
assertEquals("\u0417\u041b\u0414", Territory.NLD.toAlphaCode(AlphaCodeFormat.INTERNATIONAL, Alphabet.CYRILLIC));
assertEquals("\u039d\u039b\u0394", Territory.NLD.toAlphaCode(AlphaCodeFormat.INTERNATIONAL, Alphabet.GREEK));
assertEquals("\u0393\u03a8\u039e", Territory.GRC.toAlphaCode(AlphaCodeFormat.INTERNATIONAL, Alphabet.GREEK));
}
@Test(expected = IllegalArgumentException.class)
public void testFromStringError1() {
LOG.info("testFromStringError1");
Territory.fromString("");
}
@Test(expected = IllegalArgumentException.class)
public void testFromStringError2() {
LOG.info("testFromStringError2");
Territory.fromString("1A");
}
@Test(expected = IllegalArgumentException.class)
public void testFromStringError3() {
LOG.info("testFromStringError3");
Territory.fromString("999");
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.