Damien Martin-Guillerez | f88f4d8 | 2015-09-25 13:56:55 +0000 | [diff] [blame] | 1 | // Copyright 2014 The Bazel Authors. All rights reserved. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 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 | package com.google.devtools.build.lib.util; |
| 15 | |
Ulf Adams | 795895a | 2015-03-06 15:58:35 +0000 | [diff] [blame] | 16 | import static com.google.common.truth.Truth.assertThat; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 17 | import static org.junit.Assert.fail; |
| 18 | |
lberki | 78cfa8d | 2017-05-30 17:00:48 +0200 | [diff] [blame] | 19 | import java.io.IOException; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 20 | import org.junit.Test; |
| 21 | import org.junit.runner.RunWith; |
| 22 | import org.junit.runners.JUnit4; |
| 23 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 24 | /** |
| 25 | * A test for {@link ResourceFileLoader}. |
| 26 | */ |
| 27 | @RunWith(JUnit4.class) |
| 28 | public class ResourceFileLoaderTest { |
| 29 | |
| 30 | @Test |
| 31 | public void loader() throws IOException { |
| 32 | String message = ResourceFileLoader.loadResource( |
| 33 | ResourceFileLoaderTest.class, "ResourceFileLoaderTest.message"); |
lberki | 78cfa8d | 2017-05-30 17:00:48 +0200 | [diff] [blame] | 34 | assertThat(message).isEqualTo("Hello, world."); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | @Test |
| 38 | public void resourceNotFound() { |
| 39 | try { |
| 40 | ResourceFileLoader.loadResource(ResourceFileLoaderTest.class, |
| 41 | "does_not_exist.txt"); |
| 42 | fail(); |
| 43 | } catch (IOException e) { |
Ulf Adams | 795895a | 2015-03-06 15:58:35 +0000 | [diff] [blame] | 44 | assertThat(e).hasMessage("does_not_exist.txt not found."); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 45 | } |
| 46 | } |
| 47 | |
| 48 | } |