Exemplo n.º 1
0
  @Test
  public void testFirstEmpty() {
    Collection<String> collection = new HashSet<String>();

    assertTrue(Groups.first(collection) == null);

    collection.add("Hello World");
    assertTrue(Groups.first(collection).equals("Hello World"));

    collection.add("Goodbye World");
    assertTrue(collection.contains(Groups.first(collection)));
  }
Exemplo n.º 2
0
  @Test
  public void testCookies_whenCookiesArePresent() {

    Collection<Cookie> cookies = new ArrayList<>();
    cookies.add(new Cookie("cookie1", "cookie1value"));
    cookies.add(new Cookie("cookie2", "cookie2value"));

    Map<String, String> expected = new HashMap<>();
    for (Cookie cookie : cookies) {
      expected.put(cookie.getName(), cookie.getValue());
    }

    Cookie[] cookieArray = cookies.toArray(new Cookie[cookies.size()]);

    when(servletRequest.getCookies()).thenReturn(cookieArray);

    assertTrue(
        "The count of cookies returned should be the same as those in the request",
        request.cookies().size() == 2);

    assertEquals(
        "A Map of Cookies should have been returned because they exist",
        expected,
        request.cookies());
  }
Exemplo n.º 3
0
  @Test
  public void testOfType() {
    Collection<A> collection = new HashSet<A>();
    collection.add(new A());
    collection.add(new B());
    collection.add(new B());
    collection.add(new A());
    collection.add(new B());
    collection.add(new A());
    collection.add(new A());
    collection.add(new C());

    assertTrue(Groups.ofType(A.class, collection).size() == 8);
    assertTrue(Groups.ofType(B.class, collection).size() == 3);
    assertTrue(Groups.ofType(C.class, collection).size() == 1);
  }
Exemplo n.º 4
0
  @Test
  public void testContainsType() {
    Collection<A> collection = new HashSet<A>();
    collection.add(new B());
    collection.add(new B());

    assertTrue(Groups.containsType(A.class, collection));
    assertTrue(Groups.containsType(B.class, collection));
    assertFalse(Groups.containsType(C.class, collection));
  }
Exemplo n.º 5
0
  @Test
  public void testFirstOfType() {
    Collection<A> collection = new HashSet<A>();
    collection.add(new B());
    collection.add(new B());

    assertTrue(Groups.firstOfType(C.class, collection) == null);
    assertTrue(collection.contains(Groups.firstOfType(A.class, collection)));
    assertTrue(collection.contains(Groups.firstOfType(B.class, collection)));
  }
Exemplo n.º 6
0
 @Test
 public void test_publicInterfaceRef_annotation_present() {
   Collection<Integer> elements = new ArrayList<>();
   for (int i = 0; i < 15; i++) {
     assertSame(
         BasicConstSet.class,
         asSet(elements).getClass().getAnnotation(PublicInterfaceRef.class).value());
     elements.add(i);
   }
 }
  @Test
  public void testTriangle() {
    final Road[] roads = {new Road("A", "B"), new Road("B", "C"), new Road("A", "C")};

    Collection<Road> city = new HashSet<Road>();
    for (Road r : roads) {
      city.add(r);
    }
    final CityCameraPlanner cameraPlanner = new CityCameraPlanner(city);
    assertEquals(0, cameraPlanner.getCameras().size());
    assertFalse(cameraPlanner.getCameras().contains("B"));
  }
 /** Test of setVoters method, of class ValidatorElectionEvent. */
 @Test
 public void testSetVoters() {
   System.out.println("setVoters");
   ValidatorElectionEvent instance = new ValidatorElectionEvent();
   ValidatorVoter a = new ValidatorVoter();
   Collection<ValidatorVoter> b = new ArrayList<ValidatorVoter>();
   b.add(a);
   instance.setVoters(b);
   Collection expResult = b;
   Collection result = instance.getVoters();
   assertEquals(expResult, result);
 }
 /** Test of getCandidates method, of class ValidatorElectionEvent. */
 @Test
 public void testGetCandidates() {
   System.out.println("getCandidates");
   ValidatorElectionEvent instance = new ValidatorElectionEvent();
   ValidatorCandidate a = new ValidatorCandidate();
   Collection<ValidatorCandidate> b = new ArrayList<ValidatorCandidate>();
   b.add(a);
   instance.setCandidates(b);
   Collection expResult = b;
   Collection result = instance.getCandidates();
   assertEquals(expResult, result);
 }
Exemplo n.º 10
0
  @Test
  public void testAddAll() throws IOException {
    final int maxItems = 13;
    final IQueue q = client.getQueue(randomString());

    Collection coll = new ArrayList(maxItems);

    for (int i = 0; i < maxItems; i++) {
      coll.add(i);
    }

    assertTrue(q.addAll(coll));
    assertEquals(coll.size(), q.size());
  }
Exemplo n.º 11
0
  private void testDontPurgeAccidentaly(String k, String cfname)
      throws IOException, ExecutionException, InterruptedException {
    // This test catches the regression of CASSANDRA-2786
    Keyspace keyspace = Keyspace.open(KEYSPACE1);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfname);

    // disable compaction while flushing
    cfs.clearUnsafe();
    cfs.disableAutoCompaction();

    // Add test row
    DecoratedKey key = Util.dk(k);
    RowMutation rm = new RowMutation(KEYSPACE1, key.key);
    rm.add(
        cfname,
        CompositeType.build(ByteBufferUtil.bytes("sc"), ByteBufferUtil.bytes("c")),
        ByteBufferUtil.EMPTY_BYTE_BUFFER,
        0);
    rm.apply();

    cfs.forceBlockingFlush();

    Collection<SSTableReader> sstablesBefore = cfs.getSSTables();

    QueryFilter filter = QueryFilter.getIdentityFilter(key, cfname, System.currentTimeMillis());
    assert !(cfs.getColumnFamily(filter).getColumnCount() == 0);

    // Remove key
    rm = new RowMutation(KEYSPACE1, key.key);
    rm.delete(cfname, 2);
    rm.apply();

    ColumnFamily cf = cfs.getColumnFamily(filter);
    assert cf == null || cf.getColumnCount() == 0 : "should be empty: " + cf;

    // Sleep one second so that the removal is indeed purgeable even with gcgrace == 0
    Thread.sleep(1000);

    cfs.forceBlockingFlush();

    Collection<SSTableReader> sstablesAfter = cfs.getSSTables();
    Collection<SSTableReader> toCompact = new ArrayList<SSTableReader>();
    for (SSTableReader sstable : sstablesAfter)
      if (!sstablesBefore.contains(sstable)) toCompact.add(sstable);

    Util.compact(cfs, toCompact);

    cf = cfs.getColumnFamily(filter);
    assert cf == null || cf.getColumnCount() == 0 : "should be empty: " + cf;
  }
  @Test
  public void testExample1() {
    final Road[] roads = {
      new Road("A", "B"), new Road("B", "C"), new Road("C", "D"), new Road("D", "B")
    };

    Collection<Road> city = new HashSet<Road>();
    for (Road r : roads) {
      city.add(r);
    }
    final CityCameraPlanner cameraPlanner = new CityCameraPlanner(city);
    System.out.println(cameraPlanner.getCameras());
    assertEquals(1, cameraPlanner.getCameras().size());
    assertTrue(cameraPlanner.getCameras().contains("B"));
  }
  @Test
  public void testGraph() {
    final Road[] roads = {
      new Road("A", "B"), new Road("B", "C"), new Road("C", "D"), new Road("D", "B")
    };

    Collection<Road> city = new HashSet<Road>();
    for (Road r : roads) {
      city.add(r);
    }
    final CityCameraPlanner cameraPlanner = new CityCameraPlanner(city);
    Neighborhood B = cameraPlanner.getTheCity().get("B");
    cameraPlanner.resetVisited();
    assertTrue(cameraPlanner.isConnected());
    cameraPlanner.removeNeighborhood(B);
    cameraPlanner.resetVisited();
    assertFalse(cameraPlanner.isConnected());
    cameraPlanner.addNeighborhood(B);
    cameraPlanner.resetVisited();
    assertTrue(cameraPlanner.isConnected());
  }
Exemplo n.º 14
0
  @Test
  public void testCookie_whenCookiesArePresent() {

    final String cookieKey = "cookie1";
    final String cookieValue = "cookie1value";

    Collection<Cookie> cookies = new ArrayList<>();
    cookies.add(new Cookie(cookieKey, cookieValue));

    Cookie[] cookieArray = cookies.toArray(new Cookie[cookies.size()]);
    when(servletRequest.getCookies()).thenReturn(cookieArray);

    assertNotNull(
        "A value for the key provided should exist because a cookie with the same key is present",
        request.cookie(cookieKey));

    assertEquals(
        "The correct value for the cookie key supplied should be returned",
        cookieValue,
        request.cookie(cookieKey));
  }