<commit_before>package lib

import (
	"github.com/rafecolton/go-fileutils"
	"github.com/stretchr/testify/assert"
	"io/ioutil"
	"os"
	"path"
	"strings"
	"testing"
	"github.com/alexcesaro/log/golog"
	"github.com/alexcesaro/log"
)

func TestDetectionOfMavenWrapper(t *testing.T) {
	setup()
	defer cleanup()

	content := "#!/bin/sh\necho -n x"
	ioutil.WriteFile("./mvnw", []byte(content), 0700)

	maven := initMaven()
	err := maven.DetermineCommand()

	assert.Nil(t, err)
	assert.Equal(t, maven.command, "./mvnw")
}

func TestMavenNotFound(t *testing.T) {
	setup()
	defer cleanup()

	os.Setenv("PATH", "")

	maven := initMaven()
	err := maven.DetermineCommand()

	assert.Error(t, err)
}

func TestMavenWrapperFound(t *testing.T) {
	setup()
	defer cleanup()

	os.Setenv("PATH", ".")
	content := "#!/bin/sh\necho -n x"
	ioutil.WriteFile("mvnw", []byte(content), 0700)

	maven := initMaven()

	// action
	err := maven.DetermineCommand()

	assert.Nil(t, err)
	assert.Equal(t, maven.command, "./mvnw")
}

func TestMavenParentPomUpdate(t *testing.T) {
	maven := setupWithTestProject("simple-parent-update")
	defer cleanup()

	// action
	updateMessage, err := maven.UpdateParent()

	assert.Nil(t, err)
	assert.NotZero(t, updateMessage)
	assert.True(t, strings.HasPrefix(updateMessage, "Updating parent from 1.3.7.RELEASE to "), "but was : " + updateMessage)
}

func initMaven() *Maven {
	logger := *golog.New(os.Stderr, log.Debug)
	maven := NewMaven(logger)
	return maven
}

func setupWithTestProject(testProjectName string) *Maven {
	setup()
	sourcePath := path.Dir(temporaryDirectoryForTests.Cwd + "/../test-projects/" + testProjectName)
	if err := fileutils.CpR(sourcePath, "x"); err != nil {
		panic(err)
	}
	if err := os.Chdir("x/" + testProjectName); err != nil {
		panic(err)
	}

	maven := initMaven()
	err := maven.DetermineCommand()
	if err != nil {
		panic(err)
	}

	return maven
}<commit_msg>cleanup<commit_after>package lib

import (
	"github.com/rafecolton/go-fileutils"
	"github.com/stretchr/testify/assert"
	"io/ioutil"
	"os"
	"path"
	"strings"
	"testing"
	"github.com/alexcesaro/log/golog"
	"github.com/alexcesaro/log"
)

var maven *Maven

func init() {
	logger := *golog.New(os.Stderr, log.Debug)
	maven = NewMaven(logger)
}

func TestDetectionOfMavenWrapper(t *testing.T) {
	setup()
	defer cleanup()

	content := "#!/bin/sh\necho -n x"
	ioutil.WriteFile("./mvnw", []byte(content), 0700)

	err := maven.DetermineCommand()

	assert.Nil(t, err)
	assert.Equal(t, maven.command, "./mvnw")
}

func TestMavenNotFound(t *testing.T) {
	setup()
	defer cleanup()

	os.Setenv("PATH", "")

	err := maven.DetermineCommand()

	assert.Error(t, err)
}

func TestMavenWrapperFound(t *testing.T) {
	setup()
	defer cleanup()

	os.Setenv("PATH", ".")
	content := "#!/bin/sh\necho -n x"
	ioutil.WriteFile("mvnw", []byte(content), 0700)

	// action
	err := maven.DetermineCommand()

	assert.Nil(t, err)
	assert.Equal(t, maven.command, "./mvnw")
}

func TestMavenParentPomUpdate(t *testing.T) {
	maven := setupWithTestProject(t, "simple-parent-update")
	defer cleanup()

	// action
	updateMessage, err := maven.UpdateParent()

	assert.Nil(t, err)
	assert.NotZero(t, updateMessage)
	assert.True(t, strings.HasPrefix(updateMessage, "Updating parent from 1.3.7.RELEASE to "), "but was : " + updateMessage)
}

func setupWithTestProject(t *testing.T, testProjectName string) *Maven {
	setup()
	sourcePath := path.Dir(temporaryDirectoryForTests.Cwd + "/../test-projects/" + testProjectName)
	if err := fileutils.CpR(sourcePath, "x"); err != nil {
		panic(err)
	}
	if err := os.Chdir("x/" + testProjectName); err != nil {
		panic(err)
	}

	if _, exists := os.LookupEnv("JAVA_HOME"); !exists {
		t.Skip("missing JAVA_HOME env, try again this test in on the shell")
	}

	err := maven.DetermineCommand()
	if err != nil {
		panic(err)
	}

	return maven
}
{'fraction_non_alphanumeric': 0.17276529012023, 'fraction_numerical': 0.00575013068478829, 'mean_word_length': 4.390140845070422, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3577258', 'n_tokens_mistral': 1549, 'n_tokens_neox': 1472, 'n_words': 288}