DATACMNS-651 - Introduced a Range value type.
Primarily intended to be used with Distance instances, we introduce a Range value type. Distance now has factory methods to create Range instances between two distances. To support this, Distance now implements comparable based on the normalized value of it. Tiny refactoring in TypeDiscoverer to avoid code duplication between the lookup of parameter type information for constructors and methods.
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright 2015 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.domain;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link Range}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @since 1.10
|
||||
*/
|
||||
public class RangeUnitTests {
|
||||
|
||||
/**
|
||||
* @see DATACMNS-651
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void rejectsNullReferenceValuesForContains() {
|
||||
new Range<Long>(10L, 20L).contains(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-651
|
||||
*/
|
||||
@Test
|
||||
public void usesBoundsInclusivelyByDefault() {
|
||||
|
||||
Range<Long> range = new Range<Long>(10L, 20L);
|
||||
|
||||
assertThat(range.contains(10L), is(true));
|
||||
assertThat(range.contains(20L), is(true));
|
||||
assertThat(range.contains(15L), is(true));
|
||||
assertThat(range.contains(5L), is(false));
|
||||
assertThat(range.contains(25L), is(false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-651
|
||||
*/
|
||||
@Test
|
||||
public void excludesLowerBoundIfConfigured() {
|
||||
|
||||
Range<Long> range = new Range<Long>(10L, 20L, false, true);
|
||||
|
||||
assertThat(range.contains(10L), is(false));
|
||||
assertThat(range.contains(20L), is(true));
|
||||
assertThat(range.contains(15L), is(true));
|
||||
assertThat(range.contains(5L), is(false));
|
||||
assertThat(range.contains(25L), is(false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-651
|
||||
*/
|
||||
@Test
|
||||
public void excludesUpperBoundIfConfigured() {
|
||||
|
||||
Range<Long> range = new Range<Long>(10L, 20L, true, false);
|
||||
|
||||
assertThat(range.contains(10L), is(true));
|
||||
assertThat(range.contains(20L), is(false));
|
||||
assertThat(range.contains(15L), is(true));
|
||||
assertThat(range.contains(5L), is(false));
|
||||
assertThat(range.contains(25L), is(false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-651
|
||||
*/
|
||||
@Test
|
||||
public void handlesOpenUpperBoundCorrectly() {
|
||||
|
||||
Range<Long> range = new Range<Long>(10L, null);
|
||||
|
||||
assertThat(range.contains(10L), is(true));
|
||||
assertThat(range.contains(20L), is(true));
|
||||
assertThat(range.contains(15L), is(true));
|
||||
assertThat(range.contains(5L), is(false));
|
||||
assertThat(range.contains(25L), is(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-651
|
||||
*/
|
||||
@Test
|
||||
public void handlesOpenLowerBoundCorrectly() {
|
||||
|
||||
Range<Long> range = new Range<Long>(null, 20L);
|
||||
|
||||
assertThat(range.contains(10L), is(true));
|
||||
assertThat(range.contains(20L), is(true));
|
||||
assertThat(range.contains(15L), is(true));
|
||||
assertThat(range.contains(5L), is(true));
|
||||
assertThat(range.contains(25L), is(false));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user