#720078 : added better Exception

This commit is contained in:
Timo Westkämper 2011-02-17 08:24:55 +00:00
parent b5cd366a5e
commit f550c5958c
2 changed files with 24 additions and 15 deletions

View File

@ -125,7 +125,11 @@ public abstract class SimpleExpression<T> extends ExpressionBase<T> {
* @return
*/
public BooleanExpression eq(T right) {
return eq(new ConstantImpl<T>(right));
if (right == null){
throw new IllegalArgumentException("eq(null) is not allowed. Use isNull() instead");
}else{
return eq(new ConstantImpl<T>(right));
}
}
/**

View File

@ -23,38 +23,38 @@ import com.mysema.query.types.PathImpl;
import com.mysema.query.types.path.*;
public class SimpleExpressionTest {
enum ExampleEnum {A,B}
@Test
public void As_usage(){
SimpleExpression<String> str = new StringPath("str");
assertEquals("str as alias", str.as("alias").toString());
assertEquals("str as alias", str.as(new StringPath("alias")).toString());
}
@Test
public void Subclasses_Override_As() throws SecurityException, NoSuchMethodException{
List<Class<?>> classes = Arrays.<Class<?>>asList(
BooleanExpression.class,
ComparableExpression.class,
DateExpression.class,
DateTimeExpression.class,
BooleanExpression.class,
ComparableExpression.class,
DateExpression.class,
DateTimeExpression.class,
EnumExpression.class,
NumberExpression.class,
NumberExpression.class,
SimpleExpression.class,
StringExpression.class,
StringExpression.class,
TimeExpression.class);
for (Class<?> cl : classes){
Method asPath = cl.getDeclaredMethod("as", Path.class);
assertEquals(cl, asPath.getReturnType());
Method asString = cl.getDeclaredMethod("as", String.class);
assertEquals(cl, asString.getReturnType());
}
}
@SuppressWarnings("unchecked")
@Test
public void Various(){
@ -74,12 +74,17 @@ public class SimpleExpressionTest {
paths.add(new SimplePath(String.class,"p"));
paths.add(new StringPath("p"));
paths.add(new TimePath(Time.class,"p"));
for (SimpleExpression<?> expr : paths){
Path o = new PathImpl(expr.getType(), "o");
assertEquals(OperationImpl.create(expr.getType(), Ops.ALIAS, expr, o), expr.as("o"));
assertEquals(OperationImpl.create(expr.getType(), Ops.ALIAS, expr, o), expr.as("o"));
Path p = new PathImpl(expr.getType(), "p");
assertEquals(OperationImpl.create(expr.getType(), Ops.ALIAS, expr, p), expr.as(p));
}
}
@Test(expected=IllegalArgumentException.class)
public void Eq_Null(){
new SimplePath<Object>(Object.class, "path").eq((Object)null);
}
}