package test.assertion;

import org.testng.Assert;
import org.testng.annotations.Test;
import org.testng.asserts.IAssert;
import org.testng.asserts.SoftAssert;

import java.util.ArrayList;
import java.util.Collection;

public class SoftAssertTest {

  @Test
  public void testOnSucceedAndFailureCalled() throws Exception {
    final Collection<IAssert> succeed = new ArrayList<>();
    final Collection<IAssert> failures = new ArrayList<>();
    final SoftAssert sa = new SoftAssert() {
      @Override
      public void onAssertSuccess(IAssert assertCommand) {
        succeed.add(assertCommand);
      }

      @Override
      public void onAssertFailure(IAssert assertCommand, AssertionError ex) {
        failures.add(assertCommand);
      }
    };
    sa.assertTrue(true);
    sa.assertTrue(false);
    Assert.assertEquals(succeed.size(), 1, succeed.toString());
    Assert.assertEquals(failures.size(), 1, failures.toString());
  }

  @Test
  public void testAssertAllCount() throws Exception {
    final SoftAssert sa = new SoftAssert();
    sa.assertTrue(true);
    sa.assertTrue(false);
    try {
      sa.assertAll();
      Assert.fail("Exception expected");
    } catch (AssertionError e) {
      final String message = e.getMessage();
      Assert.assertEquals(message.split("\r?\n").length, 2, message);
    }
  }
}

@@ -994,29 +994,58 @@
 ption %7B%0A    
-final
+String message = %22My message%22;%0A   
  SoftAssert 
@@ -1111,24 +1111,33 @@
 rtTrue(false
+, message
 );%0A    try %7B
@@ -1243,28 +1243,22 @@
     
-final String message
+String%5B%5D lines
  = e
@@ -1270,16 +1270,31 @@
 essage()
+.split(%22%5Cr?%5Cn%22)
 ;%0A      
@@ -1317,50 +1317,130 @@
 als(
-message.split(%22%5Cr?%5Cn%22).length, 2, 
+lines.length, 2);%0A      lines%5B1%5D = lines%5B1%5D.replaceFirst(message, %22%22);%0A      Assert.assertFalse(lines%5B1%5D.contains(
 message)
 ;%0A  
@@ -1431,24 +1431,25 @@
 ins(message)
+)
 ;%0A    %7D%0A  %7D%0A

Add test case for #784