MaintenancePlugin extends PluginBase { public List<File> getLogfiles(String directory, int amount) { LOG.debug("getting {} logs from directory {}", amount, directory); File logDir = new File(directory); File[] files = logDir.listFiles((file, name) -> name.startsWith("AndroidAPS") && (name.endsWith(".log") || (name.endsWith(".zip") && !name.endsWith(LoggerUtils.SUFFIX)))); Arrays.sort(files, (f1, f2) -> f2.getName().compareTo(f1.getName())); List<File> result = Arrays.asList(files); int toIndex = amount++; if (toIndex > result.size()) { toIndex = result.size(); } LOG.debug("returning sublist 0 to {}", toIndex); return result.subList(0, toIndex); } MaintenancePlugin();   MaintenancePlugin(Context ctx); static MaintenancePlugin getPlugin(); static MaintenancePlugin initPlugin(Context ctx); void sendLogs(); void deleteLogs(); List<File> getLogfiles(String directory, int amount); File zipLogs(File zipFile, List<File> files); String constructName(); void zip(File zipFile, List<File> files); static Intent sendMail(Uri attachementUri, String recipient, String subject); static Intent sendMail(Uri attachementUri, String recipient, String subject, String body);  }
@Test public void getLogfilesTest() { String logDirectory = "src/test/res/logger"; List<File> logs = sut.getLogfiles(logDirectory, 2); assertEquals(2, logs.size()); assertEquals("AndroidAPS.log", logs.get(0).getName()); assertEquals("AndroidAPS.2018-01-03_01-01-00.1.zip", logs.get(1).getName()); logs = sut.getLogfiles(logDirectory, 10); assertEquals(4, logs.size()); }