-
Notifications
You must be signed in to change notification settings - Fork 34
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
#183 - Raise test coverage of 'Category' (api) class to at least 75% (line & branch) #184
Conversation
…(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).
@@ -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() { |
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.
Is there a specific reason to downgrade this from public to the default scope?
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.
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.
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.
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.
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.
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() { |
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.
Is there a specific reason to downgrade this from public to the default scope?
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.
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() |
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.
Is there a specific reason to downgrade this from public to the default scope?
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.
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() |
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.
Is there a specific reason to downgrade this from protected to the default scope?
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.
see other comment on this topic.
@@ -17,21 +17,24 @@ | |||
*******************************************************************************/ | |||
package de.tudarmstadt.ukp.wikipedia.api; | |||
|
|||
import static org.junit.Assert.assertEquals; |
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.
Please avoid star imports ;)
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.
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.*; |
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.
Please avoid star imports ;)
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.
will be fixed with next commit.
isIds.add(sibling.getPageId()); | ||
} | ||
assertEquals("siblings",expectedPageIds,isIds); | ||
} catch (WikiApiException e) { |
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.
General comment: there is no need to catch exceptions and handle them by failing explicitly. Just make the unit test method declare throws Exception
.
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.
see other comment on Exceptions/Tests.
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; |
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.
Please avoid star imports ;) (I'm not going to make more of these line comments - it is a general comment).
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.
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()); |
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.
Just throw the exception, even in setup methods.
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.
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); |
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.
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.
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.
That's a good pointer. Will look into it, yet again: separate issue/PR for these enhancements.
Note: the coverage information for master now gets properly reported :) |
That looks pretty fine now and is more helpful than before, indeed. |
…se-coverage-of-Category-above-75 * Conflicts: * de.tudarmstadt.ukp.wikipedia.api/src/test/resources/db/wikiapi_test.script
CategoryTest
which lifts the coverage for class Page to98% (line), 86% (branch) -> checked via JaCoCo report of API testsuite run.
CategoryTitleComparator
andPageTitleComparator
.MetaDataTest
class with 89% line coverage.Set<Page> getPages()
fromCategory
class as nobody used it any way.Category
.Category
: getArticleIds() vs. __getPages().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.