Skip to content

Commit 6db1299

Browse files
committed
build: add constructor tests for DI vs No_DI controllers
1 parent 23dbed6 commit 6db1299

3 files changed

Lines changed: 84 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Jooby https://jooby.io
3+
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
4+
* Copyright 2014 Edgar Espina
5+
*/
6+
package tests.instance;
7+
8+
import io.jooby.annotation.GET;
9+
import jakarta.inject.Inject;
10+
11+
public class DIController {
12+
private final NoDIController controller;
13+
14+
@Inject
15+
public DIController(NoDIController controller) {
16+
this.controller = controller;
17+
}
18+
19+
@GET("/di")
20+
public String di() {
21+
return controller.noDI();
22+
}
23+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Jooby https://jooby.io
3+
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
4+
* Copyright 2014 Edgar Espina
5+
*/
6+
package tests.instance;
7+
8+
import static org.assertj.core.api.Assertions.assertThat;
9+
10+
import org.junit.jupiter.api.Test;
11+
12+
import io.jooby.apt.ProcessorRunner;
13+
14+
public class DefaultControllerTest {
15+
16+
@Test
17+
public void shouldGenerateDIDefaultConstructor() throws Exception {
18+
new ProcessorRunner(new DIController(new NoDIController()))
19+
.withSourceCode(
20+
source -> {
21+
assertThat(source)
22+
.containsIgnoringWhitespaces(
23+
"""
24+
public DIController_() {
25+
this(DIController.class);
26+
}
27+
""");
28+
});
29+
}
30+
31+
@Test
32+
public void shouldGenerateDefaultConstructorWithoutDI() throws Exception {
33+
new ProcessorRunner(new NoDIController())
34+
.withSourceCode(
35+
source -> {
36+
assertThat(source)
37+
.containsIgnoringWhitespaces(
38+
"""
39+
public NoDIController_() {
40+
this(io.jooby.SneakyThrows.singleton(NoDIController::new));
41+
}
42+
""");
43+
});
44+
}
45+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Jooby https://jooby.io
3+
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
4+
* Copyright 2014 Edgar Espina
5+
*/
6+
package tests.instance;
7+
8+
import io.jooby.annotation.GET;
9+
10+
public class NoDIController {
11+
12+
@GET("/no-di")
13+
public String noDI() {
14+
return "no-di";
15+
}
16+
}

0 commit comments

Comments
 (0)