Polish StandardTypeLocatorTests
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 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.
|
||||
@@ -16,43 +16,60 @@
|
||||
|
||||
package org.springframework.expression.spel;
|
||||
|
||||
import java.util.List;
|
||||
import java.net.URL;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
import org.springframework.expression.EvaluationException;
|
||||
import org.springframework.expression.spel.support.StandardTypeLocator;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* Unit tests for type comparison.
|
||||
* Unit tests for {@link StandardTypeLocator}.
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
class StandardTypeLocatorTests {
|
||||
|
||||
private final StandardTypeLocator locator = new StandardTypeLocator();
|
||||
|
||||
@ParameterizedTest(name = "[{index}] {0} --> {1}")
|
||||
@CsvSource(delimiterString = "-->", textBlock = """
|
||||
Boolean --> java.lang.Boolean
|
||||
Character --> java.lang.Character
|
||||
Number --> java.lang.Number
|
||||
Integer --> java.lang.Integer
|
||||
String --> java.lang.String
|
||||
|
||||
java.lang.Boolean --> java.lang.Boolean
|
||||
java.lang.Integer --> java.lang.Integer
|
||||
java.lang.String --> java.lang.String
|
||||
""")
|
||||
void defaultImports(String typeName, Class<?> type) {
|
||||
assertThat(locator.findType(typeName)).isEqualTo(type);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testImports() throws EvaluationException {
|
||||
StandardTypeLocator locator = new StandardTypeLocator();
|
||||
assertThat(locator.findType("java.lang.Integer")).isEqualTo(Integer.class);
|
||||
assertThat(locator.findType("java.lang.String")).isEqualTo(String.class);
|
||||
void importPrefixes() {
|
||||
assertThat(locator.getImportPrefixes()).containsExactly("java.lang");
|
||||
}
|
||||
|
||||
List<String> prefixes = locator.getImportPrefixes();
|
||||
assertThat(prefixes).hasSize(1);
|
||||
assertThat(prefixes.contains("java.lang")).isTrue();
|
||||
assertThat(prefixes.contains("java.util")).isFalse();
|
||||
@Test
|
||||
void typeNotFound() {
|
||||
assertThatExceptionOfType(SpelEvaluationException.class)
|
||||
.isThrownBy(() -> locator.findType("URL"))
|
||||
.extracting(SpelEvaluationException::getMessageCode)
|
||||
.isEqualTo(SpelMessage.TYPE_NOT_FOUND);
|
||||
}
|
||||
|
||||
assertThat(locator.findType("Boolean")).isEqualTo(Boolean.class);
|
||||
// currently does not know about java.util by default
|
||||
// assertEquals(java.util.List.class,locator.findType("List"));
|
||||
|
||||
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() ->
|
||||
locator.findType("URL"))
|
||||
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.TYPE_NOT_FOUND));
|
||||
@Test
|
||||
void registerImport() {
|
||||
locator.registerImport("java.net");
|
||||
assertThat(locator.findType("URL")).isEqualTo(java.net.URL.class);
|
||||
assertThat(locator.findType("URL")).isEqualTo(URL.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user