Skip to content

Commit 75db941

Browse files
SdkComponentFactory: Add test showing problem with ambiguous components
Add 3 component implementation for the same version and component type. Which implementation is returned by getComponentImpl is currently arbitrary.
1 parent c460889 commit 75db941

4 files changed

Lines changed: 41 additions & 0 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package eu.europa.ted.eforms.sdk.component;
2+
3+
@SdkComponent(versions = "1", componentType = SdkComponentType.SCRIPT_GENERATOR)
4+
class ScriptGeneratorA implements TestComponent {
5+
6+
@Override
7+
public String testMethod() {
8+
return "A";
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package eu.europa.ted.eforms.sdk.component;
2+
3+
@SdkComponent(versions = "1", componentType = SdkComponentType.SCRIPT_GENERATOR)
4+
class ScriptGeneratorB implements TestComponent {
5+
6+
@Override
7+
public String testMethod() {
8+
return "B";
9+
}
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package eu.europa.ted.eforms.sdk.component;
2+
3+
class ScriptGeneratorSubclass extends ScriptGeneratorA {
4+
5+
@Override
6+
public String testMethod() {
7+
return "Subclass";
8+
}
9+
}

src/test/java/eu/europa/ted/eforms/sdk/component/SdkComponentFactoryTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,16 @@ void testGetComponentImpl() throws InstantiationException {
1212
factory.getComponentImpl("0.5", SdkComponentType.EFX_EXPRESSION_TRANSLATOR, TestComponent.class);
1313
assertEquals(MyComponent.class, impl.getClass());
1414
}
15+
16+
@Test
17+
void testMultipleComponentImpl() throws InstantiationException {
18+
MyComponentFactory factory = new MyComponentFactory();
19+
TestComponent impl =
20+
factory.getComponentImpl("1.0", SdkComponentType.SCRIPT_GENERATOR, TestComponent.class);
21+
22+
// impl could be either ScriptGeneratorA, ScriptGeneratorB, or ScriptGeneratorSubclass
23+
// depending on which was the last found in SdkComponentFactory.populateComponents()
24+
assertEquals(ScriptGeneratorSubclass.class, impl.getClass());
25+
assertEquals("Subclass", impl.testMethod());
26+
}
1527
}

0 commit comments

Comments
 (0)