From 86dedadb76d30e1305ad310ae21b566b814c5734 Mon Sep 17 00:00:00 2001 From: Hariharan Subramanian Date: Thu, 8 Jun 2023 16:35:18 +0000 Subject: [PATCH] UT for detect default method --- cmd/create_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/cmd/create_test.go b/cmd/create_test.go index 58380f2b..b1cfa726 100644 --- a/cmd/create_test.go +++ b/cmd/create_test.go @@ -227,3 +227,45 @@ func getAllDeploymentFiles(src string) (error, []string) { }) return err, deploymentFiles } + +func TestDetectDefaults(t *testing.T) { + ioutil.WriteFile("build.gradle", []byte("sourceCompatibility = '11'\ntargetCompatibility = '12'"), 0644) + mockCC := &createCmd{} + mockDraftConfig := &config.DraftConfig{} + mockCC.detectDefaults(mockDraftConfig, "gradlew") + assert.Equal(t, 2, len(mockDraftConfig.DetectedDefaults)) + assert.Equal(t, "VERSION", mockDraftConfig.DetectedDefaults[0].Name) + assert.Equal(t, "11-jre", mockDraftConfig.DetectedDefaults[0].Value) + assert.Equal(t, "BUILDERVERSION", mockDraftConfig.DetectedDefaults[1].Name) + assert.Equal(t, "jdk12", mockDraftConfig.DetectedDefaults[1].Value) + os.Remove("build.gradle") +} + +func TestDetectDefaultsNoGradle(t *testing.T) { + mockCC := &createCmd{} + mockDraftConfig := &config.DraftConfig{} + mockCC.detectDefaults(mockDraftConfig, "maven") + assert.Equal(t, 0, len(mockDraftConfig.DetectedDefaults)) +} + +func TestDetectDefaultsNoSourceComptability(t *testing.T) { + ioutil.WriteFile("build.gradle", []byte("targetCompatibility = '12'"), 0644) + mockCC := &createCmd{} + mockDraftConfig := &config.DraftConfig{} + mockCC.detectDefaults(mockDraftConfig, "gradlew") + assert.Equal(t, 1, len(mockDraftConfig.DetectedDefaults)) + assert.Equal(t, "BUILDERVERSION", mockDraftConfig.DetectedDefaults[0].Name) + assert.Equal(t, "jdk12", mockDraftConfig.DetectedDefaults[0].Value) + os.Remove("build.gradle") +} + +func TestDetectDefaultsNoTargetComptability(t *testing.T) { + ioutil.WriteFile("build.gradle", []byte("sourceCompatibility = '11'"), 0644) + mockCC := &createCmd{} + mockDraftConfig := &config.DraftConfig{} + mockCC.detectDefaults(mockDraftConfig, "gradlew") + assert.Equal(t, 1, len(mockDraftConfig.DetectedDefaults)) + assert.Equal(t, "VERSION", mockDraftConfig.DetectedDefaults[0].Name) + assert.Equal(t, "11-jre", mockDraftConfig.DetectedDefaults[0].Value) + os.Remove("build.gradle") +}