/*
 * Bach - Java Shell Builder
 * Copyright (C) 2019 Christian Stein
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package it;

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

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ServiceLoader;
import java.util.spi.ToolProvider;
import org.junit.jupiter.api.Test;

class ToolProviderTests {

  @Test
  void findBachUsingToolProviderAPI() {
    var bach =
        ServiceLoader.load(ToolProvider.class, getClass().getClassLoader()).stream()
            .map(ServiceLoader.Provider::get)
            .filter(provider -> provider.name().equals("bach"))
            .findFirst();
    assertTrue(bach.isPresent(), "Tool 'bach' not found!");

    var out = new PrintWriter(new StringWriter());
    var err = new PrintWriter(new StringWriter());
    assertEquals(0, bach.get().run(out, err, "version"));
    assertEquals(1, bach.get().run(out, err, "?"));
  }
}

@@ -980,23 +980,21 @@
 sing
-ToolProviderAPI
+ServiceLoader
 () %7B
@@ -1268,34 +1268,605 @@
 ), %22
-Tool 'bach' not found!
+Service 'bach' not found!%22);%0A  %7D%0A%0A  @Test%0A  void providerIsMemberOfNamedModule() %7B%0A    var bach = ToolProvider.findFirst(%22bach%22).orElseThrow();%0A    assertEquals(%22de.sormuras.bach%22, bach.getClass().getModule().getName());%0A  %7D%0A%0A  @Test%0A  void runVersionYieldsZero() %7B%0A    var bach = ToolProvider.findFirst(%22bach%22).orElseThrow();%0A    var out = new PrintWriter(new StringWriter());%0A    var err = new PrintWriter(new StringWriter());%0A    assertEquals(0, bach.run(out, err, %22version
 %22)
+)
 ;%0A
+  %7D%0A%0A  @Test%0A  void runUnsupportedArgumentYieldsOne() %7B%0A    var bach = ToolProvider.findFirst(%22bach%22).orElseThrow();
 %0A   
@@ -1968,66 +1968,8 @@
 ));%0A
-    assertEquals(0, bach.get().run(out, err, %22version%22));%0A
     
@@ -1993,14 +1993,8 @@
 ach.
-get().
 run(

Split test into dedicated methods