Carmi Grushko | 9f13600 | 2015-12-04 20:53:54 +0000 | [diff] [blame] | 1 | // Copyright 2015 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.lib.analysis; |
| 16 | |
| 17 | import static com.google.common.truth.Truth.assertThat; |
| 18 | import static com.google.devtools.build.lib.analysis.AnalysisUtils.checkProvider; |
michajlo | 660d17f | 2020-03-27 09:01:57 -0700 | [diff] [blame] | 19 | import static org.junit.Assert.assertThrows; |
Carmi Grushko | 9f13600 | 2015-12-04 20:53:54 +0000 | [diff] [blame] | 20 | |
| 21 | import com.google.auto.value.AutoValue; |
Carmi Grushko | 9f13600 | 2015-12-04 20:53:54 +0000 | [diff] [blame] | 22 | import org.junit.Test; |
| 23 | import org.junit.runner.RunWith; |
| 24 | import org.junit.runners.JUnit4; |
| 25 | |
| 26 | @RunWith(JUnit4.class) |
| 27 | public class AnalysisUtilsTest { |
| 28 | |
| 29 | @Test |
| 30 | public void checkProviderSucceedsOnClassAnnotatedWithAutoValue() { |
| 31 | checkProvider(AutoValuedClass.class); |
| 32 | } |
| 33 | |
| 34 | @Test |
Googler | 8910087 | 2016-07-26 15:52:48 +0000 | [diff] [blame] | 35 | public void checkProviderFailsOnClassGeneratedByAutoValue() { |
jcater | 42edea6 | 2019-05-01 08:46:18 -0700 | [diff] [blame] | 36 | IllegalArgumentException e = |
| 37 | assertThrows( |
| 38 | IllegalArgumentException.class, |
| 39 | () -> checkProvider(AutoValue_AnalysisUtilsTest_AutoValuedClass.class)); |
| 40 | assertThat(e).hasMessageThat().contains("generated by @AutoValue"); |
Carmi Grushko | 9f13600 | 2015-12-04 20:53:54 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Googler | 8910087 | 2016-07-26 15:52:48 +0000 | [diff] [blame] | 43 | // Note: this has to be defined outside of checkProviderFailsOnClassGeneratedByAutoValue() so it |
Carmi Grushko | 9f13600 | 2015-12-04 20:53:54 +0000 | [diff] [blame] | 44 | // can be static, which is required by @AutoValue. |
| 45 | @AutoValue |
| 46 | abstract static class AutoValuedClass implements TransitiveInfoProvider { |
| 47 | abstract int foo(); |
| 48 | } |
Googler | cecca15 | 2016-06-20 22:51:10 +0000 | [diff] [blame] | 49 | } |