// Path: src/main/java/org/lmdbjava/ByteBufferProxy.java
// public static final BufferProxy<ByteBuffer> PROXY_OPTIMAL;
// 
// Path: src/main/java/org/lmdbjava/Env.java
// public static Builder<ByteBuffer> create() {
//   return new Builder<>(PROXY_OPTIMAL);
// }
// 
// Path: src/test/java/org/lmdbjava/TestUtils.java
// public static final String DB_1 = "test-db-1";
// 
// Path: src/test/java/org/lmdbjava/TestUtils.java
// @SuppressWarnings("PMD.AvoidUsingOctalValues")
// public static final int POSIX_MODE = 0664;
// 
// Path: src/test/java/org/lmdbjava/TestUtils.java
// static ByteBuffer bb(final int value) {
//   final ByteBuffer bb = allocateDirect(BYTES);
//   bb.putInt(value).flip();
//   return bb;
// }
// 
// Path: src/main/java/org/lmdbjava/Cursor.java
// public static final class ClosedException extends LmdbException {
// 
//   private static final long serialVersionUID = 1L;
// 
//   /**
//    * Creates a new instance.
//    */
//   public ClosedException() {
//     super("Cursor has already been closed");
//   }
// }
// 
// Path: src/main/java/org/lmdbjava/Txn.java
// public static final class NotReadyException extends LmdbException {
// 
//   private static final long serialVersionUID = 1L;
// 
//   /**
//    * Creates a new instance.
//    */
//   public NotReadyException() {
//     super("Transaction is not in ready state");
//   }
// }
// 
// Path: src/main/java/org/lmdbjava/Txn.java
// public static class ReadOnlyRequiredException extends LmdbException {
// 
//   private static final long serialVersionUID = 1L;
// 
//   /**
//    * Creates a new instance.
//    */
//   public ReadOnlyRequiredException() {
//     super("Not a read-only transaction");
//   }
// }


import static com.jakewharton.byteunits.BinaryByteUnit.KIBIBYTES;
import static java.lang.Long.BYTES;
import static java.lang.Long.MIN_VALUE;
import static java.nio.ByteBuffer.allocateDirect;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.lmdbjava.ByteBufferProxy.PROXY_OPTIMAL;
import static org.lmdbjava.DbiFlags.MDB_CREATE;
import static org.lmdbjava.DbiFlags.MDB_DUPFIXED;
import static org.lmdbjava.DbiFlags.MDB_DUPSORT;
import static org.lmdbjava.Env.create;
import static org.lmdbjava.EnvFlags.MDB_NOSUBDIR;
import static org.lmdbjava.PutFlags.MDB_APPENDDUP;
import static org.lmdbjava.PutFlags.MDB_MULTIPLE;
import static org.lmdbjava.PutFlags.MDB_NODUPDATA;
import static org.lmdbjava.PutFlags.MDB_NOOVERWRITE;
import static org.lmdbjava.SeekOp.MDB_FIRST;
import static org.lmdbjava.SeekOp.MDB_GET_BOTH;
import static org.lmdbjava.TestUtils.DB_1;
import static org.lmdbjava.TestUtils.POSIX_MODE;
import static org.lmdbjava.TestUtils.bb;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.lmdbjava.Cursor.ClosedException;
import org.lmdbjava.Txn.NotReadyException;
import org.lmdbjava.Txn.ReadOnlyRequiredException;
/*-
 * #%L
 * LmdbJava
 * %%
 * Copyright (C) 2016 - 2021 The LmdbJava Open Source Project
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

package org.lmdbjava;




/**
 * Test {@link Cursor}.
 */
public final class CursorTest {

  @Rule
  public final TemporaryFolder tmp = new TemporaryFolder();

  private Env<ByteBuffer> env;

  @After
  public void after() {
    env.close();
  }

  @Before
  public void before() throws IOException {
    try {
      final File path = tmp.newFile();
      env = create(PROXY_OPTIMAL)
          .setMapSize(KIBIBYTES.toBytes(1_024))
          .setMaxReaders(1)
          .setMaxDbs(1)
          .open(path, POSIX_MODE, MDB_NOSUBDIR);
    } catch (final IOException e) {
      throw new LmdbException("IO failure", e);
    }
  }

// Path: src/main/java/org/lmdbjava/ByteBufferProxy.java
// public static final BufferProxy<ByteBuffer> PROXY_OPTIMAL;
// 
// Path: src/main/java/org/lmdbjava/Env.java
// public static Builder<ByteBuffer> create() {
//   return new Builder<>(PROXY_OPTIMAL);
// }
// 
// Path: src/test/java/org/lmdbjava/TestUtils.java
// public static final String DB_1 = "test-db-1";
// 
// Path: src/test/java/org/lmdbjava/TestUtils.java
// @SuppressWarnings("PMD.AvoidUsingOctalValues")
// public static final int POSIX_MODE = 0664;
// 
// Path: src/test/java/org/lmdbjava/TestUtils.java
// static ByteBuffer bb(final int value) {
//   final ByteBuffer bb = allocateDirect(BYTES);
//   bb.putInt(value).flip();
//   return bb;
// }
// 
// Path: src/main/java/org/lmdbjava/Cursor.java
// public static final class ClosedException extends LmdbException {
// 
//   private static final long serialVersionUID = 1L;
// 
//   /**
//    * Creates a new instance.
//    */
//   public ClosedException() {
//     super("Cursor has already been closed");
//   }
// }
// 
// Path: src/main/java/org/lmdbjava/Txn.java
// public static final class NotReadyException extends LmdbException {
// 
//   private static final long serialVersionUID = 1L;
// 
//   /**
//    * Creates a new instance.
//    */
//   public NotReadyException() {
//     super("Transaction is not in ready state");
//   }
// }
// 
// Path: src/main/java/org/lmdbjava/Txn.java
// public static class ReadOnlyRequiredException extends LmdbException {
// 
//   private static final long serialVersionUID = 1L;
// 
//   /**
//    * Creates a new instance.
//    */
//   public ReadOnlyRequiredException() {
//     super("Not a read-only transaction");
//   }
// }


// Path: src/test/java/org/lmdbjava/CursorTest.java
import static com.jakewharton.byteunits.BinaryByteUnit.KIBIBYTES;
import static java.lang.Long.BYTES;
import static java.lang.Long.MIN_VALUE;
import static java.nio.ByteBuffer.allocateDirect;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.lmdbjava.ByteBufferProxy.PROXY_OPTIMAL;
import static org.lmdbjava.DbiFlags.MDB_CREATE;
import static org.lmdbjava.DbiFlags.MDB_DUPFIXED;
import static org.lmdbjava.DbiFlags.MDB_DUPSORT;
import static org.lmdbjava.Env.create;
import static org.lmdbjava.EnvFlags.MDB_NOSUBDIR;
import static org.lmdbjava.PutFlags.MDB_APPENDDUP;
import static org.lmdbjava.PutFlags.MDB_MULTIPLE;
import static org.lmdbjava.PutFlags.MDB_NODUPDATA;
import static org.lmdbjava.PutFlags.MDB_NOOVERWRITE;
import static org.lmdbjava.SeekOp.MDB_FIRST;
import static org.lmdbjava.SeekOp.MDB_GET_BOTH;
import static org.lmdbjava.TestUtils.DB_1;
import static org.lmdbjava.TestUtils.POSIX_MODE;
import static org.lmdbjava.TestUtils.bb;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.lmdbjava.Cursor.ClosedException;
import org.lmdbjava.Txn.NotReadyException;
import org.lmdbjava.Txn.ReadOnlyRequiredException;

/*-
 * #%L
 * LmdbJava
 * %%
 * Copyright (C) 2016 - 2021 The LmdbJava Open Source Project
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

package org.lmdbjava;




/**
 * Test {@link Cursor}.
 */
public final class CursorTest {

  @Rule
  public final TemporaryFolder tmp = new TemporaryFolder();

  private Env<ByteBuffer> env;

  @After
  public void after() {
    env.close();
  }

  @Before
  public void before() throws IOException {
    try {
      final File path = tmp.newFile();
      env = create(PROXY_OPTIMAL)
          .setMapSize(KIBIBYTES.toBytes(1_024))
          .setMaxReaders(1)
          .setMaxDbs(1)
          .open(path, POSIX_MODE, MDB_NOSUBDIR);
    } catch (final IOException e) {
      throw new LmdbException("IO failure", e);
    }
  }

  @Test(expected = ClosedException.class)