-
Notifications
You must be signed in to change notification settings - Fork 569
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HV-930 Making sure ConstraintLocation implements equals
- Loading branch information
1 parent
6495152
commit 6825bdc
Showing
3 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...src/test/java/org/hibernate/validator/test/internal/metadata/core/MetaConstraintTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* 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.hibernate.validator.test.internal.metadata.core; | ||
|
||
import java.lang.reflect.Method; | ||
import javax.validation.constraints.NotNull; | ||
|
||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
import org.hibernate.validator.internal.metadata.core.ConstraintHelper; | ||
import org.hibernate.validator.internal.metadata.core.MetaConstraint; | ||
import org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl; | ||
import org.hibernate.validator.internal.metadata.location.ConstraintLocation; | ||
import org.hibernate.validator.testutil.TestForIssue; | ||
|
||
import static java.lang.annotation.ElementType.METHOD; | ||
import static org.testng.Assert.assertEquals; | ||
|
||
/** | ||
* @author Hardy Ferentschik | ||
*/ | ||
public class MetaConstraintTest { | ||
private ConstraintHelper constraintHelper; | ||
private Method barMethod; | ||
private NotNull constraintAnnotation; | ||
|
||
@BeforeClass | ||
public void setUp() throws Exception { | ||
constraintHelper = new ConstraintHelper(); | ||
barMethod = Foo.class.getMethod( "getBar" ); | ||
constraintAnnotation = barMethod.getAnnotation( NotNull.class ); | ||
} | ||
|
||
@Test | ||
@TestForIssue(jiraKey = "HV-930") | ||
public void two_meta_constraints_for_the_same_constraint_should_be_equal() throws Exception { | ||
ConstraintDescriptorImpl<NotNull> constraintDescriptor1 = new ConstraintDescriptorImpl<NotNull>( | ||
constraintHelper, barMethod, constraintAnnotation, METHOD | ||
); | ||
ConstraintLocation location1 = ConstraintLocation.forClass( Foo.class ); | ||
MetaConstraint<NotNull> metaConstraint1 = new MetaConstraint<NotNull>( constraintDescriptor1, location1 ); | ||
|
||
|
||
ConstraintDescriptorImpl<NotNull> constraintDescriptor2 = new ConstraintDescriptorImpl<NotNull>( | ||
constraintHelper, barMethod, constraintAnnotation, METHOD | ||
); | ||
ConstraintLocation location2 = ConstraintLocation.forClass( Foo.class ); | ||
MetaConstraint<NotNull> metaConstraint2 = new MetaConstraint<NotNull>( constraintDescriptor1, location1 ); | ||
|
||
assertEquals( | ||
metaConstraint1, metaConstraint2, "Two MetaConstraint instances for the same constraint should be equal" | ||
); | ||
} | ||
|
||
public static class Foo { | ||
@NotNull | ||
public String getBar() { | ||
return null; | ||
} | ||
} | ||
} | ||
|
||
|
59 changes: 59 additions & 0 deletions
59
.../java/org/hibernate/validator/test/internal/metadata/location/ConstraintLocationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* 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.hibernate.validator.test.internal.metadata.location; | ||
|
||
import java.lang.reflect.Member; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import org.hibernate.validator.internal.metadata.location.ConstraintLocation; | ||
import org.hibernate.validator.testutil.TestForIssue; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
|
||
/** | ||
* @author Hardy Ferentschik | ||
*/ | ||
public class ConstraintLocationTest { | ||
|
||
@Test | ||
@TestForIssue(jiraKey = "HV-930") | ||
public void two_constraint_locations_for_the_same_type_should_be_equal() { | ||
ConstraintLocation location1 = ConstraintLocation.forClass( Foo.class ); | ||
ConstraintLocation location2 = ConstraintLocation.forClass( Foo.class ); | ||
|
||
assertEquals( location1, location2, "Two constraint locations for the same type should be equal" ); | ||
} | ||
|
||
@Test | ||
@TestForIssue(jiraKey = "HV-930") | ||
public void two_constraint_locations_for_the_same_member_should_be_equal() throws Exception { | ||
Member member = Foo.class.getMethod( "getBar" ); | ||
ConstraintLocation location1 = ConstraintLocation.forProperty( member ); | ||
ConstraintLocation location2 = ConstraintLocation.forProperty( member ); | ||
|
||
assertEquals( location1, location2, "Two constraint locations for the same type should be equal" ); | ||
} | ||
|
||
public static class Foo { | ||
public String getBar() { | ||
return null; | ||
} | ||
} | ||
} | ||
|
||
|