-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from vierbergenlars/update-provider
Add ability to register additional CiInformationProviders outside of the ServiceLoader mechanism
- Loading branch information
Showing
7 changed files
with
157 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/test/java/be/vbgn/gradle/cidetect/provider/CiInformationProviderRegisterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package be.vbgn.gradle.cidetect.provider; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertSame; | ||
|
||
import be.vbgn.gradle.cidetect.CiInformation; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import javax.annotation.Nullable; | ||
import org.gradle.api.Project; | ||
import org.junit.Test; | ||
|
||
public class CiInformationProviderRegisterTest { | ||
|
||
static class TestProvider implements CiInformationProvider { | ||
|
||
@Override | ||
public int getPriority() { | ||
return 10; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public CiInformation newCiInformation(@Nullable Project project) { | ||
return null; | ||
} | ||
} | ||
|
||
@Test | ||
public void testRegisterProvider() { | ||
CiInformationProvider.registerProvider(TestProvider.class); | ||
CiInformationProvider.registerProvider(TestProvider.class); | ||
|
||
List<CiInformationProvider> providers = CiInformationProvider.installedProviders(); | ||
List<Class<? extends CiInformationProvider>> providerClasses = providers.stream() | ||
.map(CiInformationProvider::getClass).collect(Collectors.toList()); | ||
|
||
assertSame(TestProvider.class, providerClasses.get(0)); | ||
|
||
assertEquals("There are no providers registered multiple times", new HashSet<>(providerClasses).size(), | ||
providerClasses.size()); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters