Duplicate Check in Java
<p>I am writing a small integration piece to to retrive the testcases from TestCase Management tool in java, in which i have the following scenarios:-</p>

<p>1) I have testcase which is “failed”, that time I am checking whether there is any defect which is already exists in the Defect management tool for the failed testcase using the testcase name , because the testcase name and the defect name are same in our case. 
If not I am logging the new defect. This is fine.</p>

<p>2) In another case, I have testcase which is “Passed” at the first time, for that also I am checking the whether there are any duplicate defect is present in the Defect management tool , eventhough I am not going to log any defect. </p>

<p>This I am doing because, I don’t know whether the testcase is “Pass” or “Fail” in the first attempt or not. Hence I am doing this mandatory check , to see whether the duplicate defect exists or not for both “pass” and “fail” testcase. 
I know that it is wrong to check the duplicate existence of the defect for the “pass” testcase. But there is no option I have. Is there any way we can ignore calling duplicate existence of the defect method if the testcase is “passed”?
I want your guys opinion on this. </p>

<p>This is the code which i have:-</p>

<pre><code>     private int NOT_TESTED = 0;
     private int PASSED_1 = 0;
     private int PASSED_2 = 0;
     private int FAILED =0;

     private String testStatus = "pass"; // will be fetched dynamically
     private void execute(){
      if(testStatus.equalsIgnoreCase("fail")){
       //FAILED--;
       FAILED = FAILED + 1;
       System.out.println("the failed value is:"+FAILED);
      }else if(testStatus.equalsIgnoreCase("pass")){// first attempt
       PASSED_1 = PASSED_1 + 1;
       System.out.println("the Passed_1 value is:"+PASSED_1);
       if(PASSED_1 == 1){
        System.out.println("Passed in the first attempt, hence no need to create a defect");
       } 
      }else if(testStatus.equalsIgnoreCase("pass") &amp;&amp; FAILED ==1){// second attempt
       PASSED_2 =  PASSED_2+1;
       System.out.println("the Passed_2 value is:"+PASSED_2);
       if(PASSED_2 ==1){
        System.out.println("Passed in the second attempt, create a defect");
        // logic to create a new defect
       }
      }else {
       System.out.println("The test not tested");
      }

 }
</code></pre>

<p>This code is not working as it always go to the first pass attempt state, hence please do provide a solution to find if the testcase is passed in the second attempt (FAIL->PASS) so that we can take appropriate action on this.</p>

<p>Thanks in advance. </p>
