Class FieldTests

java.lang.Object
eu.bandm.tools.umod.FieldTests

@Generated(generator="claude-sonnet-4-6", generatorType="LLM", version="claude-sonnet-4-6-20250514", timestamp="2026-06-04T17:38") public class FieldTests extends Object
Generates JUnit 4 field round-trip test methods for all non-abstract fields of all non-abstract umod class definitions.

For each field bar of model element Foo a test method test_Foo_bar is generated. The test creates an instance of Foo, sets bar to a randomly chosen value (via the setter for mutable classes, or via with_bar for algebraic classes), reads it back through the getter, and asserts equality.

For each model element Foo an aggregating method test_Foo__fields is generated that calls every per-field test.

OPT fields are tested with a null round-trip. Fields whose types have no straightforward random generator (collections, non-OPT internal references, external types, etc.) are omitted.

When a class has required constructor parameters (i.e. UMod.ClassDef.obligateConstructorFields is non-empty), an abstract factory method createInstance_ClassName() is generated instead of an inline new ClassName(). In that case the generated test class is made abstract and must be subclassed by the user.

This class must be called after the field-definition compilation phase of UMod2java so that ClassDef.obligateConstructorFields and the Java type mappings of all fields are already populated.

  • Field Details

    • TESTCLASS_NAME_PREFIX

      public static final String TESTCLASS_NAME_PREFIX
      Prefix prepended to the model name to form the test-class name.
      See Also:
    • testClass

      public GeneratedClass testClass
      The generated JUnit test class; set by process().
  • Constructor Details

    • FieldTests

      public FieldTests(UMod.Forest model, GeneratedPackage pkg)
      Store the arguments; call process() to run the generation.
      Parameters:
      model - the compiled umod meta-model (field phases must be done)
      pkg - the target package for the generated test class
  • Method Details

    • process

      public void process()
      Create and populate the test class for all class definitions in the model passed to the constructor.