Skip to content

Commit

Permalink
Don't use random in a handler test
Browse files Browse the repository at this point in the history
  • Loading branch information
P3ridot committed Jul 18, 2023
1 parent 18f9cf2 commit 40496cd
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class DependencyInjectionHandlerTest {

@Injectable
@Retention(RetentionPolicy.RUNTIME)
@interface AwesomeRandom { }
@interface TestAnnotation { }

public static class Service1 {

Expand All @@ -32,15 +32,15 @@ public static class Service1 {
public int fieldTwo;

@Inject
@AwesomeRandom
@TestAnnotation
public int fieldThree;

@PostConstruct
public void construct() {
assertEquals("HelloWorld", this.fieldOne);

assertEquals(7, this.fieldTwo);
assertTrue(this.fieldTwo >= 2 && this.fieldTwo <= 10);
assertEquals(2, this.fieldThree);
}

}
Expand All @@ -50,11 +50,11 @@ void shouldCreateInstance() {
Injector injector = DependencyInjection.createInjector(resources -> {
resources.annotatedWith(Custom.class).assignHandler((type, annotation, args) -> "HelloWorld");
resources.on(int.class).assignHandler((type, annotation, args) -> {
AwesomeRandom randomAnnotation = type.getAnnotation(AwesomeRandom.class);
if (randomAnnotation == null) {
TestAnnotation testAnnotation = type.getAnnotation(TestAnnotation.class);
if (testAnnotation == null) {
return 7;
}
return ThreadLocalRandom.current().nextInt(2, 10);
return 2;
});
});

Expand Down

0 comments on commit 40496cd

Please sign in to comment.