blob: 3d7cacd8233fd34fb63ca655c253350934987dd7 [file] [log] [blame]
maojianwei42e23442016-02-15 10:40:48 +08001/*
2 * Copyright 2015-present Open Networking Laboratory
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 */
16package org.onosproject.fnl.base;
17
18import org.junit.After;
19import org.junit.Before;
20import org.junit.Test;
21
22import static org.junit.Assert.assertEquals;
23import static org.junit.Assert.assertFalse;
24import static org.junit.Assert.assertNotSame;
25import static org.junit.Assert.assertTrue;
26
27/**
28 * Unit Tests for TsReturn class.
29 */
30public class TsReturnTest {
31
32 private static final boolean OLD_BOOLEAN_EXAMPLE = false;
33 private static final boolean NEW_BOOLEAN_EXAMPLE = true;
34 private static final int OLD_INTEGER_EXAMPLE = 7181;
35 private static final int NEW_INTEGER_EXAMPLE = 1355;
36
37
38 @Before
39 public void setUp() {
40 // do nothing
41 }
42
43 @After
44 public void tearDown() {
45 // do nothing
46 }
47
48 @Test
49 public void testPresent() {
50 TsReturn<Boolean> bool = new TsReturn<>();
51 assertFalse(bool.isPresent());
52
53 bool.setValue(NEW_BOOLEAN_EXAMPLE);
54 assertTrue(bool.isPresent());
55 }
56
57 @Test
58 public void testRoleReturnBoolean() {
59 TsReturn<Boolean> bool = new TsReturn<>();
60 bool.setValue(OLD_BOOLEAN_EXAMPLE);
61
62 Boolean oldValue = bool.getValue();
63 changeBoolean(bool);
64 Boolean newValue = bool.getValue();
65
66 assertNotSame(oldValue, newValue);
67 assertEquals(newValue, NEW_BOOLEAN_EXAMPLE);
68 }
69
70 @Test
71 public void testRoleReturnInteger() {
72 TsReturn<Integer> integer = new TsReturn<>();
73 integer.setValue(OLD_INTEGER_EXAMPLE);
74
75 Integer oldValue = integer.getValue();
76 changeInteger(integer);
77 Integer newValue = integer.getValue();
78
79 assertNotSame(oldValue, newValue);
80 assertEquals(newValue.intValue(), NEW_INTEGER_EXAMPLE);
81 }
82
83 private void changeBoolean(TsReturn bool) {
84 bool.setValue(NEW_BOOLEAN_EXAMPLE);
85 }
86
87 private void changeInteger(TsReturn integer) {
88 integer.setValue(NEW_INTEGER_EXAMPLE);
89 }
90}