#147 - Added toString() methods to VndErrors and VndError.
Removed duplicate test class.
This commit is contained in:
@@ -26,6 +26,7 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* A representation model class to be rendered as specified for the media type {@code application/vnd.error}.
|
||||
@@ -117,6 +118,15 @@ public class VndErrors implements Iterable<VndErrors.VndError> {
|
||||
return this.vndErrors.iterator();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("VndErrors[%s]", StringUtils.collectionToCommaDelimitedString(vndErrors));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
@@ -207,6 +217,16 @@ public class VndErrors implements Iterable<VndErrors.VndError> {
|
||||
return message;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.ResourceSupport#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("VndError[logref: %s, message: %s, links: [%s]]", logref, message,
|
||||
StringUtils.collectionToCommaDelimitedString(getLinks()));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.ResourceSupport#hashCode()
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
/*
|
||||
* Copyright 2014 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.hateoas;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.hateoas.TemplateVariable.VariableType;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link TemplateVariables}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class TemplateVariablesUnitTests {
|
||||
|
||||
/**
|
||||
* @see #137
|
||||
*/
|
||||
@Test
|
||||
public void rendersNoTempalteVariablesAsEmptyString() {
|
||||
assertThat(TemplateVariables.NONE.toString(), is(""));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #137
|
||||
*/
|
||||
@Test
|
||||
public void rendersSingleVariableCorrectly() {
|
||||
|
||||
TemplateVariables variables = new TemplateVariables(new TemplateVariable("foo", VariableType.SEGMENT));
|
||||
assertThat(variables.toString(), is("{/foo}"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #137
|
||||
*/
|
||||
@Test
|
||||
public void combinesMultipleVariablesOfTheSameType() {
|
||||
|
||||
TemplateVariable first = new TemplateVariable("foo", VariableType.REQUEST_PARAM);
|
||||
TemplateVariable second = new TemplateVariable("bar", VariableType.REQUEST_PARAM);
|
||||
|
||||
TemplateVariables variables = new TemplateVariables(first, second);
|
||||
|
||||
assertThat(variables.toString(), is("{?foo,bar}"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #137
|
||||
*/
|
||||
@Test
|
||||
public void combinesMultipleVariablesOfTheDifferentType() {
|
||||
|
||||
TemplateVariable first = new TemplateVariable("foo", VariableType.SEGMENT);
|
||||
TemplateVariable second = new TemplateVariable("bar", VariableType.REQUEST_PARAM);
|
||||
|
||||
TemplateVariables variables = new TemplateVariables(first, second);
|
||||
|
||||
assertThat(variables.toString(), is("{/foo}{?bar}"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #137
|
||||
*/
|
||||
@Test
|
||||
public void concatsVariables() {
|
||||
|
||||
TemplateVariables first = new TemplateVariables(new TemplateVariable("foo", VariableType.SEGMENT));
|
||||
TemplateVariables second = new TemplateVariables(new TemplateVariable("bar", VariableType.REQUEST_PARAM));
|
||||
|
||||
TemplateVariables variables = first.concat(second);
|
||||
|
||||
assertThat(variables.toString(), is("{/foo}{?bar}"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2014 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.hateoas;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.hateoas.VndErrors.VndError;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link VndErrors}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class VndErrorsUnitTest {
|
||||
|
||||
@Test
|
||||
public void rendersToStringCorrectly() {
|
||||
|
||||
VndError error = new VndErrors.VndError("logref", "message", new Link("foo", "bar"));
|
||||
assertThat(error.toString(), is("VndError[logref: logref, message: message, links: [<foo>;rel=\"bar\"]]"));
|
||||
|
||||
VndErrors errors = new VndErrors(error);
|
||||
assertThat(errors.toString(),
|
||||
is("VndErrors[VndError[logref: logref, message: message, links: [<foo>;rel=\"bar\"]]]"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user