meanbeanlib / meanbean

Automated JavaBean Testing
Apache License 2.0
15 stars 3 forks source link

Strange behaviour concatenating verifications #8

Closed Ichigo85 closed 4 years ago

Ichigo85 commented 4 years ago

Related to #7 I modified my tests to avoid testEquals, waiting for the bug to be fixed. The strange behaviour is this: The same bean as on issue #6 gives me the error org.meanbean.factories.ObjectCreationException: Failed to create a value for property [data]. as if the factory is not registered, but my test is exactly like the one you suggested me

BeanVerifier.forClass(MyBean.class)
    .editSettings()
    .registerFactory(MessageData.class, () -> {
        RandomValueGenerator randomValueGenerator = RandomValueGenerator.getInstance();
        byte[] randomBytes = randomValueGenerator.nextBytes(100);
        return new MessageData(randomBytes);
    })
    .edited()
    .verify();

Now, I debugged the test and I'm 100% sure that the registered factory is used. I tried every different case and found this: If I use the verify() method everything works fine. If I use only one of verifyToString or verifyGettersAndSetters everything works fine. If I concatenate verifyToString and verifyGettersAndSetters i receive that error, but as I told before I am sure that the factory is registered. Maybe there is some problem with concatenation?

meanbeanlib commented 4 years ago

Ya, there is a bug with caching/scoping in ServiceFactory; will fix Could you try this work-around:

@Test
public void test() {
    createBeanVerifier().verifyGettersAndSetters();
    createBeanVerifier().verifyToString();
}

private BeanVerifier createBeanVerifier() {
    return BeanVerifier.forClass(MyBean.class)
            .editSettings()
            .registerFactory(MessageData.class, () -> {
                RandomValueGenerator randomValueGenerator = RandomValueGenerator.getInstance();
                byte[] randomBytes = randomValueGenerator.nextBytes(100);
                return new MessageData(randomBytes);
            })
            .edited();
}
Ichigo85 commented 4 years ago

Yeah, I wrote the same workaround to solve the problem :) Thank you!

meanbeanlib commented 4 years ago

Latest release should fix this problem. Please give it a try.