Skip to content

Rename OutOfBandLibraryVersionRegistrar to GlobalLibraryVersionRegistrar #236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
*/
public class DefaultUserAgentPublisher implements UserAgentPublisher {
private final String javaSDKVersionUserAgent;
private final OutOfBandLibraryVersionRegistrar gamesSDKRegistrar;
private final GlobalLibraryVersionRegistrar gamesSDKRegistrar;

DefaultUserAgentPublisher(
Set<LibraryVersion> libraryVersions, OutOfBandLibraryVersionRegistrar gamesSDKRegistrar) {
Set<LibraryVersion> libraryVersions, GlobalLibraryVersionRegistrar gamesSDKRegistrar) {
this.javaSDKVersionUserAgent = toUserAgent(libraryVersions);
this.gamesSDKRegistrar = gamesSDKRegistrar;
}
Expand Down Expand Up @@ -70,7 +70,7 @@ public static Component<UserAgentPublisher> component() {
.factory(
c ->
new DefaultUserAgentPublisher(
c.setOf(LibraryVersion.class), OutOfBandLibraryVersionRegistrar.getInstance()))
c.setOf(LibraryVersion.class), GlobalLibraryVersionRegistrar.getInstance()))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
/**
* In order to allow the C++ and Unity SDKs to publish their versions without the use of the
* components framework, we have a mechanism where the versions can be wired as out of band as side
* effects. See {@link OutOfBandLibraryVersionRegistrar#registerVersion(String, String)}
* effects. See {@link GlobalLibraryVersionRegistrar#registerVersion(String, String)}
*
* <p>Java libraries should use {@link LibraryVersionComponent#create(String, String)} instead.
*/
public class OutOfBandLibraryVersionRegistrar {
public class GlobalLibraryVersionRegistrar {
private final Set<LibraryVersion> infos = new HashSet<>();
private static volatile OutOfBandLibraryVersionRegistrar INSTANCE;
private static volatile GlobalLibraryVersionRegistrar INSTANCE;

OutOfBandLibraryVersionRegistrar() {}
GlobalLibraryVersionRegistrar() {}

/**
* Thread safe method to publish versions outside of the components mechanics.
Expand All @@ -49,14 +49,14 @@ Set<LibraryVersion> getRegisteredVersions() {
}
}

/** Returns an instance of {@link OutOfBandLibraryVersionRegistrar} */
public static OutOfBandLibraryVersionRegistrar getInstance() {
OutOfBandLibraryVersionRegistrar localRef = INSTANCE;
/** Returns an instance of {@link GlobalLibraryVersionRegistrar} */
public static GlobalLibraryVersionRegistrar getInstance() {
GlobalLibraryVersionRegistrar localRef = INSTANCE;
if (localRef == null) {
synchronized (OutOfBandLibraryVersionRegistrar.class) {
synchronized (GlobalLibraryVersionRegistrar.class) {
localRef = INSTANCE;
if (localRef == null) {
INSTANCE = localRef = new OutOfBandLibraryVersionRegistrar();
INSTANCE = localRef = new GlobalLibraryVersionRegistrar();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@
public class DefaultUserAgentPublisherTest {
private Set<LibraryVersion> libraryVersions;
private DefaultUserAgentPublisher userAgentPublisher;
private OutOfBandLibraryVersionRegistrar outOfBandLibraryVersionRegistrar;
private GlobalLibraryVersionRegistrar globalLibraryVersionRegistrar;

@Before
public void before() {
libraryVersions = new HashSet<>();
libraryVersions.add(LibraryVersion.create("foo", "1"));
libraryVersions.add(LibraryVersion.create("bar", "2"));

outOfBandLibraryVersionRegistrar = mock(OutOfBandLibraryVersionRegistrar.class);
globalLibraryVersionRegistrar = mock(GlobalLibraryVersionRegistrar.class);

when(outOfBandLibraryVersionRegistrar.getRegisteredVersions()).thenReturn(new HashSet<>());
when(globalLibraryVersionRegistrar.getRegisteredVersions()).thenReturn(new HashSet<>());

userAgentPublisher =
new DefaultUserAgentPublisher(libraryVersions, outOfBandLibraryVersionRegistrar);
new DefaultUserAgentPublisher(libraryVersions, globalLibraryVersionRegistrar);
}

@Test
Expand All @@ -59,7 +59,7 @@ public void getUserAgent_createsConcatenatedStringOfSdkVersions() {
@Test
public void getUserAgent_returnsEmptyString_whenVersionSetIsEmpty() {
userAgentPublisher =
new DefaultUserAgentPublisher(new HashSet<>(), outOfBandLibraryVersionRegistrar);
new DefaultUserAgentPublisher(new HashSet<>(), globalLibraryVersionRegistrar);

assertThat(userAgentPublisher.getUserAgent()).isEqualTo("");
}
Expand All @@ -71,9 +71,9 @@ public void getUserAgent_returnsEmptyString_whenVersionSetIsEmpty() {
HashSet<LibraryVersion> gamesLibraryVersions = new HashSet<>();
gamesLibraryVersions.add(LibraryVersion.create("fizz", "1"));
gamesLibraryVersions.add(LibraryVersion.create("buzz", "2"));
when(outOfBandLibraryVersionRegistrar.getRegisteredVersions()).thenReturn(gamesLibraryVersions);
when(globalLibraryVersionRegistrar.getRegisteredVersions()).thenReturn(gamesLibraryVersions);
userAgentPublisher =
new DefaultUserAgentPublisher(libraryVersions, outOfBandLibraryVersionRegistrar);
new DefaultUserAgentPublisher(libraryVersions, globalLibraryVersionRegistrar);

String[] actualUserAgent = userAgentPublisher.getUserAgent().split(" ");
Arrays.sort(actualUserAgent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class OutOfBandLibraryVersionRegistrarTest {
public class GlobalLibraryVersionRegistrarTest {
@Test
public void registerVersion_persistsVersion() {
OutOfBandLibraryVersionRegistrar outOfBandLibraryVersionRegistrar =
new OutOfBandLibraryVersionRegistrar();
outOfBandLibraryVersionRegistrar.registerVersion("foo", "1.1.1");
GlobalLibraryVersionRegistrar globalLibraryVersionRegistrar =
new GlobalLibraryVersionRegistrar();
globalLibraryVersionRegistrar.registerVersion("foo", "1.1.1");

assertThat(outOfBandLibraryVersionRegistrar.getRegisteredVersions())
assertThat(globalLibraryVersionRegistrar.getRegisteredVersions())
.contains(LibraryVersion.create("foo", "1.1.1"));
}

@Test
public void getRegisteredVersions_returnsEmptySet_whenNoVersionsAreRegistered() {
OutOfBandLibraryVersionRegistrar outOfBandLibraryVersionRegistrar =
new OutOfBandLibraryVersionRegistrar();
GlobalLibraryVersionRegistrar globalLibraryVersionRegistrar =
new GlobalLibraryVersionRegistrar();

assertThat(outOfBandLibraryVersionRegistrar.getRegisteredVersions()).isEmpty();
assertThat(globalLibraryVersionRegistrar.getRegisteredVersions()).isEmpty();
}
}