Skip to content

Commit

Permalink
#256 - Support the case of @factory @bean that needs to use fully qua…
Browse files Browse the repository at this point in the history
…lified class name (short name clashes)
  • Loading branch information
rbygrave committed Jan 11, 2023
1 parent ddc5cbc commit d66451c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.example.myapp.config;

import io.avaje.inject.Bean;
import io.avaje.inject.Factory;

@Factory
public class DupShortNameFactory {

@Bean
MyDup one() {
return new MyDup();
}

/**
* Requires fully qualified name as short name of MyDup clashes.
*/
@Bean
org.example.myapp.config.MyDup two() {
return new org.example.myapp.config.MyDup();
}

public static class MyDup {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.example.myapp.config;

public class MyDup {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.example.myapp.config;

import io.avaje.inject.BeanScope;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;

class DupShortNameFactoryTest {

@Test
void factoryBeanRequiringFullyQualifiedName() {
try (BeanScope testScope = BeanScope.builder().build()) {
// both have short name of MyDup
var one = testScope.get(org.example.myapp.config.MyDup.class);
var two = testScope.get(DupShortNameFactory.MyDup.class);

assertNotNull(one);
assertNotNull(two);
assertThat(one).isNotSameAs(two);
}
}
}

0 comments on commit d66451c

Please sign in to comment.