From 34a5fb28c24909063aad71818ba8e4bb2b2c9c8c Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 1 Apr 2015 17:12:29 +0200 Subject: [PATCH] Polishing --- .../propertyeditors/InputStreamEditorTests.java | 17 ++++++++++------- .../core/io/support/EncodedResource.java | 17 +++++++++-------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/InputStreamEditorTests.java b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/InputStreamEditorTests.java index 537be76543d..5073e5d5570 100644 --- a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/InputStreamEditorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/InputStreamEditorTests.java @@ -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.*; * @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 { 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 { 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 { @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()); diff --git a/spring-core/src/main/java/org/springframework/core/io/support/EncodedResource.java b/spring-core/src/main/java/org/springframework/core/io/support/EncodedResource.java index 62db53999df..35f14a84484 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/EncodedResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/EncodedResource.java @@ -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 { @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