VariantDataServiceImpl implements VariantDataService { @Override public FrequencyData getVariantFrequencyData(Variant variant, Set<FrequencySource> frequencySources) { FrequencyData defaultFrequencyData = defaultFrequencyDao.getFrequencyData(variant); List<Frequency> allFrequencies = new ArrayList<>(); for (Frequency frequency : defaultFrequencyData.getKnownFrequencies()) { if (frequencySources.contains(frequency.getSource())) { allFrequencies.add(frequency); } } if (frequencySources.contains(FrequencySource.LOCAL)) { FrequencyData localFrequencyData = localFrequencyDao.getFrequencyData(variant); allFrequencies.addAll(localFrequencyData.getKnownFrequencies()); } return FrequencyData.of(defaultFrequencyData.getRsId(), allFrequencies); } private  VariantDataServiceImpl(Builder builder); @Override boolean variantIsWhiteListed(Variant variant); @Override FrequencyData getVariantFrequencyData(Variant variant, Set<FrequencySource> frequencySources); @Override PathogenicityData getVariantPathogenicityData(Variant variant, Set<PathogenicitySource> pathogenicitySources); static Builder builder();  }
@Test public void serviceReturnsEmptyFrequencyDataWithRsIdForVariantWhenNoSourcesAreDefined() { FrequencyData result = instance.getVariantFrequencyData(variant, Collections.emptySet()); assertThat(result, equalTo(FrequencyData.of(RsId.of(1234567)))); }
@Test public void serviceReturnsFrequencyDataForVariant() { FrequencyData result = instance.getVariantFrequencyData(variant, EnumSet.allOf(FrequencySource.class)); assertThat(result, equalTo(FREQ_DATA)); }
@Test public void serviceReturnsSpecifiedFrequencyDataForVariant() { FrequencyData frequencyData = FrequencyData.of(RsId.of(234567), Frequency.of(FrequencySource.ESP_AFRICAN_AMERICAN, 1f), Frequency .of(FrequencySource.ESP_EUROPEAN_AMERICAN, 1f)); Mockito.when(defaultFrequencyDao.getFrequencyData(variant)).thenReturn(frequencyData); FrequencyData result = instance.getVariantFrequencyData(variant, EnumSet.of(FrequencySource.ESP_AFRICAN_AMERICAN)); assertThat(result, equalTo(FrequencyData.of(RsId.of(234567), Frequency.of(FrequencySource.ESP_AFRICAN_AMERICAN, 1f)))); }
@Test public void serviceReturnsLocalFrequencyDataForVariant() { FrequencyData localFrequencyData = FrequencyData.of(RsId.empty(), Frequency.of(FrequencySource.LOCAL, 2f)); Mockito.when(defaultFrequencyDao.getFrequencyData(variant)).thenReturn(FrequencyData.empty()); Mockito.when(localFrequencyDao.getFrequencyData(variant)).thenReturn(localFrequencyData); FrequencyData result = instance.getVariantFrequencyData(variant, EnumSet.of(FrequencySource.LOCAL)); assertThat(result, equalTo(localFrequencyData)); }
@Test public void serviceReturnsLocalFrequencyDataForVariantWithRsIdIfKnown() { FrequencyData localFrequencyData = FrequencyData.of(RsId.empty(), Frequency.of(FrequencySource.LOCAL, 2f)); Mockito.when(localFrequencyDao.getFrequencyData(variant)).thenReturn(localFrequencyData); FrequencyData result = instance.getVariantFrequencyData(variant, EnumSet.of(FrequencySource.LOCAL)); assertThat(result, equalTo(FrequencyData.of(RsId.of(1234567), Frequency.of(FrequencySource.LOCAL, 2f)))); }
@Test public void serviceReturnsSpecifiedFrequencyDataForVariantIncludingLocalData() { FrequencyData frequencyData = FrequencyData.of(RsId.of(234567), Frequency.of(FrequencySource.ESP_AFRICAN_AMERICAN, 1f), Frequency .of(FrequencySource.ESP_EUROPEAN_AMERICAN, 1f)); Mockito.when(defaultFrequencyDao.getFrequencyData(variant)).thenReturn(frequencyData); FrequencyData localFrequencyData = FrequencyData.of(RsId.empty(), Frequency.of(FrequencySource.LOCAL, 2f)); Mockito.when(localFrequencyDao.getFrequencyData(variant)).thenReturn(localFrequencyData); FrequencyData result = instance.getVariantFrequencyData(variant, EnumSet.of(FrequencySource.ESP_AFRICAN_AMERICAN, FrequencySource.LOCAL)); assertThat(result, equalTo(FrequencyData.of(RsId.of(234567), Frequency.of(FrequencySource.ESP_AFRICAN_AMERICAN, 1f), Frequency .of(FrequencySource.LOCAL, 2f)))); }
@Test public void serviceReturnsEmptyFrequencyDataWhenSpecifiedFrequencyDataIsUnavailable() { Mockito.when(defaultFrequencyDao.getFrequencyData(variant)).thenReturn(FrequencyData.empty()); FrequencyData result = instance.getVariantFrequencyData(variant, EnumSet.of(FrequencySource.LOCAL)); assertThat(result, equalTo(FrequencyData.empty())); }