Package org.neo4j.gis.spatial

Source Code of org.neo4j.gis.spatial.TryWithResourceTest

package org.neo4j.gis.spatial;

import org.junit.Test;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction;
import org.neo4j.test.TestGraphDatabaseFactory;

import static org.junit.Assert.assertEquals;

/**
* @author Michael Hunger @since 24.10.13
*/
public class TryWithResourceTest {

    public static final String MESSAGE = "I want to see this";

    @Test
    public void testSuppressedException() throws Exception {
        try {
        GraphDatabaseService db = new TestGraphDatabaseFactory().newImpermanentDatabase();
        try (Transaction tx = db.beginTx()) {
            Node n = db.createNode();
            try (Transaction tx2 = db.beginTx()) {
                n.setProperty("foo","bar");
                if (true) throw new Exception(MESSAGE);
                tx2.success();
            }
            tx.success();
        }
        } catch(Exception e) {
            assertEquals(MESSAGE,e.getMessage());
        }
    }

    @Test
    public void testSuppressedExceptionTopLevel() throws Exception {
        try {
            GraphDatabaseService db = new TestGraphDatabaseFactory().newImpermanentDatabase();
            try (Transaction tx = db.beginTx()) {
                Node n = db.createNode();
                n.setProperty("foo", "bar");
                if (true) throw new Exception(MESSAGE);
                tx.success();
            }
        } catch (Exception e) {
            assertEquals(MESSAGE, e.getMessage());
        }
    }
}
TOP

Related Classes of org.neo4j.gis.spatial.TryWithResourceTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.