Skip to content

addWordOfTheDay()#11

Open
sarah-oreilly wants to merge 6 commits into
MillsMCS:completefrom
sarah-oreilly:clean-part2
Open

addWordOfTheDay()#11
sarah-oreilly wants to merge 6 commits into
MillsMCS:completefrom
sarah-oreilly:clean-part2

Conversation

@sarah-oreilly
Copy link
Copy Markdown

Implements addWordOfTheDay(), fixes definition mocking which previously did not use a Map.

Also removed unnecessary tracked files. Sorry about that - now that I've added a bunch of extra files to multiple pull requests, I'll make a habit of double checking!

@sarah-oreilly
Copy link
Copy Markdown
Author

@ellenspertus I'm not getting the option to add you as a reviewer here

Comment thread src/main/java/edu/mills/cs180a/wordui/model/SampleData.java
Comment thread src/main/java/edu/mills/cs180a/wordui/model/SampleData.java
* Adds the current word of the day to a given list of words.
*
* @param backingList a list to which the word of the day will be added
* @param wordsApi the API used to get today's word of the day
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Excellent. Best in class.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The parameter should be the API, per your javadoc, not the WordOfTheDay, per your implementation.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I had originally passed the API as a parameter as stated in the javadoc, but it wasn't working correctly, and I missed updating the javadoc after changing the implementation. I'll update the javadoc

@VisibleForTesting
protected static void addWordOfTheDay(List<WordRecord> backingList, WordOfTheDay word) {
List<Object> definitions = word.getDefinitions();
if(definitions != null && !definitions.isEmpty()) {
Copy link
Copy Markdown
Contributor

@ellenspertus ellenspertus Dec 18, 2020

Choose a reason for hiding this comment

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

Please put a space after reserved words (if).


/***
* Creates a list of standard sample words and their definitions along
* with the word of the day. Implements the wordnik API.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd drop the last sentence. This makes use of an API. It doesn't implement it.

return wotd;
}

private static List<Object> makeDefinitions(Map<Object,Object> definition) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Couldn't you replace this with a call to List.of()?

If you keep it, put a space after the comma (and other places you are missing a space after a comma).

}

@Test
void getDefinition_True_mockedDefinition() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd consider this a test of getWordOfTheDay() and would combine it with the preceding test.

getDefinitions() is part of the API, iirc, and not our job to test.

when(SampleData.client.buildClient(WordApi.class)).thenReturn(mockWordApi);

LinkedList<WordRecord> backingList = new LinkedList<>();
WordOfTheDay banana = SampleData.getWordOfTheDay(mockWordsApi);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this supposed to be here?

SampleData.addWordOfTheDay(backingList, banana);

assertEquals("banana", backingList.get(0).getWord().toString());
assertEquals(backingList.size(), 1);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Check the size first so you don't get an IndexOutOfBoundsError on the prior line.

Also, put the expected value first.

Comment thread src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants