Search in sources :

Example 1 with Counter

use of io.quarkus.arc.test.interceptors.Counter in project quarkus by quarkusio.

the class BridgeMethodInterceptionTest method testInterception.

@Test
public void testInterception() {
    ArcContainer container = Arc.container();
    Counter counter = container.instance(Counter.class).get();
    counter.reset();
    Submarine submarine = container.instance(Submarine.class).get();
    assertEquals("foo", submarine.echo("foo"));
    assertEquals(Submarine.class.getSimpleName(), submarine.getName());
    assertEquals(2, counter.get());
    // Now let's invoke the bridge method...
    Base<String> base = submarine;
    assertEquals("foo", base.echo("foo"));
    assertEquals(Submarine.class.getSimpleName(), base.getName());
    assertEquals(4, counter.get());
    counter.reset();
    Ubot ubot = container.instance(Ubot.class).get();
    assertEquals("1", ubot.echo(1));
    assertEquals(42, ubot.getName());
    assertEquals(2, counter.get());
    Base<Integer> baseUbot = ubot;
    assertEquals("1", baseUbot.echo(1));
    assertEquals(42, ubot.getName());
    assertEquals(4, counter.get());
    counter.reset();
    Ponorka ponorka = container.instance(Ponorka.class).get();
    assertEquals("TRUE", ponorka.echo(true));
    assertNull(ponorka.getName());
    assertEquals(2, counter.get());
    Base<Boolean> basePonorka = ponorka;
    assertEquals("TRUE", basePonorka.echo(true));
    assertNull(basePonorka.getName());
    assertEquals(4, counter.get());
    counter.reset();
    NextSubmarine nextSubmarine = container.instance(NextSubmarine.class).get();
    assertEquals("foo", nextSubmarine.echo("foo"));
    assertEquals(NextSubmarine.class.getSimpleName(), nextSubmarine.getName());
    assertEquals(2, counter.get());
    // Now let's invoke the bridge method...
    NextBase<String> nextBase = nextSubmarine;
    assertEquals("foo", nextBase.echo("foo"));
    assertEquals(NextSubmarine.class.getSimpleName(), nextBase.getName());
    assertEquals(4, counter.get());
}
Also used : ArcContainer(io.quarkus.arc.ArcContainer) Counter(io.quarkus.arc.test.interceptors.Counter) Test(org.junit.jupiter.api.Test)

Example 2 with Counter

use of io.quarkus.arc.test.interceptors.Counter in project quarkus by quarkusio.

the class BridgeMethodInterceptionTest method testHierarchyWithInterface.

@Test
public void testHierarchyWithInterface() {
    ArcContainer container = Arc.container();
    Counter counter = container.instance(Counter.class).get();
    counter.reset();
    ExampleResource exampleResource = container.instance(ExampleResource.class).get();
    assertEquals("foo", exampleResource.create("foo"));
    assertEquals(1, counter.get());
    counter.reset();
    ExampleApi exampleApi = container.instance(ExampleApi.class).get();
    assertEquals("foo", exampleApi.create("foo"));
    assertEquals(1, counter.get());
}
Also used : ArcContainer(io.quarkus.arc.ArcContainer) Counter(io.quarkus.arc.test.interceptors.Counter) Test(org.junit.jupiter.api.Test)

Example 3 with Counter

use of io.quarkus.arc.test.interceptors.Counter in project quarkus by quarkusio.

the class MethodArgsInterceptionTest method testInterception.

@Test
public void testInterception() {
    ArcContainer container = Arc.container();
    Counter counter = container.instance(Counter.class).get();
    counter.reset();
    ExampleResource exampleResource = container.instance(ExampleResource.class).get();
    assertEquals("first,second", exampleResource.create(List.of("first", "second")));
    assertEquals(1, counter.get());
    assertEquals("PackagePrivate{}", exampleResource.otherCreate(new ExampleResource.PackagePrivate()));
    assertEquals(2, counter.get());
    CustomExecutor customThreadExecutor = container.instance(CustomExecutor.class).get();
    assertEquals("run", customThreadExecutor.run());
    assertEquals(3, counter.get());
}
Also used : ArcContainer(io.quarkus.arc.ArcContainer) Counter(io.quarkus.arc.test.interceptors.Counter) Test(org.junit.jupiter.api.Test)

Aggregations

ArcContainer (io.quarkus.arc.ArcContainer)3 Counter (io.quarkus.arc.test.interceptors.Counter)3 Test (org.junit.jupiter.api.Test)3