Sculptor is an open source productivity tool. You express your design intent in a textual DSL, from which Sculptor generates high quality Java code and configuration.
BasicType Length { BigDecimal value min="0" -@LengthUnit unit}enum LengthUnit { cm, m, km}Entity Planet { gap scaffold String name key Long population min="0" -@Length diameter nullable -Set<@Moon> moons opposite planet Repository PlanetRepository { findByKey; }}
public class LengthTest { @Test public void shouldConvertFromMeterToKilometer() { Length length = new Length(new BigDecimal("31000"), m); Length lengthInKilometer = length.to(km); assertEquals(new Length(new BigDecimal("31"), km), lengthInKilometer); } @Test public void shouldConvertFromKilometerToMeter() { Length length = new Length(new BigDecimal("44"), km); Length lengthInMeter = length.to(m); assertEquals(new Length(new BigDecimal("44000"), m), lengthInMeter); } @Test public void shouldNotConvertSameUnit() { Length length = new Length(new BigDecimal("17"), km); Length length2 = length.to(km); assertSame(length, length2); }}
No comments:
Post a Comment