Thomas Vachuska | 58de416 | 2015-09-10 16:15:33 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | ce2a03d | 2017-08-03 19:21:03 -0700 | [diff] [blame^] | 2 | * Copyright 2016-present Open Networking Foundation |
Thomas Vachuska | 58de416 | 2015-09-10 16:15:33 -0700 | [diff] [blame] | 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 Jampani | f2f086c | 2016-01-13 16:15:39 -0800 | [diff] [blame] | 16 | package org.onlab.util; |
Madan Jampani | 8098405 | 2015-07-23 13:11:36 -0700 | [diff] [blame] | 17 | |
| 18 | import static junit.framework.TestCase.assertEquals; |
| 19 | import static junit.framework.TestCase.assertFalse; |
| 20 | import static junit.framework.TestCase.assertTrue; |
| 21 | |
| 22 | import org.junit.Test; |
| 23 | |
| 24 | import com.google.common.base.Objects; |
| 25 | |
| 26 | /** |
| 27 | * Unit tests for Match. |
| 28 | */ |
| 29 | public 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 | } |