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 972a79d448
commit f274db28f6

View File

@ -6,8 +6,12 @@
*/
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.util.Map;
import java.util.HashMap;
import org.hibernate.MappingException;
import org.hibernate.annotations.common.reflection.XClass;
@ -17,17 +21,11 @@
import org.hibernate.mapping.Collection;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Table;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test;
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
*
@ -39,20 +37,18 @@ public class CollectionBinderTest extends BaseUnitTestCase {
@TestForIssue(jiraKey = "HHH-10106")
public void testAssociatedClassException() throws SQLException {
final Collection collection = mock(Collection.class);
final Map persistentClasses = mock(Map.class);
final XClass collectionType = mock(XClass.class);
final MetadataBuildingContext buildingContext = mock(MetadataBuildingContext.class);
final InFlightMetadataCollector inFly = mock(InFlightMetadataCollector.class);
final PersistentClass persistentClass = mock(PersistentClass.class);
final Table table = mock(Table.class);
when(buildingContext.getMetadataCollector()).thenReturn(inFly);
when(persistentClasses.get(null)).thenReturn(null);
when(collection.getOwner()).thenReturn(persistentClass);
when(collectionType.getName()).thenReturn("List");
when(persistentClass.getTable()).thenReturn(table);
when(table.getName()).thenReturn("Hibernate");
CollectionBinder collectionBinder = new CollectionBinder(false) {
@Override
protected Collection createCollection(PersistentClass persistentClass) {
@ -69,7 +65,7 @@ protected Collection createCollection(PersistentClass persistentClass) {
String expectMessage = "Association [abc] for entity [CollectionBinderTest] references unmapped class [List]";
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) {
assertEquals(expectMessage, e.getMessage());
}