-
Notifications
You must be signed in to change notification settings - Fork 4
Improve coverage #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?