|
| 1 | +/* |
| 2 | + * Copyright 2015 the original author or authors. |
| 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 | +package org.springframework.data.mongodb.core.convert; |
| 17 | + |
| 18 | +import static org.mockito.Mockito.*; |
| 19 | + |
| 20 | +import org.junit.Test; |
| 21 | +import org.springframework.core.convert.support.DefaultConversionService; |
| 22 | +import org.springframework.core.convert.support.GenericConversionService; |
| 23 | +import org.springframework.data.mapping.context.MappingContext; |
| 24 | +import org.springframework.data.mongodb.core.convert.MongoConverters.ObjectIdToStringConverter; |
| 25 | +import org.springframework.data.mongodb.core.convert.MongoConverters.StringToObjectIdConverter; |
| 26 | +import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity; |
| 27 | +import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty; |
| 28 | +import org.springframework.data.util.TypeInformation; |
| 29 | + |
| 30 | +import com.mongodb.DBObject; |
| 31 | +import com.mongodb.DBRef; |
| 32 | + |
| 33 | +/** |
| 34 | + * Unit tests for {@link AbstractMongoConverter}. |
| 35 | + * |
| 36 | + * @author Oliver Gierke |
| 37 | + */ |
| 38 | +public class AbstractMongoConverterUnitTests { |
| 39 | + |
| 40 | + /** |
| 41 | + * @see DATAMONGO-1324 |
| 42 | + */ |
| 43 | + @Test |
| 44 | + public void registersObjectIdConvertersExplicitly() { |
| 45 | + |
| 46 | + DefaultConversionService conversionService = spy(new DefaultConversionService()); |
| 47 | + |
| 48 | + new SampleMongoConverter(conversionService).afterPropertiesSet(); |
| 49 | + |
| 50 | + verify(conversionService).addConverter(StringToObjectIdConverter.INSTANCE); |
| 51 | + verify(conversionService).addConverter(ObjectIdToStringConverter.INSTANCE); |
| 52 | + } |
| 53 | + |
| 54 | + static class SampleMongoConverter extends AbstractMongoConverter { |
| 55 | + |
| 56 | + public SampleMongoConverter(GenericConversionService conversionService) { |
| 57 | + super(conversionService); |
| 58 | + } |
| 59 | + |
| 60 | + @Override |
| 61 | + public MongoTypeMapper getTypeMapper() { |
| 62 | + throw new UnsupportedOperationException(); |
| 63 | + } |
| 64 | + |
| 65 | + @Override |
| 66 | + public MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> getMappingContext() { |
| 67 | + throw new UnsupportedOperationException(); |
| 68 | + } |
| 69 | + |
| 70 | + @Override |
| 71 | + public <R> R read(Class<R> type, DBObject source) { |
| 72 | + throw new UnsupportedOperationException(); |
| 73 | + } |
| 74 | + |
| 75 | + @Override |
| 76 | + public void write(Object source, DBObject sink) { |
| 77 | + throw new UnsupportedOperationException(); |
| 78 | + } |
| 79 | + |
| 80 | + @Override |
| 81 | + public Object convertToMongoType(Object obj, TypeInformation<?> typeInformation) { |
| 82 | + throw new UnsupportedOperationException(); |
| 83 | + } |
| 84 | + |
| 85 | + @Override |
| 86 | + public DBRef toDBRef(Object object, MongoPersistentProperty referingProperty) { |
| 87 | + throw new UnsupportedOperationException(); |
| 88 | + } |
| 89 | + } |
| 90 | +} |
0 commit comments