Skip to content

No assertions when there are no not reference fields #811

Closed
@sofurihafe

Description

@sofurihafe

Description

No assertions are generated when there are no not reference fields.

To Reproduce

  1. Set useAssembleModelGenerator to false,
  2. Generate a test for the following code:
class FirstClass {
    SecondClass secondClass;

    FirstClass(SecondClass second) {
        this.secondClass = second;
    }
}

class SecondClass {
    FirstClass firstClass;

    SecondClass(FirstClass first) {
        this.firstClass = first;
    }
}

public class ClassWithCrossReferenceRelationship {
    public FirstClass returnFirstClass(int value) {
        if (value == 0) {
            return new FirstClass(new SecondClass(null));
        } else {
            FirstClass first = new FirstClass(null);
            first.secondClass = new SecondClass(first);

            return first;
        }
    }
}

Expected behavior

Present assertion.

Actual behavior

@Test
@DisplayName("returnFirstClassWithNullableField: value = 0")
public void testReturnFirstClassWithNullableFieldWithCornerCase() throws Exception  {
    <...>
}

@Test
@DisplayName("returnFirstClassWithNullableField: value = 134217728 (mutated from 0)")
public void testReturnFirstClassWithNullableField() throws Exception  {
    SampleClass sampleClass = new SampleClass();
    
    FirstClass actual = sampleClass.returnFirstClassWithNullableField(134217728);
    
    FirstClass expected = ((FirstClass) createInstance("codegen.deepequals.FirstClass"));
    SecondClass secondClass = ((SecondClass) createInstance("codegen.deepequals.SecondClass"));

    secondClass.firstClass = expected;
    expected.secondClass = secondClass;
    
    SecondClass expectedSecondClass = expected.secondClass;
    SecondClass actualSecondClass = actual.secondClass;
    
}

There are no asserts in the second generated test.

Metadata

Metadata

Labels

comp-codegenIssue is related to code generatorctg-bugIssue is a bug

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions