I do not want to mock session factory, I want to mock only models.
Here is my code:
Code:
@Mock
private Category category;
//...testTarget and other mocks
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
//get connection, doReturn, etc.
}
@Test
public void save() throws Exception {
testTarget.save(category);
assertThat(category.getId()).isNotEqualTo(0);
}
Mapping:
Code:
<hibernate-mapping default-lazy="true">
<class name="com.domain.models.Category" table="Category">
<id name="id" type="long" access="property">
<column name="categoryId" length="20"/>
<generator class="identity"/>
</id>
<property name="name" column="categoryName" type="string"/>
<property name="image" column="categoryImage" type="string"/>
<property name="parentId" column="categoryParentId" type="long"/>
</class>
</hibernate-mapping>