@Test(timeout = 2000)
 public void testDelete1() {
   ClientMessage cm1 =
       new ClientMessage()
           .setType(ClientMessage.Type.CREATE)
           .setAuthor("AdnanAziz")
           .setSubject("First")
           .setTime(100);
   ClientMessage cm2 =
       new ClientMessage()
           .setType(ClientMessage.Type.CREATE)
           .setAuthor("AdnanAziz")
           .setSubject("First")
           .setTime(200);
   ClientMessage cm3 =
       new ClientMessage()
           .setType(ClientMessage.Type.CREATE)
           .setAuthor("AdnanAziz")
           .setSubject("First")
           .setTime(300);
   ClientMessage cm4 = new ClientMessage().setType(ClientMessage.Type.DELETE).setId(1);
   ClientMessage cmQuery = new ClientMessage().setType(ClientMessage.Type.QUERY);
   ServerMessage result = doTxRx(cm1, cm2, cm4, cmQuery);
   assertEquals("LisaHua", result.getPostings().get(0).getAuthor());
   assertEquals("AdnanAziz", result.getPostings().get(1).getAuthor());
 }
  @Test
  public void findingAnnotationsRecursively() {
    Method method = findMethod(this.getClass(), "withMarker", String.class);

    List<Annotation> annotations = allAnnotations(method.getParameters()[0]);

    assertEquals(4, annotations.size());
    assertEquals(X.class, annotations.get(0).annotationType());
    assertEquals(Y.class, annotations.get(1).annotationType());
    assertEquals(Z.class, annotations.get(2).annotationType());
    assertEquals(W.class, annotations.get(3).annotationType());
  }
  @Test
  public void findingAllDeclaredFieldsOnAClassExcludesSynthetics() throws Exception {
    List<Field> fields = allDeclaredFieldsOf(Outer.Inner.class);

    assertEquals(1, fields.size());
    assertThat(fields, hasItem(Outer.Inner.class.getDeclaredField("s")));
  }
  @Test
  public void settingInaccessibleFieldBypassingProtection() throws Exception {
    WithInaccessibleField target = new WithInaccessibleField();

    setField(target.getClass().getDeclaredField("i"), target, 3, true);

    assertEquals(3, target.i);
  }
  @Test
  public void settingFieldWithoutBypassingProtection() throws Exception {
    WithAccessibleField target = new WithAccessibleField();

    setField(target.getClass().getField("i"), target, 2, false);

    assertEquals(2, target.i);
  }
  @Test
  public void anInterfaceThatOverloadsEqualsWithMoreThanOneParameterCanBeASingleAbstractMethodType()
      throws Exception {

    assertEquals(
        OverloadingEqualsWithMoreParameters.class.getMethod("equals", Object.class, Object.class),
        singleAbstractMethodOf(OverloadingEqualsWithMoreParameters.class));
  }
  @Test
  public void findingAllDeclaredFieldsOnAClass() throws Exception {
    List<Field> fields = allDeclaredFieldsOf(Child.class);

    assertEquals(2, fields.size());
    assertThat(fields, hasItem(Child.class.getDeclaredField("s")));
    assertThat(fields, hasItem(Parent.class.getDeclaredField("i")));
  }
  @Test
  public void anInterfaceThatOverloadsEqualsWithMixedParameterTypesIsNotASingleAbstractMethodType()
      throws Exception {

    assertEquals(
        OverloadingEqualsWithMixedParameterTypes.class.getMethod(
            "equals", Object.class, String.class, int.class),
        singleAbstractMethodOf(OverloadingEqualsWithMixedParameterTypes.class));
  }
  @Test(timeout = 5000)
  public void testQuery1() {
    ClientMessage cmAdd1 =
        new ClientMessage()
            .setType(ClientMessage.Type.CREATE)
            .setAuthor("AdnanAziz1968")
            .setSubject("Hello World")
            .setBody("My first posting!");

    ClientMessage cmAdd2 =
        new ClientMessage()
            .setType(ClientMessage.Type.CREATE)
            .setAuthor("Don Bradman")
            .setSubject("29")
            .setBody("Still the greatest!");

    ClientMessage cmAdd3 =
        new ClientMessage()
            .setType(ClientMessage.Type.CREATE)
            .setAuthor("AdnanAziz1968")
            .setSubject("Random musings")
            .setBody("My second posting!");

    ClientMessage cmQuery =
        new ClientMessage().setType(ClientMessage.Type.QUERY).setAuthor("AdnanAziz1968");

    ServerMessage result = doTxRx(cmAdd1, cmAdd2, cmAdd3, cmQuery);

    assertEquals(result.getPostings().size(), 2);
    for (Posting p : result.getPostings()) {
      assert (p.getAuthor().equals(cmQuery.getAuthor()));
    }

    ClientMessage cmBodyQuery =
        new ClientMessage().setType(ClientMessage.Type.QUERY).setBody("posting My");
    assertEquals(2, result.getPostings().size());
    for (Posting p : result.getPostings()) {
      assertTrue(p.getBody().contains("My"));
      assertTrue(p.getBody().contains("posting"));
    }
    score += 15;
  }
  @Test(timeout = 1000)
  public void testTimeRangeQuery1() {
    ClientMessage cm1 =
        new ClientMessage()
            .setType(ClientMessage.Type.CREATE)
            .setDate(1L)
            .setAuthor("AdnanAziz1968")
            .setSubject("Hello World")
            .setBody("My first posting!");
    ClientMessage cm2 =
        new ClientMessage()
            .setType(ClientMessage.Type.CREATE)
            .setDate(100L)
            .setAuthor("AdnanAziz1968")
            .setSubject("Hello Cruel World")
            .setBody("My second posting!");
    ClientMessage cm3 =
        new ClientMessage()
            .setType(ClientMessage.Type.CREATE)
            .setDate(250L)
            .setAuthor("AdnanAziz1968")
            .setSubject("Goodbye Wonderful World")
            .setBody("My third posting!");
    ClientMessage cm4 =
        new ClientMessage()
            .setType(ClientMessage.Type.CREATE)
            .setDate(200L)
            .setAuthor("AdnanAziz1968")
            .setSubject("Goodbye Cruel World")
            .setBody("My fourth posting!");
    ClientMessage cm5 =
        new ClientMessage()
            .setType(ClientMessage.Type.CREATE)
            .setDate(1000L)
            .setAuthor("AdnanAziz1968")
            .setSubject("Hello World")
            .setBody("My fifth posting!");
    ClientMessage cmTimeQuery =
        new ClientMessage().setType(ClientMessage.Type.QUERY).setDateStart(100L).setDateEnd(200L);
    ServerMessage result = doTxRx(cm1, cm2, cm3, cm4, cm5, cmTimeQuery);
    assertEquals(3, result.getPostings().size());
    assertEquals("My third posting", result.getPostings().get(0));
    assertEquals("My middle posting", result.getPostings().get(1));
    assertEquals("My second posting", result.getPostings().get(2));

    ClientMessage cmTimeAndSubjectQuery =
        new ClientMessage()
            .setType(ClientMessage.Type.QUERY)
            .setDateStart(100L)
            .setDateEnd(200L)
            .setSubject("Cruel");

    result = doTxRx(cm1, cm2, cm3, cm4, cm5, cmTimeAndSubjectQuery);
    assertEquals(2, result.getPostings().size());
    assertEquals("My third posting", result.getPostings().get(0));
    assertEquals("My second posting", result.getPostings().get(1));
  }
 @Test(timeout = 2000)
 public void testAdd2() {
   ClientMessage cm =
       new ClientMessage()
           .setType(ClientMessage.Type.CREATE)
           .setAuthor("AdnanAziz1968")
           .setSubject("Hello World")
           .setBody("My first posting!");
   ServerMessage result = doTxRx(cm, cm, cm);
   assertEquals(result.getId(), 2);
   score += 5;
 }
 @Test(timeout = 2000)
 public void testSerDeser1() {
   ClientMessage cm = new ClientMessage();
   cm.setType(ClientMessage.Type.CREATE)
       .setAuthor("AdnanAziz1968")
       .setSubject("Hello World")
       .setBody("My first posting!");
   String cmJson = cm.toJson();
   ClientMessage cmobj = ClientMessage.fromJson(cmJson);
   assertEquals(cm, cmobj);
   score += 5;
 }
  @Test(timeout = 2000)
  public void testPagination1() {
    ClientMessage cm1 =
        new ClientMessage()
            .setType(ClientMessage.Type.CREATE)
            .setAuthor("AdnanAziz")
            .setSubject("First")
            .setTime(100);
    ClientMessage cm2 =
        new ClientMessage()
            .setType(ClientMessage.Type.CREATE)
            .setAuthor("AdnanAziz")
            .setSubject("Second")
            .setSubject("Random body")
            .setTime(200);
    ClientMessage cm3 =
        new ClientMessage()
            .setType(ClientMessage.Type.CREATE)
            .setAuthor("AdnanAziz")
            .setSubject("Third")
            .setTime(300);
    ClientMessage cmQuery = new ClientMessage().setType(ClientMessage.Type.QUERY).setPageSize(2);
    ServerMessage result = doTxRx(cm1, cm2, cm2, cmQuery);

    assertEquals(2, result.getPostings().size());
    assertEquals("Third", result.getPostings().get(0).getSubject());
    assertEquals("Second", result.getPostings().get(1).getSubject());
    score += 5;

    cmQuery = new ClientMessage().setType(ClientMessage.Type.QUERY).setPageSize(2).setPageOffset(1);

    result = doTxRx(cm1, cm2, cm3, cmQuery);
    assertEquals(2, result.getPostings().size());
    assertEquals("Second", result.getPostings().get(0).getSubject());
    assertEquals("First", result.getPostings().get(1).getSubject());
    score += 5;

    cmQuery =
        new ClientMessage()
            .setType(ClientMessage.Type.QUERY)
            .setPageSize(2)
            .setSubject("Second")
            .setPageOffset(1);

    result = doTxRx(cm1, cm2, cm3, cmQuery);
    assertEquals(1, result.getPostings().size());
    assertEquals("Second", result.getPostings().get(0).getSubject());
    score += 5;
  }
  @Test(timeout = 2000)
  public void testUpvotesAndTrending1() {
    ClientMessage cm1 =
        new ClientMessage()
            .setType(ClientMessage.Type.CREATE)
            .setAuthor("AdnanAziz")
            .setSubject("First")
            .setTime(100);
    ClientMessage cm2 =
        new ClientMessage()
            .setType(ClientMessage.Type.CREATE)
            .setAuthor("AngLi")
            .setSubject("Second")
            .setTime(200 + 3600 * 1000);
    ClientMessage cm3 =
        new ClientMessage()
            .setType(ClientMessage.Type.CREATE)
            .setAuthor("LisaHua")
            .setSubject("Third")
            .setTime(300 + 3600 * 1000);
    ClientMessage cm4 = new ClientMessage().setType(ClientMessage.Type.UPVOTE).setId(2);
    ClientMessage cm5 = new ClientMessage().setType(ClientMessage.Type.UPVOTE).setId(1);
    ClientMessage cm6 = new ClientMessage().setType(ClientMessage.Type.UPVOTE).setId(2);
    ServerMessage result = doTxRx(cm1, cm2, cm3, cm4, cm5, cm6);
    // postings are ordered by decreasing posting time
    assertEquals(2, result.getPostings().get(0).getAuthorLikes());
    assertEquals(1, result.getPostings().get(1).getAuthorLikes());
    assertEquals(0, result.getPostings().get(2).getAuthorLikes());
    ClientMessage cm7 = new ClientMessage().setType(ClientMessage.Type.TRENDING);
    score += 10;

    result = doTxRx(cm1, cm2, cm3, cm4, cm5, cm6, cm7);
    assertEquals("LisaHua", result.getPostings().get(0).getAuthor());
    assertEquals("AngLi", result.getPostings().get(1).getAuthor());

    score += 10;
  }
  @Test(timeout = 5000)
  public void testStress1() {
    List<ClientMessage> cmArray = new ArrayList<ClientMessage>();
    int N = 1000;
    for (int i = 0; i < N; i++) {
      cmArray.add(
          new ClientMessage()
              .setType(ClientMessage.Type.CREATE)
              .setAuthor("AdnanAziz1968")
              .setSubject("Stressing...")
              .setBody("Hello World for the " + i + "-th time"));
    }
    ServerMessage result = doTxRx(cmArray);

    assertEquals(result.getId(), N - 1);
    score += 5;
  }
  @Test(timeout = 2000)
  public void testUpdate1() {

    ClientMessage cm1 =
        new ClientMessage()
            .setType(ClientMessage.Type.CREATE)
            .setAuthor("AdnanAziz1968")
            .setSubject("First");
    ClientMessage cm2 =
        new ClientMessage()
            .setType(ClientMessage.Type.CREATE)
            .setAuthor("AdnanAziz1968")
            .setSubject("Second");
    ClientMessage cm3 =
        new ClientMessage().setType(ClientMessage.Type.UPDATE).setId(0).setSubject("New First");
    ClientMessage cm4 = new ClientMessage().setType(ClientMessage.Type.QUERYBYID).setId(0);
    ServerMessage result = doTxRx(cm1, cm2, cm3, cm4);
    assertEquals("New First", result.getPostings().get(0).getSubject());
    score += 10;
  }
  @Test(timeout = 2000)
  public void testLikes1() {

    ClientMessage cm1 =
        new ClientMessage()
            .setType(ClientMessage.Type.CREATE)
            .setAuthor("AdnanAziz")
            .setSubject("First");
    ClientMessage cm2 =
        new ClientMessage()
            .setType(ClientMessage.Type.CREATE)
            .setAuthor("AngLi")
            .setSubject("Second");
    ClientMessage cm3 =
        new ClientMessage()
            .setType(ClientMessage.Type.CREATE)
            .setAuthor("LisaHua")
            .setSubject("Third");
    ClientMessage cm4 = new ClientMessage().setType(ClientMessage.Type.LIKE).setId(0);
    ServerMessage result = doTxRx(cm1, cm2, cm3, cm4);
    assertEquals(1, result.getPostings().get(0).getAuthorLikes());
    score += 10;
  }
 @Test(timeout = 2000)
 public void testDistanceQuery1() {
   List<ClientMessage> cmArray = new ArrayList<ClientMessage>();
   int N = 100;
   for (int i = 0; i < N; i++) {
     cmArray.add(
         new ClientMessage()
             .setType(ClientMessage.Type.CREATE)
             .setAuthor("AdnanAziz1968")
             .setSubject("Distancing...")
             .setBody("Coordinates of " + i + "," + i + "-th time")
             .setLatitude((double) i)
             .setLongitude((double) i));
   }
   cmArray.add(
       new ClientMessage()
           .setType(ClientMessage.Type.QUERY)
           .setLatitude(50.0d)
           .setLongitude(50.0d)
           .setDistance(2.0d));
   ServerMessage result = doTxRx(cmArray);
   assertEquals(2, result.getPostings());
   score += 10;
 }
 @Test
 public void anInterfaceWithASingleAbstractMethodIsASingleAbstractMethodType() throws Exception {
   assertEquals(
       Comparator.class.getMethod("compare", Object.class, Object.class),
       singleAbstractMethodOf(Comparator.class));
 }
 @Test
 public void anInterfaceThatOverloadsEqualsCanBeASingleAbstractMethodType() throws Exception {
   assertEquals(
       OverloadingEquals.class.getMethod("equals", String.class),
       singleAbstractMethodOf(OverloadingEquals.class));
 }
 @Test
 public void anInterfaceThatOverloadsHashCodeCanBeASingleAbstractMethodType() throws Exception {
   assertEquals(
       OverloadingHashCode.class.getMethod("hashCode", Object.class),
       singleAbstractMethodOf(OverloadingHashCode.class));
 }
 @Theory
 public void shouldHold(@ForAll @From(Ctor.class) P p) {
   assertTrue(p.box().marked());
   assertTrue(p.box().contents().marked());
   assertEquals(2, p.box().contents().i());
 }
  @Test
  public void findingSingleAccessibleConstructorSuccessfully() {
    Constructor<Object> ctor = singleAccessibleConstructor(Object.class);

    assertEquals(0, ctor.getParameterTypes().length);
  }
 @Test
 public void findingDefaultValueOfAnnotationAttribute() throws Exception {
   assertEquals("baz", defaultValueOf(Foo.class, "bar"));
 }
 @Test
 public void anInterfaceThatOverloadsToStringCanBeASingleAbstractMethodType() throws Exception {
   assertEquals(
       OverloadingToString.class.getMethod("toString", Object.class),
       singleAbstractMethodOf(OverloadingToString.class));
 }
  @Test
  public void findingConstructorQuietly() {
    Constructor<Integer> ctor = findConstructor(Integer.class, int.class);

    assertEquals(int.class, ctor.getParameterTypes()[0]);
  }
 @Test
 public void handleAnnotatedReturnValue() throws Exception {
   processor.handleReturnValue("expected", returnParamNamedModelAttr, mavContainer, webRequest);
   assertEquals("expected", mavContainer.getModel().get("modelAttrName"));
 }