import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Maps;
import java.io.File;
import java.io.FileNotFoundException;
-import java.util.List;
+import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import org.junit.Test;
-import org.opendaylight.mdsal.binding.java.api.generator.GeneratorJavaFile;
-import org.opendaylight.mdsal.binding.model.api.Type;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
/**
* Bug5151 involves adding <code>{@literal @}return</code> annotations to accessor methods.
@Test
public void test() throws Exception {
- final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + BUG_ID);
- assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
- final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + BUG_ID);
- assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
-
- generateTestSources(CompilationTestUtils.FS + "compilation" + CompilationTestUtils.FS + BUG_ID, sourcesOutputDir);
+ final File sourcesOutputDir = CompilationTestUtils.generatorOutput(BUG_ID);
+ final File compiledOutputDir = CompilationTestUtils.compilerOutput(BUG_ID);
+ generateTestSources(CompilationTestUtils.FS + "compilation" + CompilationTestUtils.FS + BUG_ID,
+ sourcesOutputDir);
// Test if sources are compilable
CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
final Map<String, File> generatedFiles = getFiles(sourcesOutputDir);
- assertEquals(3, generatedFiles.size());
+ assertEquals(4, generatedFiles.size());
final File fooContainerFile = generatedFiles.get("FooContainer.java");
assertNotNull(fooContainerFile);
}
private static boolean findInFile(final File file, final String searchText) throws FileNotFoundException {
- final Scanner scanner = new Scanner(file);
- while (scanner.hasNextLine()) {
- final String nextLine = scanner.nextLine();
- if (nextLine.contains(searchText)) {
- return true;
+ try (Scanner scanner = new Scanner(file)) {
+ while (scanner.hasNextLine()) {
+ final String nextLine = scanner.nextLine();
+ if (nextLine.contains(searchText)) {
+ return true;
+ }
}
}
return false;
}
- private void generateTestSources(final String resourceDirPath, final File sourcesOutputDir) throws Exception {
- final List<File> sourceFiles = CompilationTestUtils.getSourceFiles(resourceDirPath);
- final SchemaContext context = YangParserTestUtils.parseYangSources(sourceFiles);
- final List<Type> types = bindingGenerator.generateTypes(context);
- final GeneratorJavaFile generator = new GeneratorJavaFile(ImmutableSet.copyOf(types));
- generator.generateToFile(sourcesOutputDir);
- }
-
private static Map<String, File> getFiles(final File path) {
- return getFiles(path, Maps.newHashMap());
+ return getFiles(path, new HashMap<>());
}
private static Map<String, File> getFiles(final File path, final Map<String, File> files) {
for (File file : dirFiles) {
if (file.isDirectory()) {
return getFiles(file, files);
- } else {
- files.put(file.getName(), file);
}
+
+ files.put(file.getName(), file);
}
return files;
}