@@ -35,7 +35,7 @@ public class EnhancedServiceLoaderTest {
3535 @ Test
3636 public void testLoadByClassAndClassLoader () {
3737 Hello load = EnhancedServiceLoader .load (Hello .class , Hello .class .getClassLoader ());
38- Assertions .assertEquals (load .say (), "Bonjour " );
38+ Assertions .assertEquals (load .say (), "Olá. " );
3939 }
4040
4141 /**
@@ -54,7 +54,7 @@ public void testLoadException() {
5454 @ Test
5555 public void testLoadByClass () {
5656 Hello load = EnhancedServiceLoader .load (Hello .class );
57- assertThat (load .say ()).isEqualTo ("Bonjour " );
57+ assertThat (load .say ()).isEqualTo ("Olá. " );
5858 }
5959
6060 /**
@@ -82,10 +82,10 @@ public void testLoadByClassAndClassLoaderAndActivateName() {
8282 @ Test
8383 public void getAllExtensionClass () {
8484 List <Class > allExtensionClass = EnhancedServiceLoader .getAllExtensionClass (Hello .class );
85+ assertThat (allExtensionClass .get (3 ).getSimpleName ()).isEqualTo ((LatinHello .class .getSimpleName ()));
8586 assertThat (allExtensionClass .get (2 ).getSimpleName ()).isEqualTo ((FrenchHello .class .getSimpleName ()));
8687 assertThat (allExtensionClass .get (1 ).getSimpleName ()).isEqualTo ((EnglishHello .class .getSimpleName ()));
8788 assertThat (allExtensionClass .get (0 ).getSimpleName ()).isEqualTo ((ChineseHello .class .getSimpleName ()));
88-
8989 }
9090
9191 /**
@@ -98,4 +98,32 @@ public void getAllExtensionClass1() {
9898 assertThat (allExtensionClass ).isNotEmpty ();
9999 }
100100
101+ @ Test
102+ public void getSingletonExtensionInstance (){
103+ Hello hello1 = EnhancedServiceLoader .load (Hello .class , "ChineseHello" );
104+ Hello hello2 = EnhancedServiceLoader .load (Hello .class , "ChineseHello" );
105+ assertThat (hello1 == hello2 ).isTrue ();
106+ }
107+
108+ @ Test
109+ public void getMultipleExtensionInstance (){
110+ Hello hello1 = EnhancedServiceLoader .load (Hello .class , "LatinHello" );
111+ Hello hello2 = EnhancedServiceLoader .load (Hello .class , "LatinHello" );
112+ assertThat (hello1 == hello2 ).isFalse ();
113+ }
114+
115+ @ Test
116+ public void getAllInstances (){
117+ List <Hello > hellows1 = EnhancedServiceLoader .loadAll (Hello .class );
118+ List <Hello > hellows2 = EnhancedServiceLoader .loadAll (Hello .class );
119+ for (Hello hello : hellows1 ){
120+ if (hello .say ()!="Olá." ){
121+ assertThat (hellows2 .contains (hello )).isTrue ();
122+ }
123+ else {
124+ assertThat (hellows2 .contains (hello )).isFalse ();
125+ }
126+ }
127+ }
128+
101129}
0 commit comments