Skip to content

Commit a50288d

Browse files
committed
Added unit tests
1 parent 8018da8 commit a50288d

File tree

3 files changed

+101
-4
lines changed

3 files changed

+101
-4
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (C) 2014-2016 Stichting Mapcode Foundation (http://www.mapcode.com)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.mapcode;
18+
19+
import org.junit.Test;
20+
import org.slf4j.Logger;
21+
import org.slf4j.LoggerFactory;
22+
23+
@SuppressWarnings({"OverlyBroadThrowsClause", "ProhibitedExceptionDeclared"})
24+
public class CheckArgsTest {
25+
private static final Logger LOG = LoggerFactory.getLogger(CheckArgsTest.class);
26+
27+
public void testCheckNonnullOK() throws Exception {
28+
LOG.info("testCheckNonnullOK");
29+
CheckArgs.checkNonnull("test", this);
30+
}
31+
32+
@Test(expected = IllegalArgumentException.class)
33+
public void testCheckNonnullError() throws Exception {
34+
LOG.info("testCheckNonnullError");
35+
CheckArgs.checkNonnull("test", null);
36+
}
37+
38+
public void testCheckDefinedOK() throws Exception {
39+
LOG.info("testCheckDefinedOK");
40+
CheckArgs.checkDefined("test", Point.fromDeg(0.0, 0.0));
41+
}
42+
43+
@Test(expected = IllegalArgumentException.class)
44+
public void testCheckDefinedError() throws Exception {
45+
LOG.info("testCheckDefinedError");
46+
CheckArgs.checkDefined("test", Point.undefined());
47+
}
48+
49+
public void testMapcodeCodeOK() throws Exception {
50+
LOG.info("testCheckMapcodeCodeOK");
51+
CheckArgs.checkMapcodeCode("test", "XX.XX");
52+
}
53+
54+
@Test(expected = IllegalArgumentException.class)
55+
public void testMapcodeCodeError() throws Exception {
56+
LOG.info("testCheckMapcodeCodeError");
57+
CheckArgs.checkMapcodeCode("test", "XX.XX-");
58+
}
59+
}

src/test/java/com/mapcode/EncoderTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,35 @@
2121
import org.slf4j.LoggerFactory;
2222

2323
import java.util.List;
24+
import java.util.Map;
2425

2526
import static org.junit.Assert.assertEquals;
27+
import static org.junit.Assert.assertFalse;
28+
import static org.junit.Assert.assertTrue;
2629

2730
@SuppressWarnings({"OverlyBroadThrowsClause", "ProhibitedExceptionDeclared", "ValueOfIncrementOrDecrementUsed"})
2831
public class EncoderTest {
2932
private static final Logger LOG = LoggerFactory.getLogger(EncoderTest.class);
3033

34+
@Test
35+
public void encodePoint() {
36+
LOG.info("encodeMostResults");
37+
assertEquals(MapcodeCodec.encode(52.5, 5.2), MapcodeCodec.encode(Point.fromDeg(52.5, 5.2)));
38+
}
39+
40+
@Test
41+
public void encodeToInterInternationalnational() {
42+
LOG.info("encodeToInternational");
43+
assertEquals("VHYCC.2FWB", MapcodeCodec.encodeToInternational(52.5, 5.2).getCode());
44+
assertEquals("VHYCC.2FWB", MapcodeCodec.encodeToInternational(Point.fromDeg(52.5, 5.2)).getCode());
45+
}
46+
47+
@Test
48+
public void nearMultipleBorders() {
49+
LOG.info("nearMultipleBorders");
50+
assertFalse(MapcodeCodec.isNearMultipleBorders(Point.fromDeg(52.175616, 4.577179), Territory.NLD));
51+
}
52+
3153
@Test
3254
public void encodeMostResults() {
3355
LOG.info("encodeMostResults");

src/test/java/com/mapcode/TerritoryTest.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.mapcode;
1818

1919
import com.mapcode.Territory.AlphaCodeFormat;
20-
import org.junit.Ignore;
2120
import org.junit.Test;
2221
import org.slf4j.Logger;
2322
import org.slf4j.LoggerFactory;
@@ -141,21 +140,38 @@ public void checkAlphabet() throws Exception {
141140
assertEquals("\u0393\u03a8\u039e", Territory.GRC.toAlphaCode(AlphaCodeFormat.INTERNATIONAL, Alphabet.GREEK));
142141
}
143142

144-
@Test(expected = IllegalArgumentException.class)
143+
@Test(expected = UnknownTerritoryException.class)
145144
public void testFromStringError1() {
146145
LOG.info("testFromStringError1");
147146
Territory.fromString("");
148147
}
149148

150-
@Test(expected = IllegalArgumentException.class)
149+
@Test(expected = UnknownTerritoryException.class)
151150
public void testFromStringError2() {
152151
LOG.info("testFromStringError2");
153152
Territory.fromString("1A");
154153
}
155154

156-
@Test(expected = IllegalArgumentException.class)
155+
@Test(expected = UnknownTerritoryException.class)
157156
public void testFromStringError3() {
158157
LOG.info("testFromStringError3");
159158
Territory.fromString("999");
160159
}
160+
161+
public void testFromNumberOK() {
162+
LOG.info("testFromNumberOK");
163+
Territory.fromNumber(0);
164+
}
165+
166+
@Test(expected = UnknownTerritoryException.class)
167+
public void testFromNumberError1() {
168+
LOG.info("testFromNumberError1");
169+
Territory.fromNumber(-1);
170+
}
171+
172+
@Test(expected = UnknownTerritoryException.class)
173+
public void testFromNumberError2() {
174+
LOG.info("testFromNumberError2");
175+
Territory.fromNumber(99999);
176+
}
161177
}

0 commit comments

Comments
 (0)