<commit_before>/*
 * Copyright 2013-present Facebook, Inc.
 *
 * 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
 *
 *     http://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 com.facebook.buck.jvm.java;

import static org.easymock.EasyMock.createMock;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;

import com.facebook.buck.io.filesystem.ProjectFilesystem;
import com.facebook.buck.rules.SourcePathResolver;
import com.google.common.collect.Lists;
import java.util.Collections;
import org.hamcrest.Matcher;
import org.junit.Test;

public class JavacOptionsTest {

  @Test
  public void buildsAreDebugByDefault() {
    JavacOptions options = createStandardBuilder().build();

    assertOptionFlags(options, hasItem("g"));
  }

  @Test
  public void spoolModeToDiskByDefault() {
    JavacOptions options = createStandardBuilder().build();

    assertThat(options.getSpoolMode(), is(JavacOptions.SpoolMode.INTERMEDIATE_TO_DISK));
  }

  @Test
  public void productionBuildsCanBeEnabled() {
    JavacOptions options = createStandardBuilder().setProductionBuild(true).build();

    assertOptionFlags(options, not(hasItem("g")));
  }

  @Test
  public void testDoesNotSetBootclasspathByDefault() {
    JavacOptions options = createStandardBuilder().build();

    assertOptionsHasNoKey(options, "bootclasspath");
  }

  @Test
  public void canSetBootclasspath() {
    JavacOptions options = createStandardBuilder().setBootclasspath("foo:bar").build();

    assertOptionsHasKeyValue(options, "bootclasspath", "foo:bar");
  }

  @Test
  public void shouldSetTheAnnotationSource() {
    AnnotationProcessingParams params =
        AnnotationProcessingParams.builder()
            .setLegacySafeAnnotationProcessors(Collections.emptySet())
            .setLegacyAnnotationProcessorNames(Collections.singleton("processor"))
            .setProcessOnly(true)
            .build();

    JavacOptions options = createStandardBuilder().setAnnotationProcessingParams(params).build();

    assertOptionFlags(options, hasItem("proc:only"));
  }

  @Test
  public void shouldAddAllAddedAnnotationProcessors() {
    AnnotationProcessingParams params =
        AnnotationProcessingParams.builder()
            .setLegacyAnnotationProcessorDeps(Collections.emptySet())
            .setLegacyAnnotationProcessorNames(Lists.newArrayList("myproc", "theirproc"))
            .setProcessOnly(true)
            .build();

    JavacOptions options = createStandardBuilder().setAnnotationProcessingParams(params).build();

    assertOptionsHasKeyValue(options, "processor", "myproc,theirproc");<commit_msg>Fix JavacOptionsTest<commit_after>/*
 * Copyright 2013-present Facebook, Inc.
 *
 * 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
 *
 *     http://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 com.facebook.buck.jvm.java;

import static org.easymock.EasyMock.createMock;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;

import com.facebook.buck.io.filesystem.ProjectFilesystem;
import com.facebook.buck.rules.SourcePathResolver;
import com.facebook.buck.testutil.FakeProjectFilesystem;
import com.google.common.collect.Lists;
import java.util.Collections;
import org.hamcrest.Matcher;
import org.junit.Test;

public class JavacOptionsTest {

  @Test
  public void buildsAreDebugByDefault() {
    JavacOptions options = createStandardBuilder().build();

    assertOptionFlags(options, hasItem("g"));
  }

  @Test
  public void spoolModeToDiskByDefault() {
    JavacOptions options = createStandardBuilder().build();

    assertThat(options.getSpoolMode(), is(JavacOptions.SpoolMode.INTERMEDIATE_TO_DISK));
  }

  @Test
  public void productionBuildsCanBeEnabled() {
    JavacOptions options = createStandardBuilder().setProductionBuild(true).build();

    assertOptionFlags(options, not(hasItem("g")));
  }

  @Test
  public void testDoesNotSetBootclasspathByDefault() {
    JavacOptions options = createStandardBuilder().build();

    assertOptionsHasNoKey(options, "bootclasspath");
  }

  @Test
  public void canSetBootclasspath() {
    JavacOptions options = createStandardBuilder().setBootclasspath("foo:bar").build();

    assertOptionsHasKeyValue(options, "bootclasspath", "foo:bar");
  }

  @Test
  public void shouldSetTheAnnotationSource() throws InterruptedException {
    AnnotationProcessingParams params =
        AnnotationProcessingParams.builder()
            .setLegacySafeAnnotationProcessors(Collections.emptySet())
            .setLegacyAnnotationProcessorNames(Collections.singleton("processor"))
            .setProcessOnly(true)
            .setProjectFilesystem(FakeProjectFilesystem.createJavaOnlyFilesystem())
            .build();

    JavacOptions options = createStandardBuilder().setAnnotationProcessingParams(params).build();

    assertOptionFlags(options, hasItem("proc:only"));
  }

  @Test
  public void shouldAddAllAddedAnnotationProcessors() throws InterruptedException {
    AnnotationProcessingParams params =
        AnnotationProcessingParams.builder()
            .setLegacyAnnotationProcessorDeps(Collections.emptySet())
            .setLegacyAnnotationProcessorNames(Lists.newArrayList("myproc", "theirproc"))
            .setProcessOnly(true)
            .setProjectFilesystem(FakeProjectFilesystem.createJavaOnlyFilesystem())
            .build();

    JavacOptions options = createStandardBuilder().setAnnotationProcessingParams(params).build();

    assertOptionsHasKeyValue(options, "processor", "myproc,theirproc");
{'fraction_non_alphanumeric': 0.09728373191614999, 'fraction_numerical': 0.0023619722468261, 'mean_word_length': 4.645833333333333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3310319', 'n_tokens_mistral': 1867, 'n_tokens_neox': 1801, 'n_words': 410}