01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: TestContentDataUser.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.cmf.dam;
09:
10: import com.uwyn.rife.tools.InnerClassException;
11: import junit.framework.TestCase;
12:
13: public class TestContentDataUser extends TestCase {
14: public TestContentDataUser(String name) {
15: super (name);
16: }
17:
18: public void testInstantiation() {
19: ContentDataUser user = new ContentDataUser() {
20: public Object useContentData(Object contentData)
21: throws InnerClassException {
22: return null;
23: }
24: };
25:
26: assertNotNull(user);
27: }
28:
29: public void testClone() {
30: ContentDataUser user = new ContentDataUser() {
31: public Object useContentData(Object contentData)
32: throws InnerClassException {
33: return null;
34: }
35: };
36:
37: ContentDataUser cloned = user.clone();
38:
39: assertNotNull(cloned);
40: assertNotSame(cloned, user);
41: }
42:
43: public void testData() {
44: ContentDataUser user = new ContentDataUser<String, Integer>(123) {
45: public String useContentData(Object contentData)
46: throws InnerClassException {
47: return contentData + " some string " + getData();
48: }
49: };
50:
51: assertEquals("the data some string 123", user
52: .useContentData("the data"));
53: }
54:
55: public void testException() {
56: ContentDataUser user = new ContentDataUser() {
57: public Object useContentData(Object contentData)
58: throws InnerClassException {
59: throwException(new Exception(contentData.toString()));
60: return null;
61: }
62: };
63:
64: try {
65: user.useContentData("some exception");
66:
67: fail();
68: } catch (InnerClassException e) {
69: assertEquals("some exception", e.getCause().getMessage());
70: }
71: }
72: }
|