Skip to content
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

#183 - Raise test coverage of 'Category' (api) class to at least 75% (line & branch) #184

Merged
merged 4 commits into from
Jul 17, 2018

Conversation

mawiesne
Copy link
Contributor

  • Adds several test cases in CategoryTest which lifts the coverage for class Page to
    98% (line), 86% (branch) -> checked via JaCoCo report of API testsuite run.
  • Adds test cases for CategoryTitleComparator and PageTitleComparator.
  • Bonus: Adds new MetaDataTest class with 89% line coverage.
  • Removes deprecated method Set<Page> getPages() from Category class as nobody used it any way.
  • Removes dead code (commented and unused/untested) from Category.
  • Reduces code duplication in Category: getArticleIds() vs. __getPages().
  • Improves some JavaDoc here and there.
  • Fixes several misspellings throughout the whole code base of the term occured which should read as occurred (double r).

This addition of tests helps us to sleep well when things get changed in core parts of the API.

Please review and merge this PR.

…(line & branch)

- Adds several test cases in `CategoryTest` which lifts the coverage for class Page to
 98% (line), 86% (branch) -> checked via JaCoCo report of API testsuite run.
- Adds test cases for `CategoryTitleComparator` and `CategoryTitleComparator`.
- Bonus: Adds new `MetaDataTest` class with 89% line coverage.
- Removes deprecated method `Set<Page> getPages()` from `Category` class as nobody used it any way.
- Removes dead code (commented and unused/untested) from `Category`
- Reduces code duplication in `Category`: getArticleIds() vs. __getPages()
- Improves some JavaDoc here and there
- Fixes several misspellings throughout the whole code base of the term _occured_ which should read as _occurred (double r).
@mawiesne mawiesne added this to the 1.2.0 milestone Jul 16, 2018
@mawiesne mawiesne self-assigned this Jul 16, 2018
@mawiesne mawiesne requested review from reckart and daxenberger July 16, 2018 18:35
@ukp-svc-jenkins
Copy link

22% (+22.04%) vs master 0%

@@ -134,7 +134,7 @@ private void createCategory(Title title) throws WikiPageNotFoundException {
* This returns the internal id. Do not confuse this with the pageId.
* @return Returns the internal id.
*/
public long __getId() {
long __getId() {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a specific reason to downgrade this from public to the default scope?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a reason behind this:
I consider the internal, Hibernate/DB specific ID as an internal detail of the DB-access layer. Thus, it should not be exposed to other parts of the application, i.e. no code should rely on accessing the internal database object identifier / primary key. There are other stable data-identifying IDs, such as pageId. This idea follows the principle of information hiding.

Therefore, I lowered the visibility from public and/or protected to package private. With all code compiling and all tests passing, I'm confident that nothing will break or suffer from "pain" related to that architectural change.

Copy link
Member

Choose a reason for hiding this comment

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

Personally, I'm not very used to using package private things. I have sometimes tried using it to make methods accessible for testing, but very rarely. So I understand the concept of information hiding, but haven't found package private to be very useful for me. Which doesn't mean that it is not useful.

On the other hand, I have seen people often to simple forget to put visibility markers. Unfortunately, Java does not have an explicit marker for package private. I would suggest to put a line comment there if package private is being used intentionally and explain the rationale (e.g. framework-internal use) or maybe even to introduce a custom annotation like @Internal just to make the intention explicit and to avoid future developers to think that the modifier has simply been forgotten.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I will leave a comment on the respective pieces of code and push that with the next commit.

Set<Integer> tmpSet = new HashSet<Integer>(hibernateCategory.getPages());
session.getTransaction().commit();
return tmpSet;
Set<Integer> __getPages() {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a specific reason to downgrade this from public to the default scope?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case the reasons is:
No piece of code from "external" packages used it, merely internal consumers. Moreover the "__" in front of getPages() indicates the internal use, I guess.

If there is a necessity to change it back, I can do that. Otherwise I suggest to leave it like that, as it is "internal" API here.

*/
public long getId()
long getId()
Copy link
Member

Choose a reason for hiding this comment

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

Is there a specific reason to downgrade this from public to the default scope?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see other comment on this topic.

@@ -244,19 +244,17 @@ private void fetchByTitle(Title pTitle, boolean useExactTitle)
/**
* @return Returns the id.
*/
protected long __getId()
long __getId()
Copy link
Member

Choose a reason for hiding this comment

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

Is there a specific reason to downgrade this from protected to the default scope?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see other comment on this topic.

@@ -17,21 +17,24 @@
*******************************************************************************/
package de.tudarmstadt.ukp.wikipedia.api;

import static org.junit.Assert.assertEquals;
Copy link
Member

Choose a reason for hiding this comment

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

Please avoid star imports ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see a * import at this line here, as the comment is on a deletion of a line.

import org.junit.BeforeClass;
import org.junit.Test;

import de.tudarmstadt.ukp.wikipedia.api.exception.WikiApiException;
import de.tudarmstadt.ukp.wikipedia.api.exception.WikiTitleParsingException;

import static org.junit.Assert.*;
Copy link
Member

Choose a reason for hiding this comment

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

Please avoid star imports ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will be fixed with next commit.

isIds.add(sibling.getPageId());
}
assertEquals("siblings",expectedPageIds,isIds);
} catch (WikiApiException e) {
Copy link
Member

Choose a reason for hiding this comment

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

General comment: there is no need to catch exceptions and handle them by failing explicitly. Just make the unit test method declare throws Exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see other comment on Exceptions/Tests.

import org.junit.BeforeClass;
import org.junit.Test;

import static org.junit.Assert.*;
Copy link
Member

Choose a reason for hiding this comment

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

Please avoid star imports ;) (I'm not going to make more of these line comments - it is a general comment).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Will keep an eye on it in future commits. IDE had an option on which automatically optimized imports like this.

try {
wiki = new Wikipedia(db);
} catch (Exception e) {
fail("Wikipedia could not be initialized: " + e.getLocalizedMessage());
Copy link
Member

Choose a reason for hiding this comment

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

Just throw the exception, even in setup methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't change it in this PR, as this needs a separate issue that only reflects this particular concern.

@Test
public void testGetNumberOfPages() {
long numberOfPages = metaData.getNumberOfPages();
assertTrue(numberOfPages > 0);
Copy link
Member

Choose a reason for hiding this comment

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

Another general comment: You might want to take a look at assertj - I was recently introduced to it myself and find that after an initial learning curve, it really facilitates writing tests and reduces the number of asserts - or said differently - its asserts are more powerful and comprehensive checking more stuff with a single assert than the ones provided by JUnit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good pointer. Will look into it, yet again: separate issue/PR for these enhancements.

@ukp-svc-jenkins
Copy link

22% (+1.0%) vs master 21%

@reckart
Copy link
Member

reckart commented Jul 17, 2018

Note: the coverage information for master now gets properly reported :)

@mawiesne
Copy link
Contributor Author

That looks pretty fine now and is more helpful than before, indeed.

mawiesne and others added 2 commits July 17, 2018 14:15
…se-coverage-of-Category-above-75

* Conflicts:
*	de.tudarmstadt.ukp.wikipedia.api/src/test/resources/db/wikiapi_test.script
@ukp-svc-jenkins
Copy link

23% (+1.01%) vs master 22%

@ukp-svc-jenkins
Copy link

23% (+1.28%) vs master 22%

@mawiesne mawiesne merged commit a6b26da into master Jul 17, 2018
@mawiesne mawiesne deleted the enhancement/183-raise-coverage-of-Category-above-75 branch July 17, 2018 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants