### Question:
ChordSelector implements IChordSelector { @Override public HiveChord selectFourthChord(HarmonicLoop selectedLoop, HiveChord thirdChord, HiveChord nextChord, List<HiveChord> hiveChordInDatabase) { List<HiveChord> candidates = getChordCandidatesBetweenChords(thirdChord, nextChord, hiveChordInDatabase); if (candidates == null || candidates.size() == 0) { return null; } List<HiveChord> compatibleChords = selectedLoop.getValidChords(); List<HiveChord> perfectMatches = new ArrayList<>(); for (HiveChord chord : compatibleChords) { for (HiveChord dbChord : candidates) { if (chord.isEqual(dbChord)) { perfectMatches.add(dbChord); } } } if (perfectMatches.size() > 0) { int index = new Random().nextInt(perfectMatches.size()); return perfectMatches.get(index); } else { int index = new Random().nextInt(compatibleChords.size()); return compatibleChords.get(index); } }  HashMap<ProgressionType, HiveChord> selectFirstChordForType(List<ProgressionType> progressionTypes, List<HiveChord> hiveChordInDatabase); @Override HashMap<ProgressionType, List<HiveChord>> selectChordsFrom4BarLoop(List<ProgressionUnit> progressionUnits); HiveChord tempRandomChordSelect(List<HiveChord> getHiveChordInDatabase); HiveChord getChordTwoBarsPrior(HiveChord currentChord, List<HiveChord> hiveChordInDatabase); List<HiveChord> getChordCandidatesTwoBarsPrior(HiveChord currentChord, List<HiveChord> hiveChordInDatabase); HiveChord selectChordBetweenChords(HiveChord chordOne, HiveChord chordTwo, List<HiveChord> hiveChordInDatabase); @Override HiveChord selectChordBetweenChordsAndLoop(HiveChord chordOne, HiveChord chordTwo, HarmonicLoop harmonicLoop, List<HiveChord> hiveChordInDatabase); List<HiveChord> getChordCandidatesBetweenChords(HiveChord chordOne, HiveChord chordTwo, List<HiveChord> hiveChordInDatabase); @Override HiveChord selectMiddleChord(HarmonicLoop selectedLoop, HiveChord chordOneOfFour, HiveChord chordOneOfNextBar, List<HiveChord> hiveChordInDatabase); @Override HiveChord selectFourthChord(HarmonicLoop selectedLoop, HiveChord thirdChord, HiveChord nextChord, List<HiveChord> hiveChordInDatabase);  }### Answer:
@Test public void selectsCorrectFourthChord() throws Exception { List<HiveChord> hiveChordInDatabase = Arrays.asList(new HiveChord("cMAJ7"), new HiveChord("bbMin7"), new HiveChord("dDom7"), new HiveChord("ebMaj7"), new HiveChord("a#Min7"), new HiveChord("bbMin7"), new HiveChord("dDom7"), new HiveChord("ebMaj7"), new HiveChord("bbMin7")); HiveChord chordOne = new HiveChord("d#Dom7"); HiveChord chordTwo = new HiveChord("bbMin7"); List<HiveChord> chordList = new ArrayList<>(); chordList.add(chordOne); chordList.add(chordTwo); HarmonicLoop selectedLoop = new HarmonicLoop(); selectedLoop.setChords(chordList); HiveChord selectedChord = chordSelector.selectFourthChord(selectedLoop, new HiveChord("a#Min7"), new HiveChord("dDom7"), hiveChordInDatabase); Assert.assertTrue(selectedChord.isEqual("bbMin7")); }