KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cintoo > messages > error > TestErrors


1 /*
2  * Copyright 2006 cintoo, Berlin, Germany
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 cintoo.messages.error;
17
18 import org.testng.annotations.*;
19 import org.testng.Assert;
20 import api.cintoo.messages.Messages;
21
22 public class TestErrors {
23   
24   @Configuration(beforeTestMethod = true)
25   protected void setUp() throws Exception JavaDoc {
26     Messages.clear();
27   }
28
29   @Test
30   public void testError() {
31     Assert.assertEquals(Errors.error(ErrorCode.error(12345)), "testerror12345", "Errors returns correct message");
32     Assert.assertEquals(Errors.error(ErrorCode.error(67890)), "testerror67890", "Errors returns correct message");
33   }
34
35   @Test
36   public void testValidate() {
37     Assert.assertTrue(Errors.validateErrorCodes(ErrorContainerOk.class), "Validate returns true for class with correct error codes");
38     Assert.assertFalse(Errors.validateErrorCodes(ErrorContainerDoubleCode.class), "Validate returns false for class with double error codes");
39
40     Assert.assertTrue(Errors.validateErrorCodes(new Class JavaDoc[] { ErrorContainerOk.class, ErrorContainerCrossOk.class }), "Validate returns true for classes with correct error codes in several classes");
41     Assert.assertFalse(Errors.validateErrorCodes(new Class JavaDoc[] { ErrorContainerOk.class, ErrorContainerCrossFails.class }), "Validate returns false for classes with double error codes in several classes");
42   }
43
44   private interface ErrorContainerOk {
45     public static ErrorCode e1 = new ErrorCode(1);
46     public static ErrorCode e2 = new ErrorCode(2);
47     public static ErrorCode e3 = new ErrorCode(3);
48   }
49
50   private interface ErrorContainerDoubleCode {
51     public static ErrorCode e1 = new ErrorCode(1);
52     public static ErrorCode e2 = new ErrorCode(2);
53     public static ErrorCode e3 = new ErrorCode(2);
54   }
55
56   private interface ErrorContainerCrossFails {
57     public static ErrorCode e1 = new ErrorCode(2);
58   }
59
60   private interface ErrorContainerCrossOk {
61     public static ErrorCode e1 = new ErrorCode(4);
62     public static ErrorCode e2 = new ErrorCode(5);
63     public static ErrorCode e3 = new ErrorCode(6);
64   }
65
66 }
Popular Tags