[OPENJPA-2828] Fix method equals() (#72)

This commit is contained in:
Simone 2020-09-22 15:11:24 +02:00 committed by GitHub
parent 33fc72ac85
commit f93ea15745
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 83 additions and 2 deletions

View File

@ -94,8 +94,8 @@ public class Specification {
if (other == null || !this.getClass().isInstance(other))
return false;
Specification that = (Specification)other;
return Objects.equals(_name, this._name) && _major == that._major
&& Objects.equals(_minor, this._minor);
return Objects.equals(_name, that._name) && _major == that._major
&& Objects.equals(_minor, that._minor);
}
/**

View File

@ -0,0 +1,81 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.openjpa.conf;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
import org.apache.openjpa.lib.meta.ClassMetaDataIterator;
import org.apache.openjpa.meta.ClassMetaData;
import org.junit.Assert;
import org.apache.openjpa.conf.*;
public class SpecificationAdditionalTests {
String myString = "JPA";
String myCompleteString = "JPA 2.0-draft";
String myCompleteString2 = "JPA 2.1-draft";
String myHalfCompleteString = "JPA 2";
String myHalfCompleteString2 = "JPQ 2";
String myNullString = null;
@Test
public void EqualsTest() {
Specification spec = new Specification(myString);
Assert.assertTrue(spec.equals(spec)); // parse() is overidded in Specification
}
@Test
public void EqualsTest2() {
Specification spec = new Specification(myString);
Assert.assertFalse(spec.equals(myNullString)); // parse() is overidded in Specification
}
@Test
public void EqualsTest3() {
Specification spec = new Specification(myString);
Specification spec2 = new Specification(myHalfCompleteString);
Assert.assertFalse(spec.equals(spec2)); // parse() is overidded in Specification
}
@Test
public void EqualsTest4() {
Specification spec = new Specification(myString);
Assert.assertFalse(spec.equals(1)); // parse() is overidded in Specification
}
@Test
public void EqualsTest5() {
Specification spec = new Specification(myHalfCompleteString);
Specification spec2 = new Specification(myHalfCompleteString2);
Assert.assertFalse(spec.equals(spec2));
}
@Test
public void EqualsTest6() {
Specification spec = new Specification(myCompleteString);
Specification spec2 = new Specification(myHalfCompleteString2);
Assert.assertFalse(spec.equals(spec2));
}
}