DATACMNS-387 - Improvements in null handling in PartTree area.
We're now rejecting invalid constructor arguments handed to ClassTypeInformation, Part, PartTree and PropertyPath. Beyond that we skip the creation of a Part for an empty path segment, so that you don't end up with an invalid Part instance for a findAllByOrderByFooAsc.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2012 the original author or authors.
|
||||
* Copyright 2011-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,7 @@ package org.springframework.data.mapping;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.data.mapping.PropertyPath.*;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
@@ -319,6 +320,38 @@ public class PropertyPathUnitTests {
|
||||
PropertyPath.from("userNameBar", Bar.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-387
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void rejectsNullSource() {
|
||||
from(null, Foo.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-387
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void rejectsEmptySource() {
|
||||
from("", Foo.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-387
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void rejectsNullClass() {
|
||||
from("foo", (Class<?>) null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-387
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void rejectsNullTypeInformation() {
|
||||
from("foo", (TypeInformation<?>) null);
|
||||
}
|
||||
|
||||
private class Foo {
|
||||
|
||||
String userName;
|
||||
|
||||
@@ -470,6 +470,18 @@ public class PartTreeUnitTests {
|
||||
assertThat(new PartTree("findByOrderId", Product.class), is(notNullValue()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-387
|
||||
*/
|
||||
@Test
|
||||
public void buildsPartTreeFromEmptyPredicateCorrectly() {
|
||||
|
||||
PartTree tree = new PartTree("findAllByOrderByLastnameAsc", User.class);
|
||||
|
||||
assertThat(tree.getParts(), is(emptyIterable()));
|
||||
assertThat(tree.getSort(), is(new Sort(Direction.ASC, "lastname")));
|
||||
}
|
||||
|
||||
private static void assertType(Iterable<String> sources, Type type, String property) {
|
||||
assertType(sources, type, property, 1, true);
|
||||
}
|
||||
|
||||
@@ -277,6 +277,14 @@ public class ClassTypeInformationUnitTests {
|
||||
assertThat(categoryIdInfo, is((TypeInformation) from(Long.class)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-387
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void rejectsNullClass() {
|
||||
from(null);
|
||||
}
|
||||
|
||||
static class StringMapContainer extends MapContainer<String> {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user