### Question:
LimboServiceHelper { LimboPlayer merge(LimboPlayer newLimbo, LimboPlayer oldLimbo) { if (newLimbo == null) { return oldLimbo; } else if (oldLimbo == null) { return newLimbo; } boolean isOperator = newLimbo.isOperator() || oldLimbo.isOperator(); boolean canFly = newLimbo.isCanFly() || oldLimbo.isCanFly(); float flySpeed = Math.max(newLimbo.getFlySpeed(), oldLimbo.getFlySpeed()); float walkSpeed = Math.max(newLimbo.getWalkSpeed(), oldLimbo.getWalkSpeed()); Collection<String> groups = getLimboGroups(oldLimbo.getGroups(), newLimbo.getGroups()); Location location = firstNotNull(oldLimbo.getLocation(), newLimbo.getLocation()); return new LimboPlayer(location, isOperator, groups, canFly, walkSpeed, flySpeed); }    }### Answer:
@Test public void shouldMergeLimboPlayers() { Location newLocation = mock(Location.class); LimboPlayer newLimbo = new LimboPlayer(newLocation, false, Collections.singletonList("grp-new"), false, 0.0f, 0.0f); Location oldLocation = mock(Location.class); LimboPlayer oldLimbo = new LimboPlayer(oldLocation, true, Collections.singletonList("grp-old"), true, 0.1f, 0.8f); LimboPlayer result = limboServiceHelper.merge(newLimbo, oldLimbo); assertThat(result.getLocation(), equalTo(oldLocation)); assertThat(result.isOperator(), equalTo(true)); assertThat(result.getGroups(), contains("grp-old")); assertThat(result.isCanFly(), equalTo(true)); assertThat(result.getWalkSpeed(), equalTo(0.1f)); assertThat(result.getFlySpeed(), equalTo(0.8f)); }
@Test public void shouldFallBackToNewLimboForMissingData() { Location newLocation = mock(Location.class); LimboPlayer newLimbo = new LimboPlayer(newLocation, false, Collections.singletonList("grp-new"), true, 0.3f, 0.0f); LimboPlayer oldLimbo = new LimboPlayer(null, false, Collections.emptyList(), false, 0.1f, 0.1f); LimboPlayer result = limboServiceHelper.merge(newLimbo, oldLimbo); assertThat(result.getLocation(), equalTo(newLocation)); assertThat(result.isOperator(), equalTo(false)); assertThat(result.getGroups(), contains("grp-new")); assertThat(result.isCanFly(), equalTo(true)); assertThat(result.getWalkSpeed(), equalTo(0.3f)); assertThat(result.getFlySpeed(), equalTo(0.1f)); }
@Test public void shouldHandleNullInputs() { LimboPlayer limbo = mock(LimboPlayer.class); LimboPlayer result1 = limboServiceHelper.merge(limbo, null); LimboPlayer result2 = limboServiceHelper.merge(null, limbo); LimboPlayer result3 = limboServiceHelper.merge(null, null); verifyZeroInteractions(limbo); assertThat(result1, equalTo(limbo)); assertThat(result2, equalTo(limbo)); assertThat(result3, nullValue()); }