<commit_before>/*
Copyright 2017 Google 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

    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.
 */m

package com.google.androidstudiopoet.converters

import com.google.androidstudiopoet.input.AndroidModuleConfig
import com.google.androidstudiopoet.input.BuildTypeConfig
import com.google.androidstudiopoet.input.FlavorConfig
import com.google.androidstudiopoet.input.ModuleConfig
import com.google.androidstudiopoet.models.ConfigPOJO
import com.google.androidstudiopoet.testutils.assertEquals
import com.google.androidstudiopoet.testutils.assertOn
import com.google.androidstudiopoet.testutils.mock
import com.nhaarman.mockito_kotlin.whenever
import org.junit.Before
import org.junit.Test

private const val PROJECT_NAME = "project name"
private const val ROOT = "root"
private const val NUMBER_OF_PURE_MODULES = 2
private const val NUMBER_OF_ANDROID_MODULES = 2

class ConfigPojoToProjectConfigConverterTest {
    private val configPojoToModuleConfigConverter: ConfigPojoToModuleConfigConverter = mock()
    private val configPojoToFlavourConfigsConverter: ConfigPojoToFlavourConfigsConverter = mock()
    private val configPojoToBuildTypeConfigsConverter: ConfigPojoToBuildTypeConfigsConverter = mock()
    private val configPojoToAndroidModuleConfigConverter: ConfigPojoToAndroidModuleConfigConverter = mock()

    private val moduleConfig0: ModuleConfig = mock()
    private val moduleConfig1: ModuleConfig = mock()

    private val androidModuleConfig0: AndroidModuleConfig = mock()
    private val androidModuleConfig1: AndroidModuleConfig = mock()

    private val flavours: List<FlavorConfig> = mock()
    private val buildTypes: List<BuildTypeConfig> = mock()

    private val configPojo = ConfigPOJO().apply {
        projectName = PROJECT_NAME
        root = ROOT
        numModules = NUMBER_OF_PURE_MODULES
        androidModules = "$NUMBER_OF_ANDROID_MODULES"
    }

    private val configPojoToProjectConfigConverter = ConfigPojoToProjectConfigConverter(configPojoToModuleConfigConverter,
            configPojoToFlavourConfigsConverter, configPojoToBuildTypeConfigsConverter, configPojoToAndroidModuleConfigConverter)

    @Before
    fun setUp() {
        whenever(configPojoToModuleConfigConverter.convert(configPojo, 0)).thenReturn(moduleConfig0)
        whenever(configPojoToModuleConfigConverter.convert(configPojo, 1)).thenReturn(moduleConfig1)
        whenever(configPojoToAndroidModuleConfigConverter.convert(configPojo, 0, flavours, buildTypes)).thenReturn(androidModuleConfig0)
        whenever(configPojoToAndroidModuleConfigConverter.convert(configPojo, 1, flavours, buildTypes)).thenReturn(androidModuleConfig1)
        whenever(configPojoToFlavourConfigsConverter.convert(configPojo)).thenReturn(flavours)
        whenever(configPojoToBuildTypeConfigsConverter.convert(configPojo)).thenReturn(buildTypes)
    }

    @Test
    fun `convert should pass projectName, root and create module configs for ProjectConfig`() {
        val projectConfig = configPojoToProjectConfigConverter.convert(configPojo)
        assertOn(projectConfig) {
            projectName.assertEquals(PROJECT_NAME)
            root.assertEquals(ROOT)
            pureModuleConfigs.assertEquals(listOf(moduleConfig0, moduleConfig1))
            androidModuleConfigs.assertEquals(listOf(androidModuleConfig0, androidModuleConfig1))
        }
    }
}<commit_msg>fix tests<commit_after>/*
Copyright 2017 Google 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

    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 com.google.androidstudiopoet.converters

import com.google.androidstudiopoet.input.AndroidModuleConfig
import com.google.androidstudiopoet.input.BuildTypeConfig
import com.google.androidstudiopoet.input.FlavorConfig
import com.google.androidstudiopoet.input.ModuleConfig
import com.google.androidstudiopoet.models.ConfigPOJO
import com.google.androidstudiopoet.testutils.assertEquals
import com.google.androidstudiopoet.testutils.assertOn
import com.google.androidstudiopoet.testutils.mock
import com.nhaarman.mockito_kotlin.whenever
import org.junit.Before
import org.junit.Test

private const val PROJECT_NAME = "project name"
private const val ROOT = "root"
private const val NUMBER_OF_PURE_MODULES = 2
private const val NUMBER_OF_ANDROID_MODULES = 2

class ConfigPojoToProjectConfigConverterTest {
    private val configPojoToModuleConfigConverter: ConfigPojoToModuleConfigConverter = mock()
    private val configPojoToFlavourConfigsConverter: ConfigPojoToFlavourConfigsConverter = mock()
    private val configPojoToBuildTypeConfigsConverter: ConfigPojoToBuildTypeConfigsConverter = mock()
    private val configPojoToAndroidModuleConfigConverter: ConfigPojoToAndroidModuleConfigConverter = mock()

    private val moduleConfig0: ModuleConfig = mock()
    private val moduleConfig1: ModuleConfig = mock()

    private val androidModuleConfig0: AndroidModuleConfig = mock()
    private val androidModuleConfig1: AndroidModuleConfig = mock()

    private val flavours: List<FlavorConfig> = mock()
    private val buildTypes: List<BuildTypeConfig> = mock()

    private val configPojo = ConfigPOJO().apply {
        projectName = PROJECT_NAME
        root = ROOT
        numModules = NUMBER_OF_PURE_MODULES
        androidModules = "$NUMBER_OF_ANDROID_MODULES"
    }

    private val configPojoToProjectConfigConverter = ConfigPojoToProjectConfigConverter(configPojoToModuleConfigConverter,
            configPojoToFlavourConfigsConverter, configPojoToBuildTypeConfigsConverter, configPojoToAndroidModuleConfigConverter)

    @Before
    fun setUp() {
        whenever(configPojoToModuleConfigConverter.convert(configPojo, 0)).thenReturn(moduleConfig0)
        whenever(configPojoToModuleConfigConverter.convert(configPojo, 1)).thenReturn(moduleConfig1)
        whenever(configPojoToAndroidModuleConfigConverter.convert(configPojo, 0, flavours, buildTypes)).thenReturn(androidModuleConfig0)
        whenever(configPojoToAndroidModuleConfigConverter.convert(configPojo, 1, flavours, buildTypes)).thenReturn(androidModuleConfig1)
        whenever(configPojoToFlavourConfigsConverter.convert(configPojo)).thenReturn(flavours)
        whenever(configPojoToBuildTypeConfigsConverter.convert(configPojo)).thenReturn(buildTypes)
    }

    @Test
    fun `convert should pass projectName, root and create module configs for ProjectConfig`() {
        val projectConfig = configPojoToProjectConfigConverter.convert(configPojo)
        assertOn(projectConfig) {
            projectName.assertEquals(PROJECT_NAME)
            root.assertEquals(ROOT)
            pureModuleConfigs.assertEquals(listOf(moduleConfig0, moduleConfig1))
            androidModuleConfigs.assertEquals(listOf(androidModuleConfig0, androidModuleConfig1))
        }
    }
}
{'fraction_non_alphanumeric': 0.06314416177429875, 'fraction_numerical': 0.0067840834964122635, 'mean_word_length': 5.335537190082644, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3026270', 'n_tokens_mistral': 2109, 'n_tokens_neox': 2049, 'n_words': 480}