Laszlo Csomor | e042e9e | 2018-01-15 07:48:32 -0800 | [diff] [blame] | 1 | // Copyright 2018 The Bazel Authors. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package com.google.devtools.build.runfiles; |
| 16 | |
| 17 | import static com.google.common.truth.Truth.assertThat; |
| 18 | import static org.junit.Assert.fail; |
| 19 | |
| 20 | import org.junit.Test; |
| 21 | import org.junit.runner.RunWith; |
| 22 | import org.junit.runners.JUnit4; |
| 23 | |
| 24 | /** Unit tests for {@link Util}. */ |
| 25 | @RunWith(JUnit4.class) |
| 26 | public final class UtilTest { |
| 27 | |
| 28 | @Test |
| 29 | public void testIsNullOrEmpty() throws Exception { |
| 30 | assertThat(Util.isNullOrEmpty(null)).isTrue(); |
| 31 | assertThat(Util.isNullOrEmpty("")).isTrue(); |
| 32 | assertThat(Util.isNullOrEmpty("\0")).isFalse(); |
| 33 | assertThat(Util.isNullOrEmpty("some text")).isFalse(); |
| 34 | } |
| 35 | |
| 36 | @Test |
| 37 | public void testCheckArgument() throws Exception { |
| 38 | Util.checkArgument(true, null, null); |
| 39 | |
| 40 | try { |
| 41 | Util.checkArgument(false, null, null); |
| 42 | fail("expected failure"); |
| 43 | } catch (IllegalArgumentException e) { |
| 44 | assertThat(e).hasMessageThat().isEqualTo("argument validation failed"); |
| 45 | } |
| 46 | |
| 47 | try { |
| 48 | Util.checkArgument(false, "foo-%s", 42); |
| 49 | fail("expected failure"); |
| 50 | } catch (IllegalArgumentException e) { |
| 51 | assertThat(e).hasMessageThat().isEqualTo("foo-42"); |
| 52 | } |
| 53 | } |
| 54 | } |