Exemplo n.º 1
0
  @Test
  public void testLookup() {
    Lookup<IPriorityFoo> lookup = Lookups.getPriority(IPriorityFoo.class);

    // This should only be ImplB, which has the highest priority.
    IFoo myFoo = lookup.lookup();
    LOG.info("Got foo implementation: " + myFoo.getClass().getName());
    assertTrue(myFoo instanceof Providers.PriorityImplB);

    String result = myFoo.getMessage();
    LOG.info("Got result string: " + result);
    assertEquals("priorityimplB", result);
  }
Exemplo n.º 2
0
  @Test
  public void testMultiLookup() {
    Lookup<IPriorityFoo> lookup = Lookups.getPriority(IPriorityFoo.class);

    // We should get back a list of providers, ImplB followed by ImplA,
    // according to their priority order.
    List<IFoo> foos = new ArrayList<IFoo>();
    for (IFoo foo : lookup) {
      foos.add(foo);
    }

    assertEquals("expected two implementations", 2, foos.size());

    LOG.info("First impl class: " + foos.get(0).getClass().getName());
    LOG.info("Second impl class: " + foos.get(1).getClass().getName());

    assertTrue("expected implb first", foos.get(0) instanceof Providers.PriorityImplB);
    assertTrue("expected impla next", foos.get(1) instanceof Providers.PriorityImplA);
  }