diff --git a/src/test/java/de/meggsimum/w3w/What3WordsTest.java b/src/test/java/de/meggsimum/w3w/What3WordsTest.java index c22beae..61f0a28 100644 --- a/src/test/java/de/meggsimum/w3w/What3WordsTest.java +++ b/src/test/java/de/meggsimum/w3w/What3WordsTest.java @@ -6,11 +6,11 @@ /** * Unit test for {@linkplain What3Words} - * + * * @author Christian Mayer, meggsimum */ public class What3WordsTest extends TestCase { - + /** * Ensure to set your API-Key here before running the test suite */ @@ -50,6 +50,40 @@ public void testWordsToPosition() { } } + /** + * Tests wrong words -> position API wrapper + */ + public void testWrongWordsToPosition() { + What3Words w3w = new What3Words(API_KEY); + String[] words = {"aa", "aa", "aa"}; + boolean thrown = false; + try { + w3w.wordsToPosition(words); + } catch (Exception e) { + thrown = true; + assertEquals("Error returned from w3w API: String not recognised", + e.getCause().getMessage()); + } + assertTrue(thrown); + } + + /** + * Tests the words -> position API wrapper + */ + public void testWordsWithLangToPosition() { + What3Words w3w = new What3Words(API_KEY, "fr"); + String[] words = {"goldfish", "fuzzy", "aggregates"}; + double[] coords; + try { + coords = w3w.wordsToPosition(words, "en"); + assertEquals(2, coords.length); + assertEquals(49.422636, coords[0]); + assertEquals(8.320833, coords[1]); + } catch (Exception e) { + assertTrue(false); + } + } + /** * Tests the position -> words API wrapper */ @@ -68,6 +102,24 @@ public void testPositionToWords() { } } + /** + * Tests the position with a different language-> words API wrapper + */ + public void testPositionToFrenchWords() { + What3Words w3w = new What3Words(API_KEY); + double[] coords = {49.422636, 8.320833}; + String[] words; + try { + words = w3w.positionToWords(coords, "fr"); + assertEquals(3, words.length); + assertEquals("besacier", words[0]); + assertEquals("trimer", words[1]); + assertEquals("effectuer", words[2]); + } catch (Exception e) { + assertTrue(false); + } + } + /** * Tests the position -> words API wrapper after changing the language */ @@ -87,6 +139,15 @@ public void testChangeLang() { } } + /** + * Tests getLanguage method + */ + public void testGetLanguage() { + What3Words w3w = new What3Words(API_KEY); + String defaultLanguage = w3w.getLanguage(); + assertEquals(defaultLanguage, "en"); + } + /** * Test for exception in case of an invalid API-key */ @@ -104,4 +165,37 @@ public void testWhat3WordsException() { assertTrue(thrown); } + /** + * Tests the position -> words API wrapper with french words with accents + */ + public void testNonAsciiCharatersFR() { + What3Words w3w = new What3Words(API_KEY, "fr"); + String[] words = {"noël", "étain", "rizière"}; + double[] coords; + try { + coords = w3w.wordsToPosition(words); + assertEquals(2, coords.length); + assertEquals(-21.951124, coords[0]); + assertEquals(166.685219, coords[1]); + } catch (Exception e) { + assertTrue(false); + } + } + + /** + * Tests the position -> words API wrapper with german words with accents + */ + public void testNonAsciiCharactersDE() { + What3Words w3w = new What3Words(API_KEY, "de"); + String[] words = {"winkel", "artenschutz", "fängen"}; + double[] coords; + try { + coords = w3w.wordsToPosition(words); + assertEquals(2, coords.length); + assertEquals(49.423903, coords[0]); + assertEquals(8.282732, coords[1]); + } catch (Exception e) { + assertTrue(false); + } + } }