### Question:
HarmonicAltThemeWeighter { public WeightClass calculateThemeWeight(HarmonicLoop optionToWeight, ProgressionUnitBar oneBarPrior, ProgressionUnitBar secondBarPrior){ WeightClass weightClass = WeightClass.BAD; if(secondBarPrior != null && secondBarPrior.getHarmonicLoopAlt() != null && optionToWeight.getId().equals(secondBarPrior.getHarmonicLoopAlt().getId())){ weightClass = WeightClass.OK; } if(oneBarPrior != null && oneBarPrior.getHarmonicLoopAlt() != null && optionToWeight.getId().equals(oneBarPrior.getHarmonicLoopAlt().getId())){ weightClass = WeightClass.GOOD; } return weightClass; }  WeightClass calculateThemeWeight(HarmonicLoop optionToWeight, ProgressionUnitBar oneBarPrior, ProgressionUnitBar secondBarPrior);  }### Answer:
@Test public void shouldWeightGood_forOneBarPriorMatch(){ HarmonicLoop barTooWeight = new HarmonicLoop(); barTooWeight.setId(1); oneBarLoop = new HarmonicLoop(); oneBarLoop.setId(1); onePriorProgBar.setHarmonicLoopAlt(oneBarLoop); twoBarsLoop = new HarmonicLoop(); twoBarsLoop.setId(2); twoPrioProgBar.setHarmonicLoopAlt(twoBarsLoop); WeightClass result = harmonicAltThemeWeighter.calculateThemeWeight(barTooWeight, onePriorProgBar, twoPrioProgBar); assertThat(result).isEqualTo(WeightClass.GOOD); }
@Test public void shouldWeightOk_forTwoBarsPriorMatch(){ HarmonicLoop barTooWeight = new HarmonicLoop(); barTooWeight.setId(2); oneBarLoop = new HarmonicLoop(); oneBarLoop.setId(1); onePriorProgBar.setHarmonicLoopAlt(oneBarLoop); twoBarsLoop = new HarmonicLoop(); twoBarsLoop.setId(2); twoPrioProgBar.setHarmonicLoopAlt(twoBarsLoop); WeightClass result = harmonicAltThemeWeighter.calculateThemeWeight(barTooWeight, onePriorProgBar, twoPrioProgBar); assertThat(result).isEqualTo(WeightClass.OK); }
@Test public void shouldWeightBad_forNonMatch(){ HarmonicLoop barTooWeight = new HarmonicLoop(); barTooWeight.setId(0); oneBarLoop = new HarmonicLoop(); oneBarLoop.setId(1); onePriorProgBar.setHarmonicLoopAlt(oneBarLoop); twoBarsLoop = new HarmonicLoop(); twoBarsLoop.setId(2); twoPrioProgBar.setHarmonicLoopAlt(twoBarsLoop); WeightClass result = harmonicAltThemeWeighter.calculateThemeWeight(barTooWeight, onePriorProgBar, twoPrioProgBar); assertThat(result).isEqualTo(WeightClass.BAD); }
@Test public void shouldHandleNulls(){ HarmonicLoop barTooWeight = new HarmonicLoop(); barTooWeight.setId(0); oneBarLoop = null; onePriorProgBar.setHarmonicLoopAlt(oneBarLoop); twoPrioProgBar = null; WeightClass result = harmonicAltThemeWeighter.calculateThemeWeight(barTooWeight, onePriorProgBar, twoPrioProgBar); assertThat(result).isEqualTo(WeightClass.BAD); }