Skip to content

Commit e575140

Browse files
authored
Merge pull request #312 from TreeBASE/copilot/fix-test-empty-database
Fix testFindMatricesByTaxonLabel failure with empty database
2 parents bac251f + ddde71f commit e575140

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

treebase-core/src/main/java/org/cipres/treebase/dao/taxon/TaxonLabelDAO.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,11 @@ public Set<Study> findStudies(TaxonVariant taxonVariant) {
244244

245245
// TODO: This is way too slow. mjd 20080911
246246
public Collection<Matrix> findMatricesWithTaxonLabels(Collection<TaxonLabel> taxonLabels) {
247+
// Return empty collection if input is null or empty to avoid invalid HQL query
248+
if (taxonLabels == null || taxonLabels.isEmpty()) {
249+
return new ArrayList<Matrix>();
250+
}
251+
247252
Query q = getSession().createQuery("select distinct mr.matrix from MatrixRow mr where mr.taxonLabel in (:tl)");
248253
q.setParameterList("tl", taxonLabels);
249254
List<Matrix> results = q.list();

treebase-core/src/test/java/org/cipres/treebase/domain/taxon/TaxonLabelTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,15 @@ public void testFindStudies() {
8282
}
8383

8484
public void testFindMatricesByTaxonLabel() {
85-
Collection<Matrix> res = getTaxonLabelHome().findMatricesWithTaxonLabels(findHomoSapiensTL());
85+
Collection<TaxonLabel> homoTL = findHomoSapiensTL();
86+
87+
// Skip test if database is empty
88+
if (homoTL == null || homoTL.isEmpty()) {
89+
LOGGER.info("SKIPPED: testFindMatricesByTaxonLabel - No TaxonLabel data found in database. Test requires populated database.");
90+
return;
91+
}
92+
93+
Collection<Matrix> res = getTaxonLabelHome().findMatricesWithTaxonLabels(homoTL);
8694
assertNotNull(res);
8795
LOGGER.info("Homo matrices: " + res.size() + " result(s)");
8896
assertTrue(res.size() != 0);

0 commit comments

Comments
 (0)