01: /*
02: * Copyright (C) 2006 Joe Walnes.
03: * Copyright (C) 2006, 2007 XStream Committers.
04: * All rights reserved.
05: *
06: * The software in this package is published under the terms of the BSD
07: * style license a copy of which has been included with this distribution in
08: * the LICENSE.txt file.
09: *
10: * Created on 06. March 2004 by Mauro Talevi
11: */
12: package com.thoughtworks.xstream.core;
13:
14: import java.util.BitSet;
15:
16: import junit.framework.TestCase;
17:
18: import com.thoughtworks.xstream.XStream;
19: import com.thoughtworks.xstream.converters.Converter;
20: import com.thoughtworks.xstream.converters.SingleValueConverterWrapper;
21: import com.thoughtworks.xstream.converters.basic.StringConverter;
22: import com.thoughtworks.xstream.converters.collections.BitSetConverter;
23:
24: /**
25: * @author Guilherme Silveira
26: */
27: public class DefaultConverterLookupTest extends TestCase {
28:
29: public void testCanReplaceWithHigherPriority() {
30:
31: // this test actually depends on the keyset implementation of the corresponding cache map.
32: final DefaultConverterLookup lookup = new DefaultConverterLookup();
33: Converter currentConverter = new SingleValueConverterWrapper(
34: new StringConverter());
35: lookup.registerConverter(new BitSetConverter(),
36: XStream.PRIORITY_VERY_HIGH);
37: lookup.registerConverter(currentConverter, -100);
38: lookup.lookupConverterForType(String.class);
39: lookup.lookupConverterForType(BitSet.class);
40: assertEquals(lookup.lookupConverterForType(String.class),
41: currentConverter);
42: Converter newConverter = new SingleValueConverterWrapper(
43: new StringConverter());
44: lookup.registerConverter(newConverter, 100);
45: assertEquals(lookup.lookupConverterForType(String.class),
46: newConverter);
47: }
48:
49: }
|