### Question:
ReconUtils { public File getLastKnownDB(File reconDbDir, String fileNamePrefix) { String lastKnownSnapshotFileName = null; long lastKnonwnSnapshotTs = Long.MIN_VALUE; if (reconDbDir != null) { File[] snapshotFiles = reconDbDir.listFiles((dir, name) -> name.startsWith(fileNamePrefix)); if (snapshotFiles != null) { for (File snapshotFile : snapshotFiles) { String fileName = snapshotFile.getName(); try { String[] fileNameSplits = fileName.split("_"); if (fileNameSplits.length <= 1) { continue; } long snapshotTimestamp = Long.parseLong(fileNameSplits[1]); if (lastKnonwnSnapshotTs < snapshotTimestamp) { lastKnonwnSnapshotTs = snapshotTimestamp; lastKnownSnapshotFileName = fileName; } } catch (NumberFormatException nfEx) { LOG.warn("Unknown file found in Recon DB dir : {}", fileName); } } } } return lastKnownSnapshotFileName == null ? null : new File(reconDbDir.getPath(), lastKnownSnapshotFileName); } ReconUtils(); static File getReconScmDbDir(ConfigurationSource conf); File getReconDbDir(ConfigurationSource conf, String dirConfigKey); static File createTarFile(Path sourcePath); void untarCheckpointFile(File tarFile, Path destPath); HttpURLConnection makeHttpCall(URLConnectionFactory connectionFactory,
                                  String url, boolean isSpnego); File getLastKnownDB(File reconDbDir, String fileNamePrefix); static void upsertGlobalStatsTable(Configuration sqlConfiguration,
                                            GlobalStatsDao globalStatsDao,
                                            String key,
                                            Long count);  }### Answer:
@Test public void testGetLastKnownDB() throws IOException { File newDir = folder.newFolder(); File file1 = Paths.get(newDir.getAbsolutePath(), "valid_1") .toFile(); String str = "File1 Contents"; BufferedWriter writer = new BufferedWriter(new FileWriter( file1.getAbsolutePath())); writer.write(str); writer.close(); File file2 = Paths.get(newDir.getAbsolutePath(), "valid_2") .toFile(); str = "File2 Contents"; writer = new BufferedWriter(new FileWriter(file2.getAbsolutePath())); writer.write(str); writer.close(); File file3 = Paths.get(newDir.getAbsolutePath(), "invalid_3") .toFile(); str = "File3 Contents"; writer = new BufferedWriter(new FileWriter(file3.getAbsolutePath())); writer.write(str); writer.close(); ReconUtils reconUtils = new ReconUtils(); File latestValidFile = reconUtils.getLastKnownDB(newDir, "valid"); assertTrue(latestValidFile.getName().equals("valid_2")); }