Fixture-Factory lib, Index 55663 out of Bounds for length 2187

Asked

Viewed 163 times

0

I’m ultilizing the lib Fixture-Factory to create templates for my tests, but working with it, I got the following error!

Index 55663 out of bounds for length 2187

erro fixture-factory

those are my models:

Cityprop: Class with generic attributes for the city.

@Data
@AllArgsConstructor
public abstract class CityProp {

    private String name;

}

Citytour: Class with specific attributes for a given task, extending Cityprop

@Data
@EqualsAndHashCode(callSuper = true)
public class CityTour extends CityProp{

    private Integer index;

    public CityTour(String name, Integer index) {
        super(name);
        this.index = index;
    }
}

Tourprop: Class where has all generic attributes for ride, as can be seen the attribute for Cities are in a List

@Data
public abstract class TourProp {

    private Long id;
    private String code;
    private String name;
    private LocalDate startDate;
    private LocalDate endDate;
    private Integer days;
    private BigDecimal price;
    private String currency;
    private List<CityTour> cities;
    private Set<String> categories;
    private Integer amountCities;
    private Customization customization;
    private List<String> links;
    private String rateToken;

}

Tour: Specific class, created to instantiate the Ride with generic attributes

public class Tour extends TourProp{
}

Already with the templates created, I also have your templates, which are to generate the class instance.

Citytourtemplateloader

public class CityTourTemplateLoader implements TemplateLoader {

    @Override
    public void load() {
        Fixture.of(CityTour.class).addTemplate("suzuka", new Rule(){{
            add("name", "suzuka");
            add("index", 0);
        }});

        Fixture.of(CityTour.class).addTemplate("roma", new Rule(){{
            add("name", "roma");
            add("index", 1);
        }});

        Fixture.of(CityTour.class).addTemplate("paris", new Rule(){{
            add("name", "paris");
            add("index", 2);
        }});
    }
}

Tourtemplateloader

public class TourTemplateLoader implements TemplateLoader {

    @Override
    public void load() {

        Fixture.of(Tour.class).addTemplate("complete", new Rule() {{
            add("id", 1L);
            add("code", "1");
            add("name", "Europa Sim");
            add("startDate", LocalDate.of(2019, 2, 3));
            add("endDate", LocalDate.of(2019, 2, 13));
            add("days", 18);
            add("price", new BigDecimal(1000));
            add("currency", "EUR");
            add("cities", has(3).of(CityTour.class, "suzuka", "roma", "paris"));
            add("categories", new HashSet<>(Collections.singletonList("Premium")));
            add("amountCities", 1);
            add("customization", one(Customization.class, "allTrue"));
            add("links", Arrays.asList("https://image/123", "https://image/abc"));
            add("rateToken", "a");
        }});

    }

}

When trying to run the process on this particular line:

add("cities", has(3).of(CityTour.class, "suzuka", "roma", "paris"));

The error quoted and returned.

1 answer

0

So, after an analysis into the source code of Fixture-Factory, found that the problem was the lack of the constructor without class parameters Citytour adding the notation @Noargsconstructor the problem was solved. the same then remained so:

Cityprop

@Data
@NoArgsConstructor
@AllArgsConstructor
public abstract class CityProp {

    private String name;

}

Citytour

@Data
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@NoArgsConstructor
public class CityTour extends CityProp{

    private Integer index;

    public CityTour(String name, Integer index) {
        super(name);
        this.index = index;
    }
}

Probably the same is necessary to make a first class setting.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.