Projects >> fongo >>68ecbb6e8558cfd9f6ebfb51f209954cc05d49d9

Chunk
Conflicting content
    }
  }

<<<<<<< HEAD
  @Test
  public void shouldSearchGteInArray() throws Exception {
    // Given
    DBCollection collection = newCollection();
    collection.insert(new BasicDBObject("_id", 1).append("a", Util.list(1, 2, 3)));
    collection.insert(new BasicDBObject("_id", 2).append("a", 2));

    // When
    List objects = collection.find(new BasicDBObject("a", new BasicDBObject("$gte", 2))).toArray();

    // Then
    assertEquals(Arrays.asList(
        new BasicDBObject("_id", 1).append("a", Util.list(1, 2, 3)),
        new BasicDBObject("_id", 2).append("a", 2)), objects);
  }

  // issue #78 $gte throws Exception on non-Comparable
  @Test
  public void shouldNotThrowsExceptionOnNonComparableGte() throws Exception {
    // Given
    DBCollection collection = newCollection();
    collection.insert(new BasicDBObject("_id", 1).append("a", new BasicDBObject("b", 1).append("c", 1)));
    collection.insert(new BasicDBObject("_id", 2).append("a", 2));

    // When
    List objects = collection.find(new BasicDBObject("a", new BasicDBObject("$gte", 2))).toArray();

    // Then
    assertEquals(Arrays.asList(
        new BasicDBObject("_id", 2).append("a", 2)), objects);
  }

  // issue #78 $gte throws Exception on non-Comparable
  @Test
  public void shouldNotThrowsExceptionOnNonComparableLte() throws Exception {
    // Given
    DBCollection collection = newCollection();
    collection.insert(new BasicDBObject("_id", 1).append("a", new BasicDBObject("b", 1).append("c", 1)));
    collection.insert(new BasicDBObject("_id", 2).append("a", 2));

    // When
    List objects = collection.find(new BasicDBObject("a", new BasicDBObject("$lte", 2))).toArray();

    // Then
    assertEquals(Arrays.asList(
        new BasicDBObject("_id", 2).append("a", 2)), objects);
  }

  // issue #78 $gte throws Exception on non-Comparable
  @Test
  public void shouldNotThrowsExceptionOnNonComparableGt() throws Exception {
    // Given
    DBCollection collection = newCollection();
    collection.insert(new BasicDBObject("_id", 1).append("a", new BasicDBObject("b", 1).append("c", 1)));
    collection.insert(new BasicDBObject("_id", 2).append("a", 2));

    // When
    List objects = collection.find(new BasicDBObject("a", new BasicDBObject("$gt", 1))).toArray();

    // Then
    assertEquals(Arrays.asList(
        new BasicDBObject("_id", 2).append("a", 2)), objects);
  }

  // issue #78 $gte throws Exception on non-Comparable
  @Test
  public void shouldNotThrowsExceptionOnNonComparableLt() throws Exception {
    // Given
    DBCollection collection = newCollection();
    collection.insert(new BasicDBObject("_id", 1).append("a", new BasicDBObject("b", 1).append("c", 1)));
    collection.insert(new BasicDBObject("_id", 2).append("a", 2));

    // When
    List objects = collection.find(new BasicDBObject("a", new BasicDBObject("$lt", 3))).toArray();

    // Then
    assertEquals(Arrays.asList(
        new BasicDBObject("_id", 2).append("a", 2)), objects);
  }

  @Test
  public void shouldCompareObjectId() throws Exception {
    // Given
    DBCollection collection = newCollection();
    ObjectId id1 = ObjectId.get();
    ObjectId id2 = ObjectId.get();
    collection.insert(new BasicDBObject("_id", id1));
    collection.insert(new BasicDBObject("_id", id2));

    // When
    List objects = collection.find(new BasicDBObject("_id", new BasicDBObject("$gte", id1))).toArray();

    // Then
    assertEquals(Arrays.asList(
        new BasicDBObject("_id", id1),
        new BasicDBObject("_id", id2)
    ), objects);
=======

  @Test
  public void canInsertWithNewObjectId() throws Exception {
    DBCollection collection = newCollection();
    ObjectId id = ObjectId.get();

    collection.insert(new BasicDBObject("_id", id).append("name", "jon"));

    assertEquals(1, collection.count(new BasicDBObject("name", "jon")));
    assertFalse(id.isNew());
  }

  @Test
  public void saveStringAsObjectId() throws Exception {
    DBCollection collection = newCollection();
    String id = ObjectId.get().toString();

    BasicDBObject object = new BasicDBObject("_id", id).append("name", "jon");
    collection.insert(object);

    assertEquals(1, collection.count(new BasicDBObject("name", "jon")));
    assertEquals(id, object.get("_id"));
  }

  // http://docs.mongodb.org/manual/reference/operator/type/
  @Test
  public void shouldFilterByType() throws Exception {
    // Given
    DBCollection collection = newCollection();
    collection.insert(new BasicDBObject("date", 1).append("_id", 1));
    collection.insert(new BasicDBObject("date", 2D).append("_id", 2));
    collection.insert(new BasicDBObject("date", "3").append("_id", 3));
    ObjectId id = new ObjectId();
    collection.insert(new BasicDBObject("date", true).append("_id", id));
    collection.insert(new BasicDBObject("date", null).append("_id", 5));
    collection.insert(new BasicDBObject("date", 6L).append("_id", 6));
    collection.insert(new BasicDBObject("date", Util.list(1, 2, 3)).append("_id", 7));
    collection.insert(new BasicDBObject("date", Util.list(1D, 2L, "3", 4)).append("_id", 8));
    collection.insert(new BasicDBObject("date", Util.list(Util.list(1D, 2L, "3", 4))).append("_id", 9));
    collection.insert(new BasicDBObject("date", 2F).append("_id", 10));
    collection.insert(new BasicDBObject("date", new BasicDBObject("x", 1)).append("_id", 11));

    // When
    List objects = collection.find(new BasicDBObject("date", new BasicDBObject("$type", 1))).toArray();
    assertEquals(Arrays.asList(
        new BasicDBObject("_id", 2).append("date", 2D),
        new BasicDBObject("date", Util.list(1D, 2L, "3", 4)).append("_id", 8),
        new BasicDBObject("date", 2F).append("_id", 10)), objects);

    // When
    // String
    objects = collection.find(new BasicDBObject("date", new BasicDBObject("$type", 2))).toArray();
    assertEquals(Arrays.asList(
        new BasicDBObject("_id", 3).append("date", "3"),
        new BasicDBObject("date", Util.list(1D, 2L, "3", 4)).append("_id", 8)), objects);

    // Integer
    objects = collection.find(new BasicDBObject("date", new BasicDBObject("$type", 16))).toArray();
    assertEquals(Arrays.asList(
        new BasicDBObject("_id", 1).append("date", 1),
        new BasicDBObject("date", Util.list(1, 2, 3)).append("_id", 7),
        new BasicDBObject("date", Util.list(1D, 2L, "3", 4)).append("_id", 8)), objects);

    // ObjectId
    objects = collection.find(new BasicDBObject("_id", new BasicDBObject("$type", 7))).toArray();
    assertEquals(Collections.singletonList(new BasicDBObject("_id", id).append("date", true)), objects);

    // Boolean
    objects = collection.find(new BasicDBObject("date", new BasicDBObject("$type", 8))).toArray();
    assertEquals(Collections.singletonList(new BasicDBObject("_id", id).append("date", true)), objects);

    // Long ?
    objects = collection.find(new BasicDBObject("date", new BasicDBObject("$type", 18))).toArray();
    assertEquals(Arrays.asList(
        new BasicDBObject("_id", 6).append("date", 6L),
        new BasicDBObject("date", Util.list(1D, 2L, "3", 4)).append("_id", 8)), objects);

    // Array ?
    objects = collection.find(new BasicDBObject("date", new BasicDBObject("$type", 4))).toArray();
    assertEquals(Arrays.asList(
        new BasicDBObject("date", Util.list(Util.list(1D, 2L, "3", 4))).append("_id", 9)), objects);

    // Null ?
    objects = collection.find(new BasicDBObject("date", new BasicDBObject("$type", 10))).toArray();
    assertEquals(Collections.singletonList(new BasicDBObject("_id", 5).append("date", null)), objects);

    // Object ?
    objects = collection.find(new BasicDBObject("date", new BasicDBObject("$type", 3))).toArray();
    assertEquals(Arrays.asList(
        new BasicDBObject("_id", 1).append("date", 1),
        new BasicDBObject("_id", 2).append("date", 2D),
        new BasicDBObject("_id", 3).append("date", "3"),
        new BasicDBObject("_id", id).append("date", true),
        new BasicDBObject("_id", 6).append("date", 6L),
        new BasicDBObject("_id", 7).append("date", Util.list(1, 2, 3)),
        new BasicDBObject("_id", 8).append("date", Util.list(1D, 2L, "3", 4)),
        new BasicDBObject("_id", 9).append("date", Util.list(Util.list(1D, 2L, "3", 4))),
        new BasicDBObject("_id", 10).append("date", 2F),
        new BasicDBObject("_id", 11).append("date", new BasicDBObject("x", 1))), objects);
>>>>>>> 12027f6b63a54486dca494dc73bfb86ea86c73af
  }

  static class Seq {
Solution content
    // Then
  }
    }
  }

  @Test
  public void shouldSearchGteInArray() throws Exception {
    // Given
    DBCollection collection = newCollection();
    collection.insert(new BasicDBObject("_id", 1).append("a", Util.list(1, 2, 3)));
    collection.insert(new BasicDBObject("_id", 2).append("a", 2));

    // When
    List objects = collection.find(new BasicDBObject("a", new BasicDBObject("$gte", 2))).toArray();
    assertEquals(Arrays.asList(
        new BasicDBObject("_id", 1).append("a", Util.list(1, 2, 3)),
        new BasicDBObject("_id", 2).append("a", 2)), objects);
  }

  // issue #78 $gte throws Exception on non-Comparable
  @Test
  public void shouldNotThrowsExceptionOnNonComparableGte() throws Exception {
    // Given
    DBCollection collection = newCollection();
    collection.insert(new BasicDBObject("_id", 1).append("a", new BasicDBObject("b", 1).append("c", 1)));
    collection.insert(new BasicDBObject("_id", 2).append("a", 2));

    // When
    List objects = collection.find(new BasicDBObject("a", new BasicDBObject("$gte", 2))).toArray();

    // Then
    assertEquals(Arrays.asList(
        new BasicDBObject("_id", 2).append("a", 2)), objects);
  }

  // issue #78 $gte throws Exception on non-Comparable
  @Test
  public void shouldNotThrowsExceptionOnNonComparableLte() throws Exception {
    // Given
    DBCollection collection = newCollection();
    collection.insert(new BasicDBObject("_id", 1).append("a", new BasicDBObject("b", 1).append("c", 1)));
    collection.insert(new BasicDBObject("_id", 2).append("a", 2));

    // When
    List objects = collection.find(new BasicDBObject("a", new BasicDBObject("$lte", 2))).toArray();

    // Then
    assertEquals(Arrays.asList(
        new BasicDBObject("_id", 2).append("a", 2)), objects);
  }

  // issue #78 $gte throws Exception on non-Comparable
  @Test
  public void shouldNotThrowsExceptionOnNonComparableGt() throws Exception {
    // Given
    DBCollection collection = newCollection();
    collection.insert(new BasicDBObject("_id", 1).append("a", new BasicDBObject("b", 1).append("c", 1)));
    collection.insert(new BasicDBObject("_id", 2).append("a", 2));

    // When
    List objects = collection.find(new BasicDBObject("a", new BasicDBObject("$gt", 1))).toArray();

    // Then
    assertEquals(Arrays.asList(
        new BasicDBObject("_id", 2).append("a", 2)), objects);
  }

  // issue #78 $gte throws Exception on non-Comparable
  @Test
  public void shouldNotThrowsExceptionOnNonComparableLt() throws Exception {
    // Given
    DBCollection collection = newCollection();
    collection.insert(new BasicDBObject("_id", 1).append("a", new BasicDBObject("b", 1).append("c", 1)));
    collection.insert(new BasicDBObject("_id", 2).append("a", 2));

    // When
    List objects = collection.find(new BasicDBObject("a", new BasicDBObject("$lt", 3))).toArray();

    // Then
    assertEquals(Arrays.asList(
        new BasicDBObject("_id", 2).append("a", 2)), objects);
  }

  @Test
  public void shouldCompareObjectId() throws Exception {
    // Given
    DBCollection collection = newCollection();
    ObjectId id1 = ObjectId.get();
    ObjectId id2 = ObjectId.get();
    collection.insert(new BasicDBObject("_id", id1));
    collection.insert(new BasicDBObject("_id", id2));

    // When
    List objects = collection.find(new BasicDBObject("_id", new BasicDBObject("$gte", id1))).toArray();

    // Then
    assertEquals(Arrays.asList(
        new BasicDBObject("_id", id1),
        new BasicDBObject("_id", id2)
    ), objects);
  }

  @Test
  public void canInsertWithNewObjectId() throws Exception {
    DBCollection collection = newCollection();
    ObjectId id = ObjectId.get();

    collection.insert(new BasicDBObject("_id", id).append("name", "jon"));

    assertEquals(1, collection.count(new BasicDBObject("name", "jon")));
    assertFalse(id.isNew());

  @Test
  public void saveStringAsObjectId() throws Exception {
    DBCollection collection = newCollection();
    String id = ObjectId.get().toString();

    BasicDBObject object = new BasicDBObject("_id", id).append("name", "jon");
    collection.insert(object);

    assertEquals(1, collection.count(new BasicDBObject("name", "jon")));
    assertEquals(id, object.get("_id"));
  }

  // http://docs.mongodb.org/manual/reference/operator/type/
  @Test
  public void shouldFilterByType() throws Exception {
    // Given
    DBCollection collection = newCollection();
    collection.insert(new BasicDBObject("date", 1).append("_id", 1));
    collection.insert(new BasicDBObject("date", 2D).append("_id", 2));
    collection.insert(new BasicDBObject("date", "3").append("_id", 3));
    ObjectId id = new ObjectId();
    collection.insert(new BasicDBObject("date", true).append("_id", id));
    collection.insert(new BasicDBObject("date", null).append("_id", 5));
    collection.insert(new BasicDBObject("date", 6L).append("_id", 6));
    collection.insert(new BasicDBObject("date", Util.list(1, 2, 3)).append("_id", 7));
    collection.insert(new BasicDBObject("date", Util.list(1D, 2L, "3", 4)).append("_id", 8));
    collection.insert(new BasicDBObject("date", Util.list(Util.list(1D, 2L, "3", 4))).append("_id", 9));
    collection.insert(new BasicDBObject("date", 2F).append("_id", 10));
    collection.insert(new BasicDBObject("date", new BasicDBObject("x", 1)).append("_id", 11));

    // When
    List objects = collection.find(new BasicDBObject("date", new BasicDBObject("$type", 1))).toArray();
    assertEquals(Arrays.asList(
        new BasicDBObject("_id", 2).append("date", 2D),
        new BasicDBObject("date", Util.list(1D, 2L, "3", 4)).append("_id", 8),
        new BasicDBObject("date", 2F).append("_id", 10)), objects);

    // When
    // String
    objects = collection.find(new BasicDBObject("date", new BasicDBObject("$type", 2))).toArray();
    assertEquals(Arrays.asList(
        new BasicDBObject("_id", 3).append("date", "3"),
        new BasicDBObject("date", Util.list(1D, 2L, "3", 4)).append("_id", 8)), objects);

    // Integer
    objects = collection.find(new BasicDBObject("date", new BasicDBObject("$type", 16))).toArray();
    assertEquals(Arrays.asList(
        new BasicDBObject("_id", 1).append("date", 1),
        new BasicDBObject("date", Util.list(1, 2, 3)).append("_id", 7),
        new BasicDBObject("date", Util.list(1D, 2L, "3", 4)).append("_id", 8)), objects);

    // ObjectId
    objects = collection.find(new BasicDBObject("_id", new BasicDBObject("$type", 7))).toArray();
    assertEquals(Collections.singletonList(new BasicDBObject("_id", id).append("date", true)), objects);

    // Boolean
    objects = collection.find(new BasicDBObject("date", new BasicDBObject("$type", 8))).toArray();
    assertEquals(Collections.singletonList(new BasicDBObject("_id", id).append("date", true)), objects);

    // Long ?
    objects = collection.find(new BasicDBObject("date", new BasicDBObject("$type", 18))).toArray();
    assertEquals(Arrays.asList(
        new BasicDBObject("_id", 6).append("date", 6L),
        new BasicDBObject("date", Util.list(1D, 2L, "3", 4)).append("_id", 8)), objects);

    // Array ?
    objects = collection.find(new BasicDBObject("date", new BasicDBObject("$type", 4))).toArray();
    assertEquals(Arrays.asList(
        new BasicDBObject("date", Util.list(Util.list(1D, 2L, "3", 4))).append("_id", 9)), objects);

    // Null ?
    objects = collection.find(new BasicDBObject("date", new BasicDBObject("$type", 10))).toArray();
    assertEquals(Collections.singletonList(new BasicDBObject("_id", 5).append("date", null)), objects);

    // Object ?
    objects = collection.find(new BasicDBObject("date", new BasicDBObject("$type", 3))).toArray();
    assertEquals(Arrays.asList(
        new BasicDBObject("_id", 1).append("date", 1),
        new BasicDBObject("_id", 2).append("date", 2D),
        new BasicDBObject("_id", 3).append("date", "3"),
        new BasicDBObject("_id", id).append("date", true),
        new BasicDBObject("_id", 6).append("date", 6L),
        new BasicDBObject("_id", 7).append("date", Util.list(1, 2, 3)),
        new BasicDBObject("_id", 8).append("date", Util.list(1D, 2L, "3", 4)),
        new BasicDBObject("_id", 9).append("date", Util.list(Util.list(1D, 2L, "3", 4))),
        new BasicDBObject("_id", 10).append("date", 2F),
        new BasicDBObject("_id", 11).append("date", new BasicDBObject("x", 1))), objects);
  }

  static class Seq {
File
FongoTest.java
Developer's decision
Concatenation
Kind of conflict
Annotation
Comment
Method declaration
Method invocation
Method signature
Variable