01: /*
02: * Copyright (C) 2006, 2007 XStream Committers.
03: * All rights reserved.
04: *
05: * The software in this package is published under the terms of the BSD
06: * style license a copy of which has been included with this distribution in
07: * the LICENSE.txt file.
08: *
09: * Created on 07. November 2006 by Joerg Schaible
10: */
11: package com.thoughtworks.xstream.converters;
12:
13: import com.thoughtworks.xstream.mapper.CannotResolveClassException;
14:
15: import junit.framework.TestCase;
16:
17: import java.util.StringTokenizer;
18:
19: /**
20: * @author Jörg Schaible
21: */
22: public class ConversionExceptionTest extends TestCase {
23:
24: public void testDebugMessageIsNotNested() {
25: Exception ex = new CannotResolveClassException("JUnit");
26: ConversionException innerEx = new ConversionException("Inner",
27: ex);
28: ConversionException outerEx = new ConversionException("Outer",
29: innerEx);
30: StringTokenizer tokenizer = new StringTokenizer(outerEx
31: .getMessage(), "\n\r");
32: int ends = 0;
33: while (tokenizer.hasMoreTokens()) {
34: if (tokenizer.nextToken().startsWith(
35: "---- Debugging information ----")) {
36: ++ends;
37: }
38: }
39: assertEquals(1, ends);
40: }
41:
42: public void testInfoRetainsOrder() {
43: ConversionException ex = new ConversionException("Message");
44: ex.add("1st", "first");
45: ex.add("2nd", "second");
46: ex.add("3rd", "third");
47: StringTokenizer tokenizer = new StringTokenizer(
48: ex.getMessage(), "\n\r");
49: tokenizer.nextToken();
50: tokenizer.nextToken();
51: assertEquals("1st : first", tokenizer
52: .nextToken());
53: assertEquals("2nd : second", tokenizer
54: .nextToken());
55: assertEquals("3rd : third", tokenizer
56: .nextToken());
57: }
58: }
|