Layout { public static <T> Layout<T> forClass(Class<T> klass) throws TypeHandler.TypeHandlerException, IntrospectionException, NoSuchAlgorithmException, IllegalAccessException { return new Layout<>(klass); } @LayoutConstructor  Layout(String name, List<Property<T>> properties); private  Layout(Class<T> klass); static Layout<T> forClass(Class<T> klass); Property<T> getProperty(String name); T instantiate(); T instantiate(Map<Property<T>, Object> properties); @Override boolean equals(Object obj); String toString(); static final String DIGEST_ALGORITHM; }
@Test @SneakyThrows public void hashSameContent() { Layout<DigestTest1> layout1 = Layout.forClass(DigestTest1.class); Layout<DigestTest1SameName> layout1SameName = Layout.forClass(DigestTest1SameName.class); assertEquals(layout1, layout1SameName); assertEquals(layout1.getHash(), layout1SameName.getHash()); }
@Test @SneakyThrows public void hashDifferentPropName() { Layout<DigestTest1> layout1 = Layout.forClass(DigestTest1.class); Layout<DigestTest1PropName> layout1Name = Layout.forClass(DigestTest1PropName.class); assertNotEquals(layout1, layout1Name); assertNotEquals(layout1.getHash(), layout1Name.getHash()); }
@Test @SneakyThrows public void hashDifferentType() { Layout<DigestTest1> layout1 = Layout.forClass(DigestTest1.class); Layout<DigestTest1Type> layout1Name = Layout.forClass(DigestTest1Type.class); assertNotEquals(layout1, layout1Name); assertNotEquals(layout1.getHash(), layout1Name.getHash()); }
@Test @SneakyThrows public void hashBoxed() { Layout<DigestTest1Unboxed> layout1 = Layout.forClass(DigestTest1Unboxed.class); Layout<DigestTest1Boxed> layout1Name = Layout.forClass(DigestTest1Boxed.class); assertEquals(layout1, layout1Name); assertEquals(layout1.getHash(), layout1Name.getHash()); }
@Test @SneakyThrows public void layoutLayout() { Layout<Layout> layout = Layout.forClass(Layout.class); assertEquals(layout.getName(), "rfc.eventsourcing.com/spec:7/LDL/#Layout"); assertEquals(layout.getProperties().size(), 2); assertTrue(layout.getProperties().stream().anyMatch(p -> p.getName().contentEquals("name"))); assertTrue(layout.getProperties().stream().anyMatch(p -> p.getName().contentEquals("properties"))); }
@Test(expectedExceptions = IllegalArgumentException.class) @SneakyThrows public void noConstructor() { Layout.forClass(NoConstructor.class); }
@Test(expectedExceptions = IllegalArgumentException.class) @SneakyThrows public void conflictingConstructors() { Layout.forClass(ConflictingConstructors.class); }
@Test @SneakyThrows public void explicitConstructor() { Layout<ExplicitConstructor> layout = Layout.forClass(ExplicitConstructor.class); Parameter[] parameters = layout.getConstructor().getParameters(); assertEquals(parameters[0].getName(), "a"); assertEquals(parameters[0].getType(), Integer.class); assertEquals(parameters[1].getName(), "b"); assertEquals(parameters[1].getType(), String.class); }
@Test @SneakyThrows public void widestConstructor() { Layout<WidestConstructor> layout = Layout.forClass(WidestConstructor.class); assertEquals(layout.getConstructor().getParameters().length, 3); }
@Test(expectedExceptions = IllegalArgumentException.class) @SneakyThrows public void missingPropertyGetter() { Layout.forClass(MissingPropertyGetter.class); }
@Test(expectedExceptions = IllegalArgumentException.class) @SneakyThrows public void mismatchedPropertyType() { Layout.forClass(MismatchedPropertyType.class); }
@Test @SneakyThrows public void renamedProperty() { Layout<RenamedProperty> layout = Layout.forClass(RenamedProperty.class); List<Property<RenamedProperty>> properties = layout.getProperties(); assertEquals(properties.size(), 1); assertEquals(properties.get(0).getName(), "abc"); }
@Test @SneakyThrows public void properties() { Layout<Properties> layout = Layout.forClass(Properties.class); List<Property<Properties>> properties = layout.getProperties(); assertEquals(properties.size(), 3); assertEquals(properties.get(0).getName(), "a"); assertEquals(properties.get(1).getName(), "b"); assertEquals(properties.get(2).getName(), "c"); List<Property<Properties>> constructorProperties = layout.getConstructorProperties(); assertEquals(constructorProperties.size(), 3); assertEquals(constructorProperties.get(0).getName(), "c"); assertEquals(constructorProperties.get(1).getName(), "a"); assertEquals(constructorProperties.get(2).getName(), "b"); }
@Test @SneakyThrows public void getters() { Layout<Properties> layout = Layout.forClass(Properties.class); List<Property<Properties>> properties = layout.getProperties(); Properties test = new Properties(true, "hello", 1); assertEquals(properties.get(0).get(test), "hello"); assertEquals((int)properties.get(1).get(test), 1); assertEquals((boolean)properties.get(2).get(test), true); }