-
Notifications
You must be signed in to change notification settings - Fork 8
Mocking lab #14
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
Open
kaeaton
wants to merge
20
commits into
MillsMCS:mocking-base
Choose a base branch
from
kaeaton:mockingLab
base: mocking-base
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Mocking lab #14
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
1605d4d
working but needing a way to detarget words
kaeaton d284b17
button disable function working
kaeaton cbca037
Merge branch 'button' into getWord
kaeaton 587199c
add mocking for wordOfTheDay
kaeaton d1415dd
Add test for AddWordOfTheDay
kaeaton 6179d58
Extract addWordOfTheDay method
kaeaton b3f78d5
Update .gitignore
kaeaton 63311f5
Remove copy of instructions
kaeaton 201218e
working but needing a way to detarget words
kaeaton 5b8c6f2
button disable function working
kaeaton adfe2ef
add mocking for wordOfTheDay
kaeaton 031c4e9
Add test for AddWordOfTheDay
kaeaton a256237
Extract addWordOfTheDay method
kaeaton 75e275d
Update .gitignore
kaeaton d8149e3
Remove copy of instructions
kaeaton f479dca
Merge branch 'mockingLab' of github.com:kaeaton/wordui into mockingLab
kaeaton ff055ea
expand addWordOfTheDay testing
kaeaton 34a67b5
fix Javadoc, remove comments
kaeaton 23d532d
narrow Exception to IOException
kaeaton 7c111f6
add JavaDoc folder to .gitignore
kaeaton 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
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
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
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 |
|---|---|---|
|
|
@@ -42,37 +42,54 @@ private static int getFrequencyFromSummary(FrequencySummary fs, int year) { | |
| return 0; | ||
| } | ||
|
|
||
| // TODO: Move to spring-swagger-wordnik-client | ||
| @VisibleForTesting | ||
| protected static int getFrequencyByYear(WordApi wordApi, String word, int year) { | ||
| FrequencySummary fs = wordApi.getWordFrequency(word, "false", year, year); | ||
| return getFrequencyFromSummary(fs, year); | ||
| } | ||
|
|
||
| private static WordRecord buildWordRecord(String word, Map<Object, Object> definition) { | ||
| WordApi wordApi = client.buildClient(WordApi.class); | ||
| return new WordRecord( | ||
| word, | ||
| @VisibleForTesting | ||
| protected static WordOfTheDay getWordOfTheDay(WordsApi wordsApi) { | ||
| return wordsApi.getWordOfTheDay(); | ||
| } | ||
|
|
||
| /** | ||
| * Downloads the Wordnik Word of the Day and adds it to a list. | ||
| * | ||
| * @param the list to add the word to | ||
| */ | ||
| public static void addWordOfTheDay(ObservableList<WordRecord> backingList, WordsApi wordsApi, WordApi wordApi) { | ||
| WordOfTheDay word = getWordOfTheDay(wordsApi); | ||
| List<Object> definitions = word.getDefinitions(); | ||
| if (definitions != null && !definitions.isEmpty()) { | ||
| Object definition = definitions.get(0); | ||
| if (definition instanceof Map) { | ||
| @SuppressWarnings("unchecked") | ||
| Map<Object, Object> definitionAsMap = (Map<Object, Object>) definition; | ||
| backingList.add(buildWordRecord(word.getWord(), definitionAsMap, wordApi)); // pass in API | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static WordRecord buildWordRecord(String word, Map<Object, Object> definition, WordApi wordApi) { | ||
| return new WordRecord(word, | ||
| getFrequencyByYear(wordApi, word, FREQ_YEAR), | ||
| definition.get("text").toString()); | ||
| } | ||
|
|
||
| /** | ||
| * Populates the passed list with sample words and Wordnik's Word of the Day. | ||
| * | ||
| * @param the list to be populated | ||
| */ | ||
| public static void fillSampleData(ObservableList<WordRecord> backingList) { | ||
| try { | ||
| client = ApiClientHelper.getApiClient(); | ||
| WordsApi wordsApi = client.buildClient(WordsApi.class); | ||
| WordOfTheDay word = wordsApi.getWordOfTheDay(); | ||
| List<Object> definitions = word.getDefinitions(); | ||
| if (definitions != null && !definitions.isEmpty()) { | ||
| Object definition = definitions.get(0); | ||
| if (definition instanceof Map) { | ||
| @SuppressWarnings("unchecked") | ||
| Map<Object, Object> definitionAsMap = (Map<Object, Object>) definition; | ||
| backingList.add(buildWordRecord(word.getWord(), definitionAsMap)); | ||
| } | ||
| } | ||
| } catch (IOException e) { | ||
| System.err.println("Unable to get API key."); | ||
| WordApi wordApi = client.buildClient(WordApi.class); | ||
| addWordOfTheDay(backingList, wordsApi, wordApi); | ||
| } catch (IOException ex) { | ||
| System.out.println("Probably couldn't access the API client: " + ex); | ||
|
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. Write to |
||
| } | ||
|
|
||
| backingList.add(new WordRecord("buffalo", 5153, "The North American bison.")); | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.