|
| 1 | +/* |
| 2 | + * |
| 3 | + * Copyright 2016 the original author or authors. |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + * |
| 17 | + * |
| 18 | + */ |
| 19 | +package springfox.documentation.schema.property |
| 20 | + |
| 21 | +import spock.lang.Specification |
| 22 | + |
| 23 | +class SimpleMethodSignatureEqualitySpec extends Specification { |
| 24 | + def "detects method equality on different classes"() { |
| 25 | + given: |
| 26 | + def sut = new SimpleMethodSignatureEquality() |
| 27 | + def m1 = SwaggerBugRequest.methods.find { |
| 28 | + m -> "setInvisibleField".equals(m.name) && |
| 29 | + 1 == m.parameterTypes.length && |
| 30 | + String.class.equals(m.parameterTypes[0])} |
| 31 | + def m2 = SwaggerBugIF.methods.find { m -> "setInvisibleField".equals(m.name) } |
| 32 | + expect: |
| 33 | + sut.equivalent(m1, m2) |
| 34 | + } |
| 35 | + |
| 36 | + def "detects method inequality on different classes"() { |
| 37 | + given: |
| 38 | + def sut = new SimpleMethodSignatureEquality() |
| 39 | + def m1 = SwaggerBugRequest.methods.find { m -> "setVisibleField".equals(m.name) } |
| 40 | + def m2 = SwaggerBugIF.methods.find { m -> "setInvisibleField".equals(m.name) } |
| 41 | + expect: |
| 42 | + !sut.equivalent(m1, m2) |
| 43 | + } |
| 44 | + |
| 45 | + def "detects method inequality on different classes when parameter count differs"() { |
| 46 | + given: |
| 47 | + def sut = new SimpleMethodSignatureEquality() |
| 48 | + def m1 = SwaggerBugRequest.methods.find { m -> "setInvisibleField".equals(m.name) && 1 == m.parameterTypes.length } |
| 49 | + def m2 = SwaggerBugExtended.methods.find { m -> "setInvisibleField".equals(m.name) && 2 == m.parameterTypes.length } |
| 50 | + expect: |
| 51 | + !sut.equivalent(m1, m2) |
| 52 | + } |
| 53 | + |
| 54 | + def "detects method inequality when parameter type differs"() { |
| 55 | + given: |
| 56 | + def sut = new SimpleMethodSignatureEquality() |
| 57 | + def m1 = SwaggerBugExtended.methods.find { |
| 58 | + m -> "setInvisibleField".equals(m.name) && |
| 59 | + 1 == m.parameterTypes.length && |
| 60 | + String.class.equals(m.parameterTypes[0])} |
| 61 | + def m2 = SwaggerBugExtended.methods.find { |
| 62 | + m -> "setInvisibleField".equals(m.name) && |
| 63 | + 1 == m.parameterTypes.length && |
| 64 | + Boolean.class.equals(m.parameterTypes[0])} |
| 65 | + expect: |
| 66 | + !sut.equivalent(m1, m2) |
| 67 | + } |
| 68 | + |
| 69 | + def "Computes hashcode"() { |
| 70 | + given: |
| 71 | + def sut = new SimpleMethodSignatureEquality() |
| 72 | + def m1 = SwaggerBugRequest.methods.find { |
| 73 | + m -> "setInvisibleField".equals(m.name) && |
| 74 | + 1 == m.parameterTypes.length && |
| 75 | + String.class.equals(m.parameterTypes[0])} |
| 76 | + expect: |
| 77 | + sut.hash(m1) > 0 |
| 78 | + } |
| 79 | + |
| 80 | + |
| 81 | + class SwaggerBugRequest extends SwaggerBugExtended implements SwaggerBugIF { |
| 82 | + private String visibleField; |
| 83 | + |
| 84 | + public String getVisibleField() { |
| 85 | + return visibleField; |
| 86 | + } |
| 87 | + |
| 88 | + public void setVisibleField(String visibleField) { |
| 89 | + this.visibleField = visibleField; |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + class SwaggerBugExtended { |
| 94 | + private String invisibleField; |
| 95 | + |
| 96 | + public String getInvisibleField() { |
| 97 | + return invisibleField; |
| 98 | + } |
| 99 | + |
| 100 | + public void setInvisibleField(String invisibleField) { |
| 101 | + this.invisibleField = invisibleField; |
| 102 | + } |
| 103 | + |
| 104 | + public void setInvisibleField(Boolean another) { |
| 105 | + } |
| 106 | + |
| 107 | + public void setInvisibleField(String invisibleField, boolean another) { |
| 108 | + this.invisibleField = invisibleField; |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | + interface SwaggerBugIF { |
| 113 | + |
| 114 | + String getVisibleField(); |
| 115 | + |
| 116 | + void setVisibleField(String visibleField); |
| 117 | + |
| 118 | + String getInvisibleField(); |
| 119 | + |
| 120 | + void setInvisibleField(String invisibleField); |
| 121 | + |
| 122 | + } |
| 123 | +} |
0 commit comments