mtedone / podam

PODAM - POjo DAta Mocker
https://mtedone.github.io/podam
MIT License
326 stars 749 forks source link

private and protected fields #313

Closed lowcasz closed 1 year ago

lowcasz commented 1 year ago

I think a lot of fields should be visible by its child class. For example: We have AbstractRandomDataProviderStrategy with private field typeManufacturers I would like to add new typeManufacturer depends on field name. When field name match i want use my custom manufacturer, but if not use the default. In this situation I have not possibility to get typeManufacturers in implementation which extends this abstract class.

daivanov commented 1 year ago

Hi,

This is breaking the data encapsulation. To achieve what you want you should inherit from the default type manufacturer

    @Override
    public String getType(DataProviderStrategy strategy,
            AttributeMetadata attributeMetadata,
            ManufacturingContext manufacturingCtx) {

        if ("myAttr".equals(attributeMetadata.getAttributeName())) {
            String retValue;
            /* Customization here */
            ...
            return retValue;
        } else {
            return super.getType(strategy, attributeMetadata, manufacturingCtx);
        }
    }

and then just replace default manufacturer with custom one

   dataProviderStrategy.addOrReplaceTypeManufacturer(String.class, customManufacturer);

Thanks, Daniil

daivanov commented 1 year ago

Let me know, if there is a need for clarification.

Thanks, Daniil

lowcasz commented 1 year ago

Yes of course. But for me this encapsulation is too strictly. It is abstract class only. I wanted do this, because of standard implementation is generally ok as concept, but attribute strategies are not working there.