From def9d6cfe2123def8947bb992813dc0b4cb06bf7 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Thu, 5 Mar 2015 11:01:20 +0100 Subject: [PATCH] =?UTF-8?q?#11=20-=20Fixed=20broken=20equals(=E2=80=A6)=20?= =?UTF-8?q?in=20SimplePluginMetadata.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/metadata/SimplePluginMetadata.java | 4 +- .../SimplePluginMetadataUnitTest.java | 51 +++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 metadata/src/test/java/org/springframework/plugin/metadata/SimplePluginMetadataUnitTest.java diff --git a/metadata/src/main/java/org/springframework/plugin/metadata/SimplePluginMetadata.java b/metadata/src/main/java/org/springframework/plugin/metadata/SimplePluginMetadata.java index 7dcdcf2..f8fdf09 100644 --- a/metadata/src/main/java/org/springframework/plugin/metadata/SimplePluginMetadata.java +++ b/metadata/src/main/java/org/springframework/plugin/metadata/SimplePluginMetadata.java @@ -23,7 +23,7 @@ import org.springframework.util.Assert; /** * Value object style implementation of {@code PluginMetadata}. * - * @author Oliver Gierke - gierke@synyx.de + * @author Oliver Gierke */ public class SimplePluginMetadata implements PluginMetadata { @@ -88,7 +88,7 @@ public class SimplePluginMetadata implements PluginMetadata { PluginMetadata that = (PluginMetadata) obj; boolean sameName = nullSafeEquals(this.getName(), that.getName()); - boolean sameVersion = nullSafeEquals(this.getName(), that.getName()); + boolean sameVersion = nullSafeEquals(this.getVersion(), that.getVersion()); return sameName && sameVersion; } diff --git a/metadata/src/test/java/org/springframework/plugin/metadata/SimplePluginMetadataUnitTest.java b/metadata/src/test/java/org/springframework/plugin/metadata/SimplePluginMetadataUnitTest.java new file mode 100644 index 0000000..2f13fbf --- /dev/null +++ b/metadata/src/test/java/org/springframework/plugin/metadata/SimplePluginMetadataUnitTest.java @@ -0,0 +1,51 @@ +/* + * Copyright 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. 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.plugin.metadata; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; + +import org.junit.Test; + +/** + * Unit tests for {@link SimplePluginMetadata}. + * + * @author Oliver Gierke + */ +public class SimplePluginMetadataUnitTest { + + /** + * @see #11 + */ + @Test + public void equalsIsWorkingCorrectly() { + + SimplePluginMetadata nameOneOh = new SimplePluginMetadata("Name", "1.0"); + SimplePluginMetadata sameNameOneOh = new SimplePluginMetadata("Name", "1.0"); + SimplePluginMetadata nameTwoOh = new SimplePluginMetadata("Name", "2.0"); + SimplePluginMetadata anotherNameOneOh = new SimplePluginMetadata("AnotherName", "1.0"); + + assertThat(nameOneOh, is(nameOneOh)); + assertThat(nameOneOh, is(sameNameOneOh)); + assertThat(sameNameOneOh, is(nameOneOh)); + + assertThat(nameOneOh, is(not(nameTwoOh))); + assertThat(nameTwoOh, is(not(nameOneOh))); + + assertThat(nameOneOh, is(not(anotherNameOneOh))); + assertThat(anotherNameOneOh, is(not(nameOneOh))); + } +}