Exemplo n.º 1
0
  @Test
  public void testClassNames() {
    Document doc = Jsoup.parse("<div class=\"c1 c2\">C</div>");
    Element div = doc.select("div").get(0);

    assertEquals("c1 c2", div.className());

    final Set<String> set1 = div.classNames();
    final Object[] arr1 = set1.toArray();
    assertTrue(arr1.length == 2);
    assertEquals("c1", arr1[0]);
    assertEquals("c2", arr1[1]);

    // Changes to the set should not be reflected in the Elements getters
    set1.add("c3");
    assertTrue(2 == div.classNames().size());
    assertEquals("c1 c2", div.className());

    // Update the class names to a fresh set
    final Set<String> newSet = new LinkedHashSet<String>(3);
    newSet.addAll(set1);
    newSet.add("c3");

    div.classNames(newSet);

    assertEquals("c1 c2 c3", div.className());

    final Set<String> set2 = div.classNames();
    final Object[] arr2 = set2.toArray();
    assertTrue(arr2.length == 3);
    assertEquals("c1", arr2[0]);
    assertEquals("c2", arr2[1]);
    assertEquals("c3", arr2[2]);
  }
Exemplo n.º 2
0
  @Test
  public void testQueryParams() {

    Map<String, String[]> params = new HashMap<>();
    params.put("sort", new String[] {"asc"});
    params.put("items", new String[] {"10"});

    when(servletRequest.getParameterMap()).thenReturn(params);

    Set<String> result = request.queryParams();

    assertArrayEquals(
        "Should return the query parameter names", params.keySet().toArray(), result.toArray());
  }
Exemplo n.º 3
0
 private static void compare_order(Set<?> expected, Set<?> actual) {
   assertArrayEquals(expected.toArray(), actual.toArray());
 }