Пример #1
0
  @Test
  public void testDefaultMethodInInterface() throws Exception {
    final CtInterface<?> ctInterface =
        (CtInterface<?>) factory.Type().get(InterfaceWithDefaultMethods.class);

    final CtMethod<?> ctMethod = ctInterface.getMethodsByName("getZonedDateTime").get(0);
    assertTrue("The method in the interface must to be default", ctMethod.isDefaultMethod());

    final String expected =
        "default java.time.ZonedDateTime getZonedDateTime(java.lang.String zoneString) {"
            + System.lineSeparator()
            + "    return java.time.ZonedDateTime.of(getLocalDateTime(), spoon.test.interfaces.testclasses.InterfaceWithDefaultMethods.getZoneId(zoneString));"
            + System.lineSeparator()
            + "}";
    assertEquals("The default method must to be well printed", expected, ctMethod.toString());
  }
Пример #2
0
  @Test
  public void testRedefinesStaticMethodInSubInterface() throws Exception {
    final CtInterface<?> ctInterface =
        (CtInterface<?>) factory.Type().get(RedefinesStaticMethodInterface.class);

    assertEquals(
        "Sub interface must have only one method in its interface",
        1,
        ctInterface.getMethods().size());
    assertEquals(
        "Sub interface must have 6+12(from java.lang.Object) methods in its interface and its super interfaces",
        18,
        ctInterface.getAllMethods().size());

    final CtMethod<?> getZoneIdMethod = ctInterface.getMethodsByName("getZoneId").get(0);
    assertFalse(
        "Method in the sub interface mustn't be a static method",
        getZoneIdMethod.getModifiers().contains(ModifierKind.STATIC));
    assertEquals(
        "Interface of the static method must be the sub interface",
        RedefinesStaticMethodInterface.class,
        getZoneIdMethod.getDeclaringType().getActualClass());
  }
Пример #3
0
  @Test
  public void testRedefinesDefaultMethodInSubInterface() throws Exception {
    final CtInterface<?> ctInterface =
        (CtInterface<?>) factory.Type().get(RedefinesDefaultMethodInterface.class);

    assertEquals(
        "Sub interface must have only one method in its interface",
        1,
        ctInterface.getMethods().size());
    assertEquals(
        "Sub interface must have 6+12(from java.lang.Object) methods in its interface and its super interfaces",
        18,
        ctInterface.getAllMethods().size());

    final CtMethod<?> getZonedDateTimeMethod =
        ctInterface.getMethodsByName("getZonedDateTime").get(0);
    assertFalse(
        "Method in the sub interface mustn't be a default method",
        getZonedDateTimeMethod.isDefaultMethod());
    assertEquals(
        "Interface of the default method must be the sub interface",
        RedefinesDefaultMethodInterface.class,
        getZonedDateTimeMethod.getDeclaringType().getActualClass());
  }