HHH-12804 Don't mock Map in CollectionBinderTest

Apparently, Mockito + ByteBuddy are unable to mock Map on JDK 11.

It might be solved in the future but there's no point in doing it so
let's avoid it.
This commit is contained in:
Guillaume Smet 2018-07-14 11:45:56 +02:00
parent 48c44ef7d0
commit 667b565028
1 changed files with 8 additions and 12 deletions

View File

@ -6,8 +6,12 @@
*/ */
package org.hibernate.cfg.annotations; package org.hibernate.cfg.annotations;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Map; import java.util.HashMap;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.annotations.common.reflection.XClass; import org.hibernate.annotations.common.reflection.XClass;
@ -17,17 +21,11 @@ import org.hibernate.cfg.PropertyHolder;
import org.hibernate.mapping.Collection; import org.hibernate.mapping.Collection;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Table; import org.hibernate.mapping.Table;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test; import org.junit.Test;
import org.mockito.Mockito; import org.mockito.Mockito;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/** /**
* Test for HHH-10106 * Test for HHH-10106
* *
@ -39,7 +37,6 @@ public class CollectionBinderTest extends BaseUnitTestCase {
@TestForIssue(jiraKey = "HHH-10106") @TestForIssue(jiraKey = "HHH-10106")
public void testAssociatedClassException() throws SQLException { public void testAssociatedClassException() throws SQLException {
final Collection collection = mock(Collection.class); final Collection collection = mock(Collection.class);
final Map persistentClasses = mock(Map.class);
final XClass collectionType = mock(XClass.class); final XClass collectionType = mock(XClass.class);
final MetadataBuildingContext buildingContext = mock(MetadataBuildingContext.class); final MetadataBuildingContext buildingContext = mock(MetadataBuildingContext.class);
final InFlightMetadataCollector inFly = mock(InFlightMetadataCollector.class); final InFlightMetadataCollector inFly = mock(InFlightMetadataCollector.class);
@ -47,7 +44,6 @@ public class CollectionBinderTest extends BaseUnitTestCase {
final Table table = mock(Table.class); final Table table = mock(Table.class);
when(buildingContext.getMetadataCollector()).thenReturn(inFly); when(buildingContext.getMetadataCollector()).thenReturn(inFly);
when(persistentClasses.get(null)).thenReturn(null);
when(collection.getOwner()).thenReturn(persistentClass); when(collection.getOwner()).thenReturn(persistentClass);
when(collectionType.getName()).thenReturn("List"); when(collectionType.getName()).thenReturn("List");
when(persistentClass.getTable()).thenReturn(table); when(persistentClass.getTable()).thenReturn(table);
@ -69,7 +65,7 @@ public class CollectionBinderTest extends BaseUnitTestCase {
String expectMessage = "Association [abc] for entity [CollectionBinderTest] references unmapped class [List]"; String expectMessage = "Association [abc] for entity [CollectionBinderTest] references unmapped class [List]";
try { try {
collectionBinder.bindOneToManySecondPass(collection, persistentClasses, null, collectionType, false, false, buildingContext, null); collectionBinder.bindOneToManySecondPass(collection, new HashMap(), null, collectionType, false, false, buildingContext, null);
} catch (MappingException e) { } catch (MappingException e) {
assertEquals(expectMessage, e.getMessage()); assertEquals(expectMessage, e.getMessage());
} }