1 /*
2 * Copyright 2004-2008 the Seasar Foundation and the Others.
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,
13 * either express or implied. See the License for the specific language
14 * governing permissions and limitations under the License.
15 */
16 package org.seasar.uruma.util;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.seasar.framework.exception.SIllegalArgumentException;
22
23 import junit.framework.TestCase;
24
25 /**
26 * {@link AssertionUtil} のためのテストクラスです。<br />
27 *
28 * @author y-komori
29 */
30 public class AssertionUtilTest extends TestCase {
31
32 /**
33 * {@link AssertionUtil#assertNotNull(String, Object)} メソッドのテストです。<br />
34 */
35 public void testAssertNotNull() {
36 try {
37 AssertionUtil.assertNotNull("test1", new Object());
38 assertTrue(true);
39 } catch (SIllegalArgumentException e) {
40 fail("test1");
41 }
42
43 try {
44 AssertionUtil.assertNotNull("test2", null);
45 fail("test2");
46 } catch (SIllegalArgumentException e) {
47 assertTrue(true);
48 }
49 }
50
51 /**
52 * {@link AssertionUtil#assertNotEmpty(String, String)} メソッドのテストです。<br />
53 */
54 public void testAssertNotEmpty() {
55 try {
56 AssertionUtil.assertNotEmpty("test3", "sample");
57 assertTrue(true);
58 } catch (SIllegalArgumentException e) {
59 fail("test3");
60 }
61
62 try {
63 AssertionUtil.assertNotEmpty("test4", "");
64 fail("test4");
65 } catch (SIllegalArgumentException e) {
66 assertTrue(true);
67 }
68
69 try {
70 AssertionUtil.assertNotEmpty("test5", null);
71 fail("test5");
72 } catch (SIllegalArgumentException e) {
73 assertTrue(true);
74 }
75 }
76
77 /**
78 * {@link AssertionUtil#assertInstanceOf(String, Class, Object)} メソッドのテストです。<br />
79 */
80 public void testAssertInstanceOf() {
81 try {
82 AssertionUtil.assertInstanceOf("test6", List.class,
83 new ArrayList<Object>());
84 assertTrue(true);
85 } catch (SIllegalArgumentException e) {
86 fail("test6");
87 }
88
89 try {
90 AssertionUtil.assertInstanceOf("test7", List.class, new Object());
91 fail("test7");
92 } catch (SIllegalArgumentException e) {
93 assertTrue(true);
94 }
95 }
96 }