I have written below code in Kotlin for the different values of "isOlListingEnabled" as True, False and null. I got the comment on my PR as "Instead of making new method we can pass value for isOlListingEnabled in method getFlightsOpinionLabModel with default value true or false or null". Can someone please help me to write the below code in such a way that I can handle all three (true, false and null) values in same method.
package com.abc.api.flights.unit.fixture
import com.abc.api.flights.models.domain.TripType
import com.abc.api.flights.models.ui.opinionlab.FlightsOpinionLabModel
import java.util.UUID
object FlightsOpinionLabModelFixture {
fun getFlightsOpinionLabModel(tripType: TripType): FlightsOpinionLabModel = FlightsOpinionLabModel(
siteName = "www.abc.com",
langId = 1033,
duaid = UUID.randomUUID(),
expId = null,
tripType = tripType,
isOlListingEnabled = true
)
fun getFlightsOpinionLabModelWithoutListingEnabled(tripType: TripType): FlightsOpinionLabModel = FlightsOpinionLabModel(
siteName = "www.abc.com",
langId = 1033,
duaid = UUID.randomUUID(),
expId = null,
tripType = tripType,
isOlListingEnabled = false
)
fun getFlightsOpinionLabModelWitListingEnabledNull(tripType: TripType): FlightsOpinionLabModel = FlightsOpinionLabModel(
siteName = "www.abc.com",
langId = 1033,
duaid = UUID.randomUUID(),
expId = null,
tripType = tripType,
isOlListingEnabled = null
)
}
your FlightsOpinionLabModelFixture
can be simplified in such way:
object FlightsOpinionLabModelFixture {
fun getFlightsOpinionLabModel(tripType: TripType, isOlListingEnabled: Boolean? = true): FlightsOpinionLabModel = FlightsOpinionLabModel(
siteName = "www.abc.com",
langId = 1033,
duaid = UUID.randomUUID(),
expId = null,
tripType = tripType,
isOlListingEnabled = isOlListingEnabled
)
}
invokation example:
// FlightsOpinionLabModelFixture.getFlightsOpinionLabModelWithoutListingEnabled(type)
FlightsOpinionLabModelFixture.getFlightsOpinionLabModel(type, isOlListingEnabled = false)