package com.github.kohanyirobert.mongoroid;

import com.github.kohanyirobert.ebson.BsonDocuments;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public final class MongoCollectionSimpleSingleIndexTest
    extends AbstractMongoConnectionSimpleSingleTest {

  private MongoDatabase database;
  private MongoCollection collection;

  public MongoCollectionSimpleSingleIndexTest() {}

  @Override
  @Before
  public void setUp() throws MongoException {
    super.setUp();
    database = connection.database("test");
    collection = database.collection("test");
    collection.insert(MongoInserts.builder()
        .documents(BsonDocuments.of("a", "a"))
        .documents(BsonDocuments.of("a", "b"))
        .documents(BsonDocuments.of("a", "c"))
        .build());
  }

  @Test
  public void indexSimpleField() throws MongoException {
    collection.index(MongoIndexes.builder()
        .name("a")
        .selector(BsonDocuments.of("a", Integer.valueOf(1)))
        .build());

    Assert.assertEquals(1, database.collection("system.indexes")
        .count(MongoCounts.builder()
            .selector(BsonDocuments.builder()
                .put("key.a", Integer.valueOf(1))
                .put("ns", database.name() + "." + collection.name())
                .build())
            .build()));
  }
}

@@ -92,16 +92,40 @@
 ments;%0A%0A
+import org.junit.After;%0A
 import o
@@ -813,16 +813,168 @@
 );%0A  %7D%0A%0A
+  @Override%0A  @After%0A  public void tearDown() throws MongoException %7B%0A    database.command(BsonDocuments.of(%22dropIndexes%22, %22test%22, %22index%22, %22*%22));%0A  %7D%0A%0A
   @Test%0A

Add tear down method to the index tests.