title: java.lang.StackOverflowError while running junit test case
body: <p>I am writing junit test cases for a java application 
  Here is junit test code</p>
  
  <pre><code>public class CultureMachineTestCases extends CultureMachineAssignment {
  
      CultureMachineTestCases testObj=new CultureMachineTestCases();
  
      @Before
      public void init() throws IOException{
          testObj.insertDataIntoSet();
          testObj.addKeywords("video1");
  
      }
  
      /*@Test
  public void testVideo() throws IOException {
      result=testObj.search("abcd");
      answer=result.toString();
      answer1=answer.replaceAll("[^a-z0-9]","");
  
       assertEquals("video1", answer1);
  
  }
  @Before
  public void initMethod() throws IOException{
      testObj.insertDataIntoSet();
      testObj.addKeywords("video2");
   }   */ @Test
    public void testLenth() throws IOException{
      flagVal=testObj.flag;
  
      assertEquals(1, flagVal);
  
      }
  }
  </code></pre>
  
  <p>After I run this code in eclipse I am getting following error</p>
  
  <pre><code> java.lang.StackOverflowError
      at cultureMachine.CultureMachineAssignment.&lt;init&gt;     (CultureMachineAssignment.java:13)
      at cultureMachine.CultureMachineTestCases.&lt;init&gt;(CultureMachineTestCases.java:11)
       at cultureMachine.CultureMachineTestCases.&lt;init&gt;(CultureMachineTestCases.java:14)
       at cultureMachine.CultureMachineTestCases.&lt;init&gt;(CultureMachineTestCases.java:14)
      at cultureMachine.CultureMachineTestCases.&lt;init&gt;(CultureMachineTestCases.java:14)
   java.lang.StackOverflowError
      at cultureMachine.CultureMachineAssignment.&lt;init&gt;     (CultureMachineAssignment.java:13)
      at cultureMachine.CultureMachineTestCases.&lt;init&gt;(CultureMachineTestCases.java:11)
      at cultureMachine.CultureMachineTestCases.&lt;init&gt;(CultureMachineTestCases.java:14)
      at cultureMachine.CultureMachineTestCases.&lt;init&gt;(CultureMachineTestCases.java:14)
      at cultureMachine.CultureMachineTestCases.&lt;init&gt;(CultureMachineTestCases.java:14)
  </code></pre>
  
  <p>Here is my main java code</p>
  
  <pre><code>package cultureMachine;
          public class CultureMachineAssignment {
  
              HashMap&lt;String,HashSet&lt;String&gt;&gt; kewordVideo = new HashMap&lt;String,HashSet&lt;String&gt;&gt;();
              HashMap&lt;String,HashSet&lt;String&gt;&gt; videoKeyword =  new         HashMap&lt;String,HashSet&lt;String&gt;&gt;();
              HashMap&lt;String,Integer&gt; keywordLength = new HashMap&lt;String,Integer&gt;();
  
              HashSet&lt;String&gt; videoNames = new HashSet&lt;String&gt;();
              HashSet&lt;String&gt; result = new HashSet&lt;String&gt;();
  
              public void insertDataIntoSet(){
                  for(int i=0;i&lt;500;i++){
                      videoNames.add("video"+i);
                  }
              }
              public void addKeywords(String video)throws IOException{
  
  
                  InputStreamReader ip = new InputStreamReader(System.in);
                  BufferedReader br = new BufferedReader(ip);
  
                  Integer previousVal=0;
  
                  if(!videoKeyword.containsKey(video) &amp;&amp; videoNames.contains(video)){
                      videoKeyword.put(video,new HashSet&lt;String&gt;());
                  }
                  else if(!videoNames.contains(video)){
                      System.out.println("Video is not a part of lookup");
                  }
  
                  System.out.println("Enter keywords for video");
                  String keyword =br.readLine();
  
                  if(!keywordLength.containsKey(video))
                      keywordLength.put(video, 0);
  
                  if((keywordLength.get(video)+keyword.length())&lt;500){
                      videoKeyword.get(video).add(keyword);
                      previousVal=keywordLength.get(video);
                      keywordLength.put(video, previousVal+keyword.length());
                  }
                  else{
                      System.out.println("Maximum length exceeded for video "+ video);
                  }
                  if(!kewordVideo.containsKey(keyword)){
                      kewordVideo.put(keyword,new HashSet&lt;String&gt;());
                  }
                  kewordVideo.get(keyword).add(video);
              }
  
              public HashSet search(String searchKey){
                  for (Entry&lt;String, HashSet&lt;String&gt;&gt; entry : videoKeyword.entrySet()) {
                      for (String s : entry.getValue()) {
                          if (s.contains(searchKey)) {
                              result.add(entry.getKey());
                          break;
                          }
                      }
                  }
                  return result;
              }
  
              public static void main(String args[]) throws IOException {
  
                  CultureMachineAssignment obj1 = new CultureMachineAssignment();
                  HashSet&lt;String&gt; searchResults = new HashSet&lt;String&gt;();
                  int num=0;
                  InputStreamReader ip = new InputStreamReader(System.in);
                  BufferedReader br = new BufferedReader(ip);
                  obj1.insertDataIntoSet();
                  Scanner in = new Scanner(System.in);
                  while(num!=3){
                      System.out.println();
                      System.out.println("Please enter your choice");
                      System.out.println("1. To assign keyword to video");
                      System.out.println("2. To Search Video using keyword");
                      System.out.println("3. Exit");
  
                      num=in.nextInt();
  
                      switch(num)
                      {
                      case 1 :
                          System.out.println("Enter Video name[video followed by video number]");
                          String video =br.readLine();
                          if(obj1.videoNames.contains(video))
                              obj1.addKeywords(video);
                          else
                              System.out.println(video+" is not a part of lookup");
                          break;
                      case 2 :
                          System.out.println("Enter partial or complete keyword to search video");
                          String searchKey = br.readLine();
                          searchResults=obj1.search(searchKey);
                          System.out.println(searchResults);
                          break;  
                      case 3:
                          System.out.println("exiting from application");
                          break;  
                      default:
                          System.out.println("Please enter correct choice");
                          break;  
                      }
                  }
              }   
          }
  </code></pre>
  
  <p>Can someone please help to solve the error?
  Here I am not able to run both test function individually they are running fine
  How to run them together</p>