1 /* Copyright 2017 The TensorFlow 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 
16 package org.tensorflow.processor;
17 
18 import static com.google.testing.compile.CompilationSubject.assertThat;
19 
20 import com.google.testing.compile.Compilation;
21 import com.google.testing.compile.Compiler;
22 import com.google.testing.compile.JavaFileObjects;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.junit.runners.JUnit4;
26 
27 /** Basic tests for {@link org.tensorflow.processor.operator.OperatorProcessor}. */
28 @RunWith(JUnit4.class)
29 public final class OperatorProcessorTest {
30 
31   @Test
basicGood()32   public void basicGood() {
33     Compilation compile = compile("org/tensorflow/processor/operator/good/BasicGood.java");
34     assertThat(compile).succeededWithoutWarnings();
35     assertThat(compile).generatedSourceFile("org.tensorflow.op.Ops");
36   }
37 
38   @Test
basicBad()39   public void basicBad() {
40     assertThat(compile("org/tensorflow/processor/operator/bad/BasicBad.java")).failed();
41   }
42 
43   // Create a compilation unit that includes the @Operator annotation and processor.
compile(String path)44   private static Compilation compile(String path) {
45     return Compiler.javac()
46         .withProcessors(new OperatorProcessor())
47         .compile(
48             JavaFileObjects.forResource("src/main/java/org/tensorflow/op/annotation/Operator.java"),
49             JavaFileObjects.forResource(path));
50   }
51 }
52