Skip to content

Commit

Permalink
Merge pull request #432 from bennofs/fix-best-statements-none
Browse files Browse the repository at this point in the history
Return null in getBestStatements if there are none
  • Loading branch information
Tpt committed Aug 28, 2019
2 parents 77d5684 + e7bbf9e commit c87ebf4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
Expand Up @@ -99,6 +99,7 @@ public StatementGroup getBestStatements() {
bestStatements.add(statement);
}
}
if (bestStatements.size() == 0) return null;
return new StatementGroupImpl(bestStatements);
}

Expand Down
Expand Up @@ -45,7 +45,7 @@ public interface StatementGroup extends Collection<Statement> {
* These are the statements with rank {@link StatementRank::PREFERRED }
* if they exists or the one with rank {@link StatementRank::NORMAL }
*
* @return a subset of the current StatementGroup
* @return a subset of the current StatementGroup, or null if there are no best statements
*/
StatementGroup getBestStatements();

Expand Down
Expand Up @@ -44,6 +44,8 @@ public class StatementGroupTest {
Collections.emptyList(), Collections.emptyList(), subject);
private Statement statementEmptyId = new StatementImpl("", StatementRank.NORMAL, mainSnak,
Collections.emptyList(), Collections.emptyList(), subject);
private Statement statementDeprecrated = new StatementImpl("DepId", StatementRank.DEPRECATED, mainSnak,
Collections.emptyList(), Collections.emptyList(), subject);
private StatementGroup sg1 = new StatementGroupImpl(Collections.singletonList(statement1));
private StatementGroup sg2 = new StatementGroupImpl(Collections.singletonList(statement1));

Expand Down Expand Up @@ -79,6 +81,14 @@ public void getBestStatementsWithoutPreferred() {
);
}

@Test
public void getBestStatementsEmpty() {
assertNull(
new StatementGroupImpl(Collections.singletonList(statementDeprecrated)).getBestStatements()

);
}

@Test
public void propertyIsCorrect() {
assertEquals(sg1.getProperty(), property);
Expand Down

0 comments on commit c87ebf4

Please sign in to comment.