<commit_before>/*
 * Bach - Java Shell Builder
 * Copyright (C) 2019 <NAME>
 *
 * 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 test.modules;

import static java.lang.module.ModuleDescriptor.Requires.Modifier.MANDATED;
import static java.lang.module.ModuleDescriptor.newModule;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.junit.jupiter.api.DynamicTest.dynamicTest;

import de.sormuras.bach.Bach;
import java.lang.module.ModuleDescriptor;
import java.lang.module.ModuleFinder;
import java.lang.module.ModuleReference;
import java.util.List;
import java.util.Set;
import java.util.spi.ToolProvider;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestFactory;

class ModuleSystemTests {

  @Test
  void testModuleIsNamedAndTheNameIsTestModules() {
    assumeTrue(getClass().getModule().isNamed(), "not running on the module path");
    assertEquals("test.modules", getClass().getModule().getName());
  }

  @Test
  void bachModule() {
    var actual = Bach.class.getModule().getDescriptor();
    assumeTrue(actual != null, "not running on the module path");
    // exploded and jarred module fixtures
    var expected =
        newModule("de.sormuras.bach")
            .exports("de.sormuras.bach")
            .exports("de.sormuras.bach.project")
            .packages(Set.of("de.sormuras.bach.task", "de.sormuras.bach.util"))
            .uses(ToolProvider.class.getName())
        // .provides(ToolProvider.class.getName(), List.of("de.sormuras.bach.BachToolProvider"))
        ;
    // requires may contain compiled version
    if (Runtime.version().feature() <= 11) {
      var version = Object.class.getModule().getDescriptor().version().orElseThrow();
      expected
          .requires(Set.of(MANDATED), "java.base", version)
          .requires(Set.of(), "java.compiler", version)<commit_msg>Detect compiled version of requires directives<commit_after>/*
 * Bach - Java Shell Builder
 * Copyright (C) 2019 <NAME>
 *
 * 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 test.modules;

import static java.lang.module.ModuleDescriptor.Requires.Modifier.MANDATED;
import static java.lang.module.ModuleDescriptor.newModule;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.junit.jupiter.api.DynamicTest.dynamicTest;

import de.sormuras.bach.Bach;
import java.lang.module.ModuleDescriptor;
import java.lang.module.ModuleFinder;
import java.lang.module.ModuleReference;
import java.util.List;
import java.util.Set;
import java.util.spi.ToolProvider;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestFactory;

class ModuleSystemTests {

  @Test
  void testModuleIsNamedAndTheNameIsTestModules() {
    assumeTrue(getClass().getModule().isNamed(), "not running on the module path");
    assertEquals("test.modules", getClass().getModule().getName());
  }

  @Test
  void bachModule() {
    var actual = Bach.class.getModule().getDescriptor();
    assumeTrue(actual != null, "not running on the module path");
    // exploded and jarred module fixtures
    var expected =
        newModule("de.sormuras.bach")
            .exports("de.sormuras.bach")
            .exports("de.sormuras.bach.project")
            .packages(Set.of("de.sormuras.bach.task", "de.sormuras.bach.util"))
            .uses(ToolProvider.class.getName())
        // .provides(ToolProvider.class.getName(), List.of("de.sormuras.bach.BachToolProvider"))
        ;
    // requires may contain compiled version
    var requiresWithVersion =
        actual.requires().stream()
            .filter(requires -> requires.name().equals("java.base"))
            .findFirst()
            .orElseThrow()
            .compiledVersion();
    if (requiresWithVersion.isPresent()) {
      var version = requiresWithVersion.orElseThrow();
      expected
          .requires(Set.of(MANDATED), "java.base", version)
          .requires(Set.of(), "java.compiler", version)
{'fraction_non_alphanumeric': 0.11742983751846381, 'fraction_numerical': 0.0033234859675036928, 'mean_word_length': 3.76429199648197, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3833890', 'n_tokens_mistral': 1548, 'n_tokens_neox': 1527, 'n_words': 395}