pholser/junit-quickcheck

Make Generator an interface

vlsi opened this issue · 2 comments

vlsi commented

Currently, Generator is a class, and it makes it complicated to implement generators.

For instance, I already have a generator, however, it extends its own class for simplified API.

Base class: https://github.com/apache/calcite/blob/763ec429c951acd5fa251c5d4a2b7780fbf648d4/core/src/test/java/org/apache/calcite/rex/RexProgramBuilderBase.java#L44

Uses in the generator: https://github.com/apache/calcite/blob/763ec429c951acd5fa251c5d4a2b7780fbf648d4/core/src/test/java/org/apache/calcite/test/fuzzer/RexFuzzer.java#L184

It does not hurt much, however, at this point it looks like all the Generator / Shrinker behavior can be implemented with interface default methods.

@vlsi Thanks for this. I'm open to having Generator become an interface. My main concern is avoiding breaking existing subclasses of Generator, as you might expect. I'll noodle on this a bit.

vlsi commented

My main concern is avoiding breaking existing subclasses of

I see.

There are two options at least:

  • Just do it :) junit-quickcheck is 0.x, so slight glitches in the backward compatibility are expected by the consumers
  • Add super interface for those who want to implement a generator without having to extend a base class (and use it internally instead of the current Generator)