@Test
public void testParentInnerJoin() {

	Function<FromStep, JoinStep> parentJoinFunction =
		fromStep -> fromStep.from(
			MainExampleTable.INSTANCE
		).innerJoinON(
			ReferenceExampleTable.INSTANCE,
			MainExampleTable.INSTANCE.mainExampleId.eq(
				ReferenceExampleTable.INSTANCE.mainExampleId)
		);
	ReferenceExampleTable aliasReferenceExampleTable =
		ReferenceExampleTable.INSTANCE.as("aliasReferenceExampleTable");
	Function<FromStep, JoinStep> selfJoinFunction1 =
		fromStep -> fromStep.from(
			aliasReferenceExampleTable
		).innerJoinON(
			ReferenceExampleTable.INSTANCE,
			ReferenceExampleTable.INSTANCE.referenceExampleId.eq(
				aliasReferenceExampleTable.parentReferenceExampleId)
		);
	Function<FromStep, JoinStep> selfJoinFunction2 =
		fromStep -> fromStep.from(
			aliasReferenceExampleTable
		).innerJoinON(
			ReferenceExampleTable.INSTANCE,
			ReferenceExampleTable.INSTANCE.parentReferenceExampleId.eq(
				aliasReferenceExampleTable.referenceExampleId)
		);
	TableReferenceDefinition<ReferenceExampleTable>
		tableReferenceDefinition =
			new TestTableReferenceDefinition<ReferenceExampleTable>(
				ReferenceExampleTable.INSTANCE) {
				@Override
				public void defineChildTableReferences(
					ChildTableReferenceInfoBuilder<ReferenceExampleTable>
						childTableReferenceInfoBuilder) {
					childTableReferenceInfoBuilder.referenceInnerJoin(
						selfJoinFunction1);
				}
				@Override
				public void defineParentTableReferences(
					ParentTableReferenceInfoBuilder<ReferenceExampleTable>
						parentTableReferenceInfoBuilder) {
					parentTableReferenceInfoBuilder.referenceInnerJoin(
						parentJoinFunction
					).referenceInnerJoin(
						selfJoinFunction2
					);
				}
			};
	TableReferenceInfo<ReferenceExampleTable> tableReferenceInfo =
		TableReferenceInfoFactory.create(
			ReferenceExampleTable.CLASS_NAME_ID,
			ReferenceExampleTable.INSTANCE.referenceExampleId,
			tableReferenceDefinition);
	Assert.assertNotNull(tableReferenceInfo);
	Assert.assertSame(
		tableReferenceDefinition,
		tableReferenceInfo.getTableReferenceDefinition());
	Map<Table<?>, List<TableJoinHolder>> childTableJoinHoldersMap =
		tableReferenceInfo.getChildTableJoinHoldersMap();
	Assert.assertEquals(
		childTableJoinHoldersMap.toString(), 1,
		childTableJoinHoldersMap.size());
	List<TableJoinHolder> childTableJoinHolders =
		childTableJoinHoldersMap.get(ReferenceExampleTable.INSTANCE);
	Assert.assertEquals(
		childTableJoinHolders.toString(), 1, childTableJoinHolders.size());
	TableJoinHolder childJoinHolder = childTableJoinHolders.get(0);
	Assert.assertSame(selfJoinFunction1, childJoinHolder.getJoinFunction());
	Assert.assertSame(
		aliasReferenceExampleTable.referenceExampleId,
		childJoinHolder.getParentPKColumn());
	Assert.assertSame(
		ReferenceExampleTable.INSTANCE.referenceExampleId,
		childJoinHolder.getChildPKColumn());
	Map<Table<?>, List<TableJoinHolder>> parentTableJoinHoldersMap =
		tableReferenceInfo.getParentTableJoinHoldersMap();
	Assert.assertEquals(
		parentTableJoinHoldersMap.toString(), 2,
		parentTableJoinHoldersMap.size());
	List<TableJoinHolder> parentTableJoinHolders =
		parentTableJoinHoldersMap.get(MainExampleTable.INSTANCE);
	Assert.assertEquals(
		parentTableJoinHolders.toString(), 1,
		parentTableJoinHolders.size());
	TableJoinHolder parentJoinHolder = parentTableJoinHolders.get(0);
	Assert.assertSame(
		parentJoinFunction, parentJoinHolder.getJoinFunction());
	Assert.assertSame(
		MainExampleTable.INSTANCE.mainExampleId,
		parentJoinHolder.getParentPKColumn());
	Assert.assertSame(
		ReferenceExampleTable.INSTANCE.referenceExampleId,
		parentJoinHolder.getChildPKColumn());
	parentTableJoinHolders = parentTableJoinHoldersMap.get(
		ReferenceExampleTable.INSTANCE);
	Assert.assertEquals(
		parentTableJoinHolders.toString(), 1,
		parentTableJoinHolders.size());
	childJoinHolder = parentTableJoinHolders.get(0);
	Assert.assertSame(selfJoinFunction2, childJoinHolder.getJoinFunction());
	Assert.assertSame(
		aliasReferenceExampleTable.referenceExampleId,
		childJoinHolder.getParentPKColumn());
	Assert.assertSame(
		ReferenceExampleTable.INSTANCE.referenceExampleId,
		childJoinHolder.getChildPKColumn());
	Assert.assertEquals(
		ReferenceExampleTable.CLASS_NAME_ID,
		tableReferenceInfo.getClassNameId());
}