Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 96 additions & 2 deletions src/test/java/de/meggsimum/w3w/What3WordsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -104,4 +165,37 @@ public void testWhat3WordsException() {
assertTrue(thrown);
}

/**
* Tests the position -> words API wrapper with french words with accents
*/
public void testNonAsciiCharatersFR() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding some little API-doc blocks, like the other test methods have?

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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding some little API-doc blocks, like the other test methods have?

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);
}
}
}