Skip to content

Commit 8b35118

Browse files
committed
PojoCodec - Added test for generic interfaces
JAVA-2653
1 parent 275513a commit 8b35118

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

bson/src/test/unit/org/bson/codecs/pojo/PojoRoundTripTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.bson.codecs.pojo.entities.CollectionSpecificReturnTypeModel;
2424
import org.bson.codecs.pojo.entities.ConcreteAndNestedAbstractInterfaceModel;
2525
import org.bson.codecs.pojo.entities.ConcreteCollectionsModel;
26+
import org.bson.codecs.pojo.entities.ConcreteInterfaceGenericModel;
2627
import org.bson.codecs.pojo.entities.ConcreteStandAloneAbstractInterfaceModel;
2728
import org.bson.codecs.pojo.entities.ContainsAlternativeMapAndCollectionModel;
2829
import org.bson.codecs.pojo.entities.ConventionModel;
@@ -137,6 +138,9 @@ private static List<TestData> testCases() {
137138
+ "'child': {'_t': 'org.bson.codecs.pojo.entities.ConcreteAndNestedAbstractInterfaceModel', 'name': 'B', "
138139
+ " 'child': {'_t': 'org.bson.codecs.pojo.entities.ConcreteStandAloneAbstractInterfaceModel', 'name': 'C'}}}}"));
139140

141+
data.add(new TestData("Concrete generic interface model", new ConcreteInterfaceGenericModel("someValue"),
142+
getPojoCodecProviderBuilder(ConcreteInterfaceGenericModel.class), "{propertyA: 'someValue'}"));
143+
140144
data.add(new TestData("Primitives model", getPrimitivesModel(),
141145
getPojoCodecProviderBuilder(PrimitivesModel.class),
142146
"{ 'myBoolean': true, 'myByte': 1, 'myCharacter': '1', 'myDouble': 1.0, 'myFloat': 2.0, 'myInteger': 3, "
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2017 MongoDB, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.bson.codecs.pojo.entities;
18+
19+
public class ConcreteInterfaceGenericModel implements InterfaceGenericModel<String> {
20+
private String property;
21+
22+
public ConcreteInterfaceGenericModel() {
23+
}
24+
25+
public ConcreteInterfaceGenericModel(final String property) {
26+
this.property = property;
27+
}
28+
29+
@Override
30+
public String getPropertyA() {
31+
return property;
32+
}
33+
34+
@Override
35+
public void setPropertyA(final String property) {
36+
this.property = property;
37+
}
38+
39+
@Override
40+
public boolean equals(final Object o) {
41+
if (this == o) return true;
42+
if (o == null || getClass() != o.getClass()) {
43+
return false;
44+
}
45+
46+
ConcreteInterfaceGenericModel that = (ConcreteInterfaceGenericModel) o;
47+
48+
return property != null ? property.equals(that.property) : that.property == null;
49+
}
50+
51+
@Override
52+
public int hashCode() {
53+
return property != null ? property.hashCode() : 0;
54+
}
55+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2017 MongoDB, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.bson.codecs.pojo.entities;
18+
19+
20+
public interface InterfaceGenericModel<T> {
21+
22+
T getPropertyA();
23+
24+
void setPropertyA(T property);
25+
}

0 commit comments

Comments
 (0)