Browse Source

Polishing

pull/769/head
Juergen Hoeller 11 years ago
parent
commit
34a5fb28c2
  1. 17
      spring-beans/src/test/java/org/springframework/beans/propertyeditors/InputStreamEditorTests.java
  2. 17
      spring-core/src/main/java/org/springframework/core/io/support/EncodedResource.java

17
spring-beans/src/test/java/org/springframework/beans/propertyeditors/InputStreamEditorTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2006 the original author or authors.
* Copyright 2002-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.
@ -30,9 +30,9 @@ import static org.junit.Assert.*; @@ -30,9 +30,9 @@ import static org.junit.Assert.*;
* @author Rick Evans
* @author Chris Beams
*/
public final class InputStreamEditorTests {
public class InputStreamEditorTests {
@Test(expected=IllegalArgumentException.class)
@Test(expected = IllegalArgumentException.class)
public void testCtorWithNullResourceEditor() throws Exception {
new InputStreamEditor(null);
}
@ -41,7 +41,8 @@ public final class InputStreamEditorTests { @@ -41,7 +41,8 @@ public final class InputStreamEditorTests {
public void testSunnyDay() throws Exception {
InputStream stream = null;
try {
String resource = "classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass()) + ".class";
String resource = "classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) +
"/" + ClassUtils.getShortName(getClass()) + ".class";
InputStreamEditor editor = new InputStreamEditor();
editor.setAsText(resource);
Object value = editor.getValue();
@ -49,14 +50,15 @@ public final class InputStreamEditorTests { @@ -49,14 +50,15 @@ public final class InputStreamEditorTests {
assertTrue(value instanceof InputStream);
stream = (InputStream) value;
assertTrue(stream.available() > 0);
} finally {
}
finally {
if (stream != null) {
stream.close();
}
}
}
@Test(expected=IllegalArgumentException.class)
@Test(expected = IllegalArgumentException.class)
public void testWhenResourceDoesNotExist() throws Exception {
String resource = "classpath:bingo!";
InputStreamEditor editor = new InputStreamEditor();
@ -66,7 +68,8 @@ public final class InputStreamEditorTests { @@ -66,7 +68,8 @@ public final class InputStreamEditorTests {
@Test
public void testGetAsTextReturnsNullByDefault() throws Exception {
assertNull(new InputStreamEditor().getAsText());
String resource = "classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass()) + ".class";
String resource = "classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) +
"/" + ClassUtils.getShortName(getClass()) + ".class";
InputStreamEditor editor = new InputStreamEditor();
editor.setAsText(resource);
assertNull(editor.getAsText());

17
spring-core/src/main/java/org/springframework/core/io/support/EncodedResource.java

@ -85,6 +85,7 @@ public class EncodedResource { @@ -85,6 +85,7 @@ public class EncodedResource {
this.charset = charset;
}
/**
* Return the {@code Resource} held by this {@code EncodedResource}.
*/
@ -152,17 +153,17 @@ public class EncodedResource { @@ -152,17 +153,17 @@ public class EncodedResource {
@Override
public boolean equals(Object obj) {
if (obj == this) {
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (obj instanceof EncodedResource) {
EncodedResource that = (EncodedResource) obj;
return (this.resource.equals(that.resource) &&
ObjectUtils.nullSafeEquals(this.charset, that.charset) &&
ObjectUtils.nullSafeEquals(this.encoding, that.encoding));
if (!(other instanceof EncodedResource)) {
return false;
}
return false;
EncodedResource otherResource = (EncodedResource) other;
return (this.resource.equals(otherResource.resource) &&
ObjectUtils.nullSafeEquals(this.charset, otherResource.charset) &&
ObjectUtils.nullSafeEquals(this.encoding, otherResource.encoding));
}
@Override

Loading…
Cancel
Save