2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.mdsal.binding.java.api.generator.test;
10 import static junit.framework.TestCase.assertTrue;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
15 import java.io.FileNotFoundException;
16 import java.util.HashMap;
18 import java.util.Scanner;
19 import org.junit.Test;
22 * Bug5151 involves adding <code>{@literal @}return</code> annotations to accessor methods.
24 public class Bug5151Test extends BaseCompilationTest {
26 private static final String BUG_ID = "bug5151";
29 public void test() throws Exception {
30 final File sourcesOutputDir = CompilationTestUtils.generatorOutput(BUG_ID);
31 final File compiledOutputDir = CompilationTestUtils.compilerOutput(BUG_ID);
32 generateTestSources(CompilationTestUtils.FS + "compilation" + CompilationTestUtils.FS + BUG_ID,
35 // Test if sources are compilable
36 CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
38 final Map<String, File> generatedFiles = getFiles(sourcesOutputDir);
39 assertEquals(4, generatedFiles.size());
41 final File fooContainerFile = generatedFiles.get("FooContainer.java");
42 assertNotNull(fooContainerFile);
43 assertTrue(findInFile(fooContainerFile,
44 "@return <code>java.lang.String</code> <code>fooInContainer</code>, "
45 + "or <code>null</code> if not present"));
47 final File fooDataFile = generatedFiles.get("FooData.java");
48 assertNotNull(fooDataFile);
49 assertTrue(findInFile(fooDataFile, "FooContainer</code> <code>fooContainer</code>, or <code>null</code> if not present"));
51 CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
54 private static boolean findInFile(final File file, final String searchText) throws FileNotFoundException {
55 try (Scanner scanner = new Scanner(file)) {
56 while (scanner.hasNextLine()) {
57 final String nextLine = scanner.nextLine();
58 if (nextLine.contains(searchText)) {
66 private static Map<String, File> getFiles(final File path) {
67 return getFiles(path, new HashMap<>());
70 private static Map<String, File> getFiles(final File path, final Map<String, File> files) {
71 final File [] dirFiles = path.listFiles();
72 for (File file : dirFiles) {
73 if (file.isDirectory()) {
74 return getFiles(file, files);
77 files.put(file.getName(), file);