package test.integration;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertLinesMatch;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.github.sormuras.bach.Bach;
import com.github.sormuras.bach.Base;
import com.github.sormuras.bach.Command;
import com.github.sormuras.bach.Recording;
import java.util.List;
import java.util.spi.ToolProvider;
import org.junit.jupiter.api.Test;

class BachTests {
  @Test
  void defaults() {
    var bach = new Bach();
    // components
    assertNotNull(bach.project());
    assertNotNull(bach.browser());
    assertTrue(bach.recordings().isEmpty());
    // compute
    assertTrue(bach.computeExternalModuleUri("java.base").isEmpty());
    assertEquals("foo@0.jar", bach.computeMainJarFileName("foo"));
    assertEquals("jar", bach.computeToolProvider("jar").name());
    assertEquals("javac", bach.computeToolProvider("javac").name());
    assertEquals("javadoc", bach.computeToolProvider("javadoc").name());
    var tools = List.of("jar", "javac", "javadoc", "javap", "jdeps", "jlink", "jmod", "jpackage");
    assertTrue(bach.computeToolProviders().map(ToolProvider::name).toList().containsAll(tools));
  }

  @Test
  void print() {
    var bach = new Bach(Base.ofSystem(), silent -> {});

    bach.run(Command.of("print").add("10", "PRINT 'HELLO WORLD'"));
    bach.run(ToolProvider.findFirst("print").orElseThrow(), List.of("20", "PRINT 20"));
    bach.run(new PrintToolProvider("30 GOTO 10"));
    bach.run(new PrintToolProvider(true, "END.", 0));

    assertLinesMatch(
        """
            10 PRINT 'HELLO WORLD'
            20 PRINT 20
            30 GOTO 10
            END.
            """
            .lines(),
        bach.recordings().stream().map(Recording::output));
  }
}

@@ -208,16 +208,77 @@
 otNull;%0A
+import static org.junit.jupiter.api.Assertions.assertThrows;%0A
 import s
@@ -328,16 +328,16 @@
 rtTrue;%0A
-
 %0Aimport 
@@ -512,16 +512,57 @@
 l.List;%0A
+import java.util.NoSuchElementException;%0A
 import j
@@ -848,36 +848,74 @@
 pute%0A    assertT
-rue(
+hrows(NoSuchElementException.class, () -%3E 
 bach.computeExte
@@ -940,26 +940,16 @@
 a.base%22)
-.isEmpty()
 );%0A    a

Update test assertion