/** * Copyright (c) 2012 BMW Car IT and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ package org.jnario.standalone.tests; import com.google.inject.Inject; import java.io.File; import java.io.FilenameFilter; import java.util.List; import org.eclipse.xtext.junit4.InjectWith; import org.eclipse.xtext.junit4.XtextRunner; import org.eclipse.xtext.util.Files; import org.eclipse.xtext.xbase.lib.Conversions; import org.eclipse.xtext.xbase.lib.Exceptions; import org.jnario.jnario.test.util.ExtendedSpecInjectorProvider; import org.jnario.spec.compiler.SpecBatchCompiler; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(XtextRunner.class) @InjectWith(ExtendedSpecInjectorProvider.class) @SuppressWarnings("all") public class SpecBatchCompilerTest { @Inject private SpecBatchCompiler batchCompiler; private static String OUTPUT_DIRECTORY = "./test-result"; private static String XTEND_SRC_DIRECTORY = "./testdata"; private static String TEMP_DIRECTORY = "./test-temp-dir"; @Before public void onSetup() { try { this.batchCompiler.setSourcePath(SpecBatchCompilerTest.XTEND_SRC_DIRECTORY); this.batchCompiler.setOutputPath(SpecBatchCompilerTest.OUTPUT_DIRECTORY); this.batchCompiler.setDeleteTempDirectory(true); this.batchCompiler.setUseCurrentClassLoaderAsParent(true); File _file = new File(SpecBatchCompilerTest.OUTPUT_DIRECTORY); _file.mkdir(); File _file_1 = new File(SpecBatchCompilerTest.OUTPUT_DIRECTORY); Files.cleanFolder(_file_1, null, true, false); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } } @After public void onTearDown() { try { File _file = new File(SpecBatchCompilerTest.OUTPUT_DIRECTORY); Files.cleanFolder(_file, null, true, true); File _file_1 = new File(SpecBatchCompilerTest.TEMP_DIRECTORY); boolean _exists = _file_1.exists(); if (_exists) { File _file_2 = new File(SpecBatchCompilerTest.TEMP_DIRECTORY); Files.cleanFolder(_file_2, null, true, true); } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } } @Test public void testCompileTestData() { this.batchCompiler.compile(); File _file = new File((SpecBatchCompilerTest.OUTPUT_DIRECTORY + "/test")); final FilenameFilter _function = new FilenameFilter() { public boolean accept(final File dir, final String name) { return name.endsWith(".java"); } }; String[] _list = _file.list(_function); int _size = ((List<String>)Conversions.doWrapArray(_list)).size(); Assert.assertEquals(3, _size); } }