Simplifying validators
[groupbasedpolicy.git] / groupbasedpolicy / src / test / java / org / opendaylight / groupbasedpolicy / resolver / validator / ValidationResultTest.java
1 /*\r
2  * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 \r
9 package org.opendaylight.groupbasedpolicy.resolver.validator;\r
10 \r
11 import org.junit.Assert;\r
12 import org.junit.Before;\r
13 import org.junit.Rule;\r
14 import org.junit.Test;\r
15 import org.junit.rules.ExpectedException;\r
16 \r
17 public class ValidationResultTest {\r
18 \r
19     @Rule\r
20     public ExpectedException thrown = ExpectedException.none();\r
21 \r
22     ValidationResultBuilder resultBuilder;\r
23     ValidationResult result;\r
24 \r
25     @Before\r
26     public void initialisation() {\r
27         resultBuilder = new ValidationResultBuilder();\r
28     }\r
29 \r
30     @Test\r
31     public void successValidationTest() {\r
32         result = resultBuilder.success().build();\r
33         Assert.assertTrue(result.isValid());\r
34         Assert.assertTrue(result.getMessage().equals(""));\r
35     }\r
36 \r
37     @Test\r
38     public void unsuccessValidationTest() {\r
39         result = resultBuilder.failed().build();\r
40         Assert.assertFalse(result.isValid());\r
41         Assert.assertTrue(result.getMessage().equals(""));\r
42     }\r
43 \r
44     @Test\r
45     public void messageTest() {\r
46         result = resultBuilder.setMessage("Validated.").build();\r
47         Assert.assertTrue(result.getMessage().equals("Validated."));\r
48         thrown.expect(IllegalArgumentException.class);\r
49         thrown.expectMessage("Result message cannot be set to NULL!");\r
50         resultBuilder.setMessage(null);\r
51     }\r
52 \r
53 }\r