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

Return null in getBestStatements if there are none #432

Merged
merged 3 commits into from Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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