<commit_before>require 'test_case_generator/dsl_context'
require 'test_case_generator/indented_writer'

module TestCaseGenerator
  class GeneratorJava
    def can_handle?(source_fn)
      File.extname(source_fn).eql? '.java'
    end

    def write(ctx, source_fn)
      write_skeleton source_fn unless File.exist? source_fn
      write_interface ctx, File.join(File.dirname(source_fn), make_interface_name(source_fn)) + '.java', make_package_name(source_fn)
      write_source ctx, source_fn
    end

    def make_class_name(filename)
      # File.join(File.dirname(source_fn), File.basename(source_fn, File.extname(source_fn))
      File.basename filename, '.*'
    end

    def make_interface_name(filename)
      make_class_name(filename) + 'Generated'
    end

    def make_package_name(filename)
      parts = []
      java_seen = false
      File.absolute_path(File.dirname(filename)).split('/').each do |x|
        parts << x if java_seen
        java_seen = true if x == 'java'
      end

      if parts.empty?
        'com.example'
      else
        parts.join '.'
      end
    end

    def write_skeleton(source_fn)
      class_name = make_class_name(source_fn)
      File.open(source_fn, 'w') do |f|
        writer = IndentedWriter.new f
        writer.puts <<EOS
package #{make_package_name source_fn};

import android.content.Context;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

import java.util.ArrayList;

import static org.junit.Assert.*;

@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 18)
public class #{class_name} implements #{make_interface_name source_fn} {

    @Before
    public void setUp() {
        Robolectric.getForegroundThreadScheduler().reset();
        Robolectric.getForegroundThreadScheduler().pause();
        Robolectric.getBackgroundThreadScheduler().reset();
        Robolectric.getBackgroundThreadScheduler().pause();
    }
<commit_msg>Prevent to remove static import statement if auto-import feature is enabled in Android Studio.<commit_after>require 'test_case_generator/dsl_context'
require 'test_case_generator/indented_writer'

module TestCaseGenerator
  class GeneratorJava
    def can_handle?(source_fn)
      File.extname(source_fn).eql? '.java'
    end

    def write(ctx, source_fn)
      write_skeleton source_fn unless File.exist? source_fn
      write_interface ctx, File.join(File.dirname(source_fn), make_interface_name(source_fn)) + '.java', make_package_name(source_fn)
      write_source ctx, source_fn
    end

    def make_class_name(filename)
      # File.join(File.dirname(source_fn), File.basename(source_fn, File.extname(source_fn))
      File.basename filename, '.*'
    end

    def make_interface_name(filename)
      make_class_name(filename) + 'Generated'
    end

    def make_package_name(filename)
      parts = []
      java_seen = false
      File.absolute_path(File.dirname(filename)).split('/').each do |x|
        parts << x if java_seen
        java_seen = true if x == 'java'
      end

      if parts.empty?
        'com.example'
      else
        parts.join '.'
      end
    end

    def write_skeleton(source_fn)
      class_name = make_class_name(source_fn)
      File.open(source_fn, 'w') do |f|
        writer = IndentedWriter.new f
        writer.puts <<EOS
package #{make_package_name source_fn};

import android.content.Context;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

import java.util.ArrayList;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 18)
public class #{class_name} implements #{make_interface_name source_fn} {

    @Before
    public void setUp() {
        Robolectric.getForegroundThreadScheduler().reset();
        Robolectric.getForegroundThreadScheduler().pause();
        Robolectric.getBackgroundThreadScheduler().reset();
        Robolectric.getBackgroundThreadScheduler().pause();

        // Auto import 機能でimport文が削除されないようにするためのダミー
        assertEquals("dummy", "dummy");
        mock(String.class);
    }

{'fraction_non_alphanumeric': 0.10067997367843826, 'fraction_numerical': 0.000877385391533231, 'mean_word_length': 3.7253886010362693, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2637729', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1410, 'n_words': 276}