RelationCollisionUtil { protected Namer getXToOneNamerByConvention(Attribute fromAttribute, String fromEntityName, String fromAttributeVar, Namer targetEntityNamer) { String var = null; if (fromAttributeVar.toUpperCase().endsWith("ID")) { if (fromAttributeVar.length() > 2) { var = fromAttributeVar.substring(0, fromAttributeVar.length() - 2); } } else { var = fromAttributeVar; } if (var == null) { var = targetEntityNamer.getVar(); } return new AccessorNamer(targetEntityNamer, getClashSafeVar(fromEntityName, var)); }  void addVar(String entityType, String attributeVar); void removeVar(String entityType, String attributeVar); Namer getManyToOneNamer(Attribute fromAttribute, Namer targetEntityNamer); Namer getOneToManyNamer(ColumnConfig fromAttributeColumnConfig, Namer fromEntityNamer); Namer getManyToManyNamer(Namer fromEntityNamer, ColumnConfig pointsOnToEntity, Namer toEntityNamer); Namer getManyToOneIntermediateNamer(Namer fromEntityNamer, ColumnConfig pointsOnToEntity, Namer toEntityNamer); Namer getOneToManyIntermediateNamer(Namer fromEntityNamer, ColumnConfig pointsOnToEntity, Namer toEntityNamer); Namer getOneToOneNamer(Attribute fromAttribute, Namer targetEntityNamer); Namer getInverseOneToOneNamer(Attribute fromAttribute, Namer fromEntityNamer); String getClashSafeVar(String entityName, String javaField);  }
@Test public void xToOneNamerByConventionId() { RelationCollisionUtil relationUtil = new RelationCollisionUtil(); String fromEntityName = "Account"; String fromAttributeVar = "myAddressId"; Namer targetEntityNamer = getNamer("address", "Address"); Namer result = relationUtil.getXToOneNamerByConvention(null, fromEntityName, fromAttributeVar, targetEntityNamer); assertThat(result.getVar()).isEqualTo("myAddress"); assertThat(result.getType()).isEqualTo("Address"); }
@Test public void xToOneNamerByConventionRef() { RelationCollisionUtil relationUtil = new RelationCollisionUtil(); String fromEntityName = "Account"; String fromAttributeVar = "address"; Namer targetEntityNamer = getNamer("address", "Address"); Namer result = relationUtil.getXToOneNamerByConvention(null, fromEntityName, fromAttributeVar, targetEntityNamer); assertThat(result.getVar()).isEqualTo("address"); assertThat(result.getType()).isEqualTo("Address"); }
@Test public void xToOneNamerByConventionAny() { RelationCollisionUtil relationUtil = new RelationCollisionUtil(); String fromEntityName = "Account"; String fromAttributeVar = "anythingElse"; Namer targetEntityNamer = getNamer("address", "Address"); Namer result = relationUtil.getXToOneNamerByConvention(null, fromEntityName, fromAttributeVar, targetEntityNamer); assertThat(result.getVar()).isEqualTo("anythingElse"); assertThat(result.getType()).isEqualTo("Address"); }
@Test public void xToOneNamerByConventionWithClash() { RelationCollisionUtil relationUtil = new RelationCollisionUtil(); String fromEntityName = "Account"; String fromAttributeVar = "anythingElse"; Namer targetEntityNamer = getNamer("address", "Address"); Namer result = relationUtil.getXToOneNamerByConvention(null, fromEntityName, fromAttributeVar, targetEntityNamer); assertThat(result.getVar()).isEqualTo("anythingElse"); assertThat(result.getType()).isEqualTo("Address"); result = relationUtil.getXToOneNamerByConvention(null, fromEntityName, fromAttributeVar, targetEntityNamer); assertThat(result.getVar()).isEqualTo("anythingElse2"); assertThat(result.getType()).isEqualTo("Address"); }