Skip to content

Mock api#9

Open
moketa99 wants to merge 9 commits into
MillsMCS:mockingfrom
moketa99:MockApi
Open

Mock api#9
moketa99 wants to merge 9 commits into
MillsMCS:mockingfrom
moketa99:MockApi

Conversation

@moketa99
Copy link
Copy Markdown

@moketa99 moketa99 commented Dec 7, 2020

Mocking Lab

Would you please point out if I misunderstand the instructions?

@ellenspertus ellenspertus changed the base branch from complete to mocking December 7, 2020 20:33
Copy link
Copy Markdown
Contributor

@ellenspertus ellenspertus left a comment

Choose a reason for hiding this comment

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

I'd be happy to meet and discuss.

private void populateChoiceBox() {
sortChoiceBox.setItems(FXCollections.observableArrayList(
WordRecord.SortOrder.values()));
sortChoiceBox.setItems(FXCollections.observableArrayList(WordRecord.SortOrder.values()));
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 changes to this file are all due to formatting. You should keep this type of change out of PRs. The best way to do so it to look at your PR on GitHub before submitting it.

* Create sample data to display on the list in JavaFX.
*
* @author Ellen Spertus
* @author Makie Maekawa
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! I didn't even ask for people to add class-level javadoc. I should have.

protected static final int FREQ_YEAR = 2012;
private static ApiClient client; // set in fillSampleData()

@VisibleForTesting
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.

Reordering the code made it harder to review.

getFrequencyByYear(wordApi, word, FREQ_YEAR),
definition.get("text").toString());
@VisibleForTesting
public static String getWord(WordsApi WordsApi) {
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.

You should never have a variable name with the same name as a type. I'm surprised that Java allows this. Also, argument names should be lowerCamelCase.

getFrequencyByYear(wordApi, word, FREQ_YEAR),
definition.get("text").toString());
@VisibleForTesting
public static String getWord(WordsApi WordsApi) {
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.

You don't need this method. Instead, call a method in WordOfTheDay.

assertEquals(count, getFrequencyByYear(mockWordApi, word, year));
}

private static WordOfTheDay makeWordOfTheDay(String word, List<Object> defin) {
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.

It might be clear to make the second argument a String and for this method to call makeMapDefin. That makes things easier for this method's caller and improves abstraction.

getWordOfTheDay(mockWordsApi).getDefinitions().get(0));
}

@SuppressWarnings("static-access")
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.

Rather than suppressing warnings, you should deal with the underlying issue, which I'm happy to discuss.

@SuppressWarnings("static-access")
@Test
void addWordOfTheDay_Equal_correctValue() {
SampleData sd = mock(SampleData.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.

There is no need to mock the class.

@Test
void addWordOfTheDay_Equal_correctValue() {
SampleData sd = mock(SampleData.class);
when(sd.getWordOfTheDay(mockWordsApi).getDefinitions()).thenReturn(DIFINITION_MAP);
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.

You should not mock within the test.

sd.getWordOfTheDay(mockWordsApi).getWord(), FREQ_YEAR),
definitionAsMap.get("text").toString());

assertTrue(MOCK_WORDRECORD.getWord().equals(testWordRecord.getWord())
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.

You should have a series of assertEquals() statements. Those would give better error messages than a single assertTrue().

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