Search in sources :

Example 1 with TypeComparator

use of org.springframework.expression.TypeComparator in project spring-framework by spring-projects.

the class DefaultComparatorUnitTests method testNulls.

@Test
public void testNulls() throws EvaluationException {
    TypeComparator comparator = new StandardTypeComparator();
    assertTrue(comparator.compare(null, "abc") < 0);
    assertTrue(comparator.compare(null, null) == 0);
    assertTrue(comparator.compare("abc", null) > 0);
}
Also used : TypeComparator(org.springframework.expression.TypeComparator) StandardTypeComparator(org.springframework.expression.spel.support.StandardTypeComparator) StandardTypeComparator(org.springframework.expression.spel.support.StandardTypeComparator) Test(org.junit.Test)

Example 2 with TypeComparator

use of org.springframework.expression.TypeComparator in project spring-framework by spring-projects.

the class DefaultComparatorUnitTests method testObjects.

@Test
public void testObjects() throws EvaluationException {
    TypeComparator comparator = new StandardTypeComparator();
    assertTrue(comparator.compare("a", "a") == 0);
    assertTrue(comparator.compare("a", "b") < 0);
    assertTrue(comparator.compare("b", "a") > 0);
}
Also used : TypeComparator(org.springframework.expression.TypeComparator) StandardTypeComparator(org.springframework.expression.spel.support.StandardTypeComparator) StandardTypeComparator(org.springframework.expression.spel.support.StandardTypeComparator) Test(org.junit.Test)

Example 3 with TypeComparator

use of org.springframework.expression.TypeComparator in project spring-security by spring-projects.

the class DelegatingEvaluationContextTests method getTypeComparator.

@Test
public void getTypeComparator() {
    TypeComparator expected = mock(TypeComparator.class);
    when(this.delegate.getTypeComparator()).thenReturn(expected);
    assertThat(this.context.getTypeComparator()).isEqualTo(expected);
}
Also used : TypeComparator(org.springframework.expression.TypeComparator) Test(org.junit.Test)

Example 4 with TypeComparator

use of org.springframework.expression.TypeComparator in project spring-framework by spring-projects.

the class DefaultComparatorUnitTests method testCanCompare.

@Test
public void testCanCompare() throws EvaluationException {
    TypeComparator comparator = new StandardTypeComparator();
    assertTrue(comparator.canCompare(null, 1));
    assertTrue(comparator.canCompare(1, null));
    assertTrue(comparator.canCompare(2, 1));
    assertTrue(comparator.canCompare("abc", "def"));
    assertTrue(comparator.canCompare("abc", 3));
    assertFalse(comparator.canCompare(String.class, 3));
}
Also used : TypeComparator(org.springframework.expression.TypeComparator) StandardTypeComparator(org.springframework.expression.spel.support.StandardTypeComparator) StandardTypeComparator(org.springframework.expression.spel.support.StandardTypeComparator) Test(org.junit.Test)

Example 5 with TypeComparator

use of org.springframework.expression.TypeComparator in project spring-framework by spring-projects.

the class DefaultComparatorUnitTests method testPrimitives.

@Test
public void testPrimitives() throws EvaluationException {
    TypeComparator comparator = new StandardTypeComparator();
    // primitive int
    assertTrue(comparator.compare(1, 2) < 0);
    assertTrue(comparator.compare(1, 1) == 0);
    assertTrue(comparator.compare(2, 1) > 0);
    assertTrue(comparator.compare(1.0d, 2) < 0);
    assertTrue(comparator.compare(1.0d, 1) == 0);
    assertTrue(comparator.compare(2.0d, 1) > 0);
    assertTrue(comparator.compare(1.0f, 2) < 0);
    assertTrue(comparator.compare(1.0f, 1) == 0);
    assertTrue(comparator.compare(2.0f, 1) > 0);
    assertTrue(comparator.compare(1L, 2) < 0);
    assertTrue(comparator.compare(1L, 1) == 0);
    assertTrue(comparator.compare(2L, 1) > 0);
    assertTrue(comparator.compare(1, 2L) < 0);
    assertTrue(comparator.compare(1, 1L) == 0);
    assertTrue(comparator.compare(2, 1L) > 0);
    assertTrue(comparator.compare(1L, 2L) < 0);
    assertTrue(comparator.compare(1L, 1L) == 0);
    assertTrue(comparator.compare(2L, 1L) > 0);
}
Also used : TypeComparator(org.springframework.expression.TypeComparator) StandardTypeComparator(org.springframework.expression.spel.support.StandardTypeComparator) StandardTypeComparator(org.springframework.expression.spel.support.StandardTypeComparator) Test(org.junit.Test)

Aggregations

TypeComparator (org.springframework.expression.TypeComparator)8 Test (org.junit.Test)7 StandardTypeComparator (org.springframework.expression.spel.support.StandardTypeComparator)5 BigDecimal (java.math.BigDecimal)1 List (java.util.List)1 TypeLocator (org.springframework.expression.TypeLocator)1 SpelEvaluationException (org.springframework.expression.spel.SpelEvaluationException)1