Removed deprecated core.enums package
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -21,7 +21,6 @@ import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.core.enums.LabeledEnum;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.servlet.support.BindStatus;
|
||||
@@ -40,10 +39,6 @@ import org.springframework.web.servlet.support.BindStatus;
|
||||
* {@link #exhaustiveCompare exhaustive comparison} with the aim being to <strong>prove</strong> equality rather
|
||||
* than disprove it.
|
||||
*
|
||||
* <p>Special support is given for instances of {@link LabeledEnum} with a {@code String}-based
|
||||
* comparison of the candidate value against the code of the {@link LabeledEnum}. This can be useful when a
|
||||
* {@link LabeledEnum} is used to define a list of '{@code <option>}' elements in HTML.
|
||||
*
|
||||
* <p>Next, an attempt is made to compare the {@code String} representations of both the candidate and bound
|
||||
* values. This may result in {@code true} in a number of cases due to the fact both values will be represented
|
||||
* as {@code Strings} when shown to the user.
|
||||
@@ -153,18 +148,7 @@ abstract class SelectedValueComparator {
|
||||
PropertyEditor editor, Map<PropertyEditor, Object> convertedValueCache) {
|
||||
|
||||
String candidateDisplayString = ValueFormatter.getDisplayString(candidate, editor, false);
|
||||
if (boundValue instanceof LabeledEnum) {
|
||||
LabeledEnum labeledEnum = (LabeledEnum) boundValue;
|
||||
String enumCodeAsString = ObjectUtils.getDisplayString(labeledEnum.getCode());
|
||||
if (enumCodeAsString.equals(candidateDisplayString)) {
|
||||
return true;
|
||||
}
|
||||
String enumLabelAsString = ObjectUtils.getDisplayString(labeledEnum.getLabel());
|
||||
if (enumLabelAsString.equals(candidateDisplayString)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (boundValue.getClass().isEnum()) {
|
||||
if (boundValue.getClass().isEnum()) {
|
||||
Enum boundEnum = (Enum) boundValue;
|
||||
String enumCodeAsString = ObjectUtils.getDisplayString(boundEnum.name());
|
||||
if (enumCodeAsString.equals(candidateDisplayString)) {
|
||||
|
||||
@@ -185,59 +185,12 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
try {
|
||||
tag.doStartTag();
|
||||
fail("Must not be able to use <option> tag without exposed context.");
|
||||
} catch (IllegalStateException ex) {
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testWithEnum() throws Exception {
|
||||
String selectName = "testBean.favouriteColour";
|
||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
|
||||
|
||||
String value = Colour.GREEN.getCode().toString();
|
||||
String label = Colour.GREEN.getLabel();
|
||||
|
||||
this.tag.setValue(value);
|
||||
this.tag.setLabel(label);
|
||||
|
||||
int result = this.tag.doStartTag();
|
||||
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
|
||||
result = this.tag.doEndTag();
|
||||
assertEquals(Tag.EVAL_PAGE, result);
|
||||
|
||||
String output = getOutput();
|
||||
|
||||
assertOptionTagOpened(output);
|
||||
assertOptionTagClosed(output);
|
||||
assertContainsAttribute(output, "value", value);
|
||||
assertContainsAttribute(output, "selected", "selected");
|
||||
assertBlockTagContains(output, label);
|
||||
}
|
||||
|
||||
public void testWithEnumNotSelected() throws Exception {
|
||||
String selectName = "testBean.favouriteColour";
|
||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
|
||||
|
||||
String value = Colour.BLUE.getCode().toString();
|
||||
String label = Colour.BLUE.getLabel();
|
||||
|
||||
this.tag.setValue(value);
|
||||
this.tag.setLabel(label);
|
||||
|
||||
int result = this.tag.doStartTag();
|
||||
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
|
||||
result = this.tag.doEndTag();
|
||||
assertEquals(Tag.EVAL_PAGE, result);
|
||||
|
||||
String output = getOutput();
|
||||
|
||||
assertOptionTagOpened(output);
|
||||
assertOptionTagClosed(output);
|
||||
assertContainsAttribute(output, "value", value);
|
||||
assertAttributeNotPresent(output, "selected");
|
||||
assertBlockTagContains(output, label);
|
||||
}
|
||||
|
||||
public void testWithPropertyEditor() throws Exception {
|
||||
String selectName = "testBean.stringArray";
|
||||
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
|
||||
|
||||
Reference in New Issue
Block a user