Skip to content

Commit

Permalink
#2213 Test erroneous union queries with different numbers of yields
Browse files Browse the repository at this point in the history
In general, this approach of asserting that an exception is thrown is
far from the best because it ignores potential exceptions that may be
thrown for unexpected reasons. Being more specific and expecting only a
certain type of exceptions doesn't work either since the exception gets
rethrown at some higher level, effectively becoming a cause of another
exception. Should we be making assertions about the stack trace at this
point? I don't think so.
  • Loading branch information
homedirectory committed Apr 8, 2024
1 parent 8a073a1 commit e9c8823
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static org.junit.Assert.*;
import static ua.com.fielden.platform.entity.query.fluent.EntityQueryUtils.*;
import static ua.com.fielden.platform.test_utils.TestUtils.assertNotThrows;
import static ua.com.fielden.platform.test_utils.TestUtils.assertThrows;

public class EntityQuery3ExecutionTest extends AbstractDaoTestCase {
private final IEntityAggregatesOperations aggregateDao = getInstance(IEntityAggregatesOperations.class);
Expand Down Expand Up @@ -1105,6 +1106,15 @@ public void nonNulls_can_be_compared_to_nonNulls_in_join_conditions() {
final List<EntityAggregates> entities = co(EntityAggregates.class).getAllEntities(from(query).model());
}

@Test
public void union_of_queries_with_different_numbers_of_yields_fails() {
final var q1 = select().yield().val(200).as("x").modelAsAggregate();
final var q2 = select().yield().val(100).as("x").yield().val(300).as("y").modelAsAggregate();
final var union = select(q1, q2).yieldAll().modelAsAggregate();

assertThrows(() -> co(EntityAggregates.class).getAllEntities(from(union).model()));
}

@Override
public boolean saveDataPopulationScriptToFile() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,14 @@ public static void assertNotThrows(final ThrowingRunnable runnable) {
}
}

public static void assertThrows(final ThrowingRunnable runnable) {
try {
runnable.run();
} catch (final Throwable $) {
return;
}

fail("Expected an exception to be thrown but nothing was thrown.");
}

}

0 comments on commit e9c8823

Please sign in to comment.