Skip to content

Commit

Permalink
Remove usage of @test with exceptions in metadata tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Damans227 authored and ebyhr committed Oct 8, 2021
1 parent a2bc080 commit 6c7d4d8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void testExactMatchBeforeCoercion()
assertTrue(foundOperator);
}

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "\\QFunction already registered: custom_add(bigint,bigint):bigint\\E")
@Test
public void testDuplicateFunctions()
{
List<SqlFunction> functions = new FunctionListBuilder()
Expand All @@ -101,17 +101,21 @@ public void testDuplicateFunctions()

Metadata metadata = createTestMetadataManager();
metadata.addFunctions(functions);
metadata.addFunctions(functions);
assertThatThrownBy(() -> metadata.addFunctions(functions))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageMatching("\\QFunction already registered: custom_add(bigint,bigint):bigint\\E");
}

@Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "'sum' is both an aggregation and a scalar function")
@Test
public void testConflictingScalarAggregation()
{
List<SqlFunction> functions = new FunctionListBuilder()
.scalars(ScalarSum.class)
.getFunctions();

createTestMetadataManager().addFunctions(functions);
assertThatThrownBy(() -> createTestMetadataManager().addFunctions(functions))
.isInstanceOf(IllegalStateException.class)
.hasMessage("'sum' is both an aggregation and a scalar function");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import static io.trino.spi.type.VarcharType.VARCHAR;
import static io.trino.spi.type.VarcharType.createVarcharType;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
Expand Down Expand Up @@ -275,31 +276,35 @@ public void testSetsHiddenToTrueForOperators()
function.specialize(functionBinding, new FunctionDependencies(METADATA, ImmutableMap.of(), ImmutableSet.of()));
}

@Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "method foo was not found in class io.trino.metadata.TestPolymorphicScalarFunction\\$TestMethods")
@Test
public void testFailIfNotAllMethodsPresent()
{
new PolymorphicScalarFunctionBuilder(TestMethods.class)
assertThatThrownBy(() -> new PolymorphicScalarFunctionBuilder(TestMethods.class)
.signature(SIGNATURE)
.deterministic(true)
.choice(choice -> choice
.implementation(methodsGroup -> methodsGroup.methods("bigintToBigintReturnExtraParameter"))
.implementation(methodsGroup -> methodsGroup.methods("foo")))
.build();
.build())
.isInstanceOf(IllegalStateException.class)
.hasMessageMatching("method foo was not found in class io.trino.metadata.TestPolymorphicScalarFunction\\$TestMethods");
}

@Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "methods must be selected first")
@Test
public void testFailNoMethodsAreSelectedWhenExtraParametersFunctionIsSet()
{
new PolymorphicScalarFunctionBuilder(TestMethods.class)
assertThatThrownBy(() -> new PolymorphicScalarFunctionBuilder(TestMethods.class)
.signature(SIGNATURE)
.deterministic(true)
.choice(choice -> choice
.implementation(methodsGroup -> methodsGroup
.withExtraParameters(context -> ImmutableList.of(42))))
.build();
.build())
.isInstanceOf(IllegalStateException.class)
.hasMessageMatching("methods must be selected first");
}

@Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "two matching methods \\(varcharToBigintReturnFirstExtraParameter and varcharToBigintReturnExtraParameter\\) for parameter types \\[varchar\\(10\\)\\]")
@Test
public void testFailIfTwoMethodsWithSameArguments()
{
SqlScalarFunction function = new PolymorphicScalarFunctionBuilder(TestMethods.class)
Expand All @@ -315,7 +320,10 @@ public void testFailIfTwoMethodsWithSameArguments()
BOUND_SIGNATURE,
VARCHAR_TYPE_VARIABLES,
VARCHAR_LONG_VARIABLES);
function.specialize(functionBinding, new FunctionDependencies(METADATA, ImmutableMap.of(), ImmutableSet.of()));

assertThatThrownBy(() -> function.specialize(functionBinding, new FunctionDependencies(METADATA, ImmutableMap.of(), ImmutableSet.of())))
.isInstanceOf(IllegalStateException.class)
.hasMessageMatching("two matching methods \\(varcharToBigintReturnFirstExtraParameter and varcharToBigintReturnExtraParameter\\) for parameter types \\[varchar\\(10\\)\\]");
}

public static final class TestMethods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public void testBindDifferentLiteralParameters()
.fails();
}

@Test(expectedExceptions = UnsupportedOperationException.class)
@Test
public void testNoVariableReuseAcrossTypes()
{
TypeSignature leftType = new TypeSignature("decimal", TypeSignatureParameter.typeVariable("p1"), TypeSignatureParameter.typeVariable("s"));
Expand All @@ -307,9 +307,11 @@ public void testNoVariableReuseAcrossTypes()
.argumentTypes(leftType, rightType)
.build();

assertThat(function)
assertThatThrownBy(() -> assertThat(function)
.boundTo(createDecimalType(2, 1), createDecimalType(3, 1))
.produces(NO_BOUND_VARIABLES);
.produces(NO_BOUND_VARIABLES))
.isInstanceOf(UnsupportedOperationException.class)
.hasMessage("Literal parameters may not be shared across different types");
}

@Test
Expand Down

0 comments on commit 6c7d4d8

Please sign in to comment.