/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sourceclear.gramtest;

import java.io.IOException;
import java.util.List;
import junit.framework.TestCase;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.ParserRuleContext;
import org.junit.Assert;
import org.junit.Ignore;

/**
 *
 * @author asankhaya
 */
public class MainTest extends TestCase {
  
  public MainTest(String testName) {
    super(testName);
  }
  
  @Override
  protected void setUp() throws Exception {
    super.setUp();
  }
  
  @Override
  protected void tearDown() throws Exception {
    super.tearDown();
  }

  /**
   * Test with arithmetic expressions grammar
   * @throws java.io.IOException
   */
  public void testArithExpGram() throws IOException {
    Lexer lexer = new bnfLexer(new ANTLRInputStream(getClass().getResourceAsStream("/arithexp.bnf")));        
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    bnfParser grammarparser = new bnfParser(tokens);
    ParserRuleContext tree = grammarparser.rulelist();
    GeneratorVisitor extractor = new GeneratorVisitor();
    extractor.visit(tree);
    List<String> generatedTests = extractor.getTests();
    Assert.assertEquals(100,generatedTests.size());
  }
  
  /**
   * Test with course codes grammar
   * @throws java.io.IOException
   */
  public void testCourseCodeGram() throws IOException {
    Lexer lexer = new bnfLexer(new ANTLRInputStream(getClass().getResourceAsStream("/coursecodes.bnf")));        
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    bnfParser grammarparser = new bnfParser(tokens);
    ParserRuleContext tree = grammarparser.rulelist();
    GeneratorVisitor extractor = new GeneratorVisitor();
    extractor.visit(tree);
    List<String> generatedTests = extractor.getTests();
    Assert.assertEquals(100,generatedTests.size());
  }
  
  /**
   * Test with main grammar
   * @throws java.io.IOException
   */
  public void testMainStrGram() throws IOException {
    Lexer lexer = new bnfLexer(new ANTLRInputStream(getClass().getResourceAsStream("/main.bnf")));        
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    bnfParser grammarparser = new bnfParser(tokens);
    ParserRuleContext tree = grammarparser.rulelist();
    GeneratorVisitor extractor = new GeneratorVisitor(100,2,100,true);
    extractor.visit(tree);
    List<String> generatedTests = extractor.getTests();
    Assert.assertEquals(100,generatedTests.size());
  }

  /**
   * Test with url grammar
   * @throws java.io.IOException
   */
  @Ignore("long running test")
  public void testURLGram() throws IOException {
    Lexer lexer = new bnfLexer(new ANTLRInputStream(getClass().getResourceAsStream("/url.bnf")));
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    bnfParser grammarparser = new bnfParser(tokens);
    ParserRuleContext tree = grammarparser.rulelist();
    GeneratorVisitor extractor = new GeneratorVisitor(100,2,100,true);
    extractor.visit(tree);
    List<String> generatedTests = extractor.getTests();
    Assert.assertEquals(100,generatedTests.size());
  }
  
}

@@ -268,41 +268,8 @@
 st;%0A
-import junit.framework.TestCase;%0A
 impo
@@ -460,39 +460,9 @@
 nit.
-Assert;%0Aimport org.junit.Ignore
+*
 ;%0A%0A/
@@ -518,25 +518,8 @@
 est 
-extends TestCase 
 %7B%0A  
@@ -587,36 +587,31 @@
 %7D%0A  %0A  @
-Override%0A  protected
+Before%0A  public
  void se
@@ -641,55 +641,30 @@
 %7B%0A  
-  super.setUp();%0A  %7D%0A  %0A  @Override%0A  protected
+%7D%0A  %0A  @After%0A  public
  voi
@@ -699,30 +699,8 @@
 n %7B%0A
-    super.tearDown();%0A
   %7D%0A
@@ -783,32 +783,40 @@
 Exception%0A   */%0A
+  @Test%0A
   public void te
@@ -1405,32 +1405,40 @@
 Exception%0A   */%0A
+  @Test%0A
   public void te
@@ -2032,16 +2032,24 @@
 n%0A   */%0A
+  @Test%0A
   public
@@ -2652,16 +2652,24 @@
 n%0A   */%0A
+  @Test%0A
   @Ignor

Move to JUnit4