|
| 1 | +/* |
| 2 | + * Copyright 2008-present 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; |
| 18 | + |
| 19 | +import org.bson.codecs.pojo.entities.DiscriminatorModel; |
| 20 | +import org.bson.codecs.pojo.entities.DiscriminatorWithGetterModel; |
| 21 | +import org.junit.jupiter.api.Test; |
| 22 | + |
| 23 | +import static org.junit.jupiter.api.Assertions.assertArrayEquals; |
| 24 | + |
| 25 | +public final class PojoCodecDiscriminatorTest extends PojoTestCase { |
| 26 | + |
| 27 | + @Test |
| 28 | + public void testDiscriminatorEncodedOnceWhenItIsAlsoAGetter() { |
| 29 | + byte[] encodedDiscriminatorWithoutGetter = encode( |
| 30 | + getCodec(DiscriminatorModel.class), |
| 31 | + new DiscriminatorModel(), |
| 32 | + false |
| 33 | + ).toByteArray(); |
| 34 | + byte[] encodedDiscriminatorWithGetter = encode( |
| 35 | + getCodec(DiscriminatorWithGetterModel.class), |
| 36 | + new DiscriminatorWithGetterModel(), |
| 37 | + false |
| 38 | + ).toByteArray(); |
| 39 | + assertArrayEquals(encodedDiscriminatorWithoutGetter, encodedDiscriminatorWithGetter); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + public void testDiscriminatorEncodingWhenItIsAlsoAGetter() { |
| 44 | + encodesTo( |
| 45 | + getCodec(DiscriminatorWithGetterModel.class), |
| 46 | + new DiscriminatorWithGetterModel(), |
| 47 | + "{discriminatorKey:'discriminatorValue'}" |
| 48 | + ); |
| 49 | + } |
| 50 | +} |
0 commit comments