blob: 48a5f9446c2177140945c6ad4c7b21571f03c776 [file] [log] [blame]
Laszlo Csomore042e9e2018-01-15 07:48:32 -08001// 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
15package com.google.devtools.build.runfiles;
16
17import static com.google.common.truth.Truth.assertThat;
18import static org.junit.Assert.fail;
19
20import org.junit.Test;
21import org.junit.runner.RunWith;
22import org.junit.runners.JUnit4;
23
24/** Unit tests for {@link Util}. */
25@RunWith(JUnit4.class)
26public 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}