// Path: src/test/java/ru/job4j/principle_004/ConnectionRollback.java
// public static Connection create(Connection connection) throws SQLException {
//     connection.setAutoCommit(false);
//     return (Connection) Proxy.newProxyInstance(
//             ConnectionRollback.class.getClassLoader(),
//             new Class[] {
//                     Connection.class
//             },
//             (proxy, method, args) -> {
//                 Object rsl = null;
//                 if ("close".equals(method.getName())) {
//                     connection.rollback();
//                     connection.close();
//                 } else {
//                     rsl = method.invoke(connection, args);
//                 }
//                 return rsl;
//             }
//     );
// }


import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.junit.AfterClass;
import org.junit.Ignore;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
import static ru.job4j.principle_004.ConnectionRollback.create;
package ru.job4j.principle_004;



/**
 * Tests for hibernate.
 */
@Ignore
public class HibernateStoreTest {
    /**
     * Create a new user and check id.
     */
    @Test
    public void whenCreateUser() {
        SessionFactory factory = create(HibernateFactory.FACTORY);
        HibernateStore store = new HibernateStore(factory);
        User user = store.add(new User(-1, "Petr Arsentev"));
        assertThat(
                user.getId(),
                not(-1)
        );
        factory.close();
    }

    /**
     * Create a new user and find it.
     */
    @Test
    public void whenCreateAndFind() {
// Path: src/test/java/ru/job4j/principle_004/ConnectionRollback.java
// public static Connection create(Connection connection) throws SQLException {
//     connection.setAutoCommit(false);
//     return (Connection) Proxy.newProxyInstance(
//             ConnectionRollback.class.getClassLoader(),
//             new Class[] {
//                     Connection.class
//             },
//             (proxy, method, args) -> {
//                 Object rsl = null;
//                 if ("close".equals(method.getName())) {
//                     connection.rollback();
//                     connection.close();
//                 } else {
//                     rsl = method.invoke(connection, args);
//                 }
//                 return rsl;
//             }
//     );
// }


// Path: src/test/java/ru/job4j/principle_004/HibernateStoreTest.java
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.junit.AfterClass;
import org.junit.Ignore;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
import static ru.job4j.principle_004.ConnectionRollback.create;

package ru.job4j.principle_004;



/**
 * Tests for hibernate.
 */
@Ignore
public class HibernateStoreTest {
    /**
     * Create a new user and check id.
     */
    @Test
    public void whenCreateUser() {
        SessionFactory factory = create(HibernateFactory.FACTORY);
        HibernateStore store = new HibernateStore(factory);
        User user = store.add(new User(-1, "Petr Arsentev"));
        assertThat(
                user.getId(),
                not(-1)
        );
        factory.close();
    }

    /**
     * Create a new user and find it.
     */
    @Test
    public void whenCreateAndFind() {
        SessionFactory factory = create(HibernateFactory.FACTORY);