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:
Oliver Gierke
2013-10-27 16:21:01 +01:00
parent 1624fec11a
commit ae9ee5b428
7 changed files with 79 additions and 19 deletions

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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> {
}