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