Skip to content

Commit

Permalink
HBX-2747: Create Interface for ForeignKeyWrapper
Browse files Browse the repository at this point in the history
  - Add new test case 'org.hibernate.tool.orm.jbt.api.ForeignKeyWrapperTest#testGetReferencedColumns()'
  - Add new default interface method 'org.hibernate.tool.orm.jbt.api.ForeignKeyWrapper#getReferencedColumns()'

Signed-off-by: Koen Aers <koen.aers@gmail.com>
  • Loading branch information
koentsje committed Mar 13, 2024
1 parent 094805f commit 589a5bd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.hibernate.tool.orm.jbt.api;

import java.util.Iterator;
import java.util.List;

import org.hibernate.mapping.Column;
import org.hibernate.mapping.ForeignKey;
Expand All @@ -14,6 +15,8 @@ public interface ForeignKeyWrapper extends Wrapper {
default Iterator<Column> columnIterator() { return ((ForeignKey)getWrappedObject()).getColumns().iterator(); }

default boolean isReferenceToPrimaryKey() { return ((ForeignKey)getWrappedObject()).isReferenceToPrimaryKey(); }

default List<Column> getReferencedColumns() { return ((ForeignKey)getWrappedObject()).getReferencedColumns(); }


}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package org.hibernate.tool.orm.jbt.api;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.hibernate.mapping.Column;
import org.hibernate.mapping.ForeignKey;
Expand Down Expand Up @@ -62,4 +64,17 @@ public void testIsReferenceToPrimaryKey() {
assertFalse(foreignKeyWrapper.isReferenceToPrimaryKey());
}

@Test
public void testGetReferencedColumns() {
List<Column> list = foreignKeyWrapper.getReferencedColumns();
assertTrue(list.isEmpty());
Column column = new Column();
ArrayList<Column> columns = new ArrayList<Column>();
columns.add(column);
wrappedForeignKey.addReferencedColumns(columns);
list = foreignKeyWrapper.getReferencedColumns();
assertEquals(1, list.size());
assertSame(column, list.get(0));
}

}

0 comments on commit 589a5bd

Please sign in to comment.