blob: 952393aaa37fd908e957e5961fd2b5629ed977b1 [file] [log] [blame]
Thomas Vachuska58de4162015-09-10 16:15:33 -07001/*
2 * Copyright 2015 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 */
Madan Jampani80984052015-07-23 13:11:36 -070016package org.onosproject.store.consistent.impl;
17
18import static junit.framework.TestCase.assertEquals;
19import static junit.framework.TestCase.assertFalse;
20import static junit.framework.TestCase.assertTrue;
21
22import org.junit.Test;
23
24import com.google.common.base.Objects;
25
26/**
27 * Unit tests for Match.
28 */
29public class MatchTest {
30
31 @Test
32 public void testMatches() {
33 Match<String> m1 = Match.any();
34 assertTrue(m1.matches(null));
35 assertTrue(m1.matches("foo"));
36 assertTrue(m1.matches("bar"));
37
38 Match<String> m2 = Match.ifNull();
39 assertTrue(m2.matches(null));
40 assertFalse(m2.matches("foo"));
41
42 Match<String> m3 = Match.ifValue("foo");
43 assertFalse(m3.matches(null));
44 assertFalse(m3.matches("bar"));
45 assertTrue(m3.matches("foo"));
46 }
47
48 @Test
49 public void testEquals() {
50 Match<String> m1 = Match.any();
51 Match<String> m2 = Match.any();
52 Match<String> m3 = Match.ifNull();
53 Match<String> m4 = Match.ifValue("bar");
54 assertEquals(m1, m2);
55 assertFalse(Objects.equal(m1, m3));
56 assertFalse(Objects.equal(m3, m4));
57 }
58
59 @Test
60 public void testMap() {
61 Match<String> m1 = Match.ifNull();
62 assertEquals(m1.map(s -> "bar"), Match.ifNull());
63 Match<String> m2 = Match.ifValue("foo");
64 Match<String> m3 = m2.map(s -> "bar");
65 assertTrue(m3.matches("bar"));
66 }
67}