### Question:
ObservableDRLFile implements ResourceChangeObservableFile { @Override public boolean accept(final Path path) { try { final String fileName = path.getFileName(); if (!fileName.endsWith("." + EXTENSION)) { return false; } final String drl = ioService.readAllString(convert(path)); return PATTERN.matcher(drl.toLowerCase()).matches(); } catch (NoSuchFileException e) { return false; } } ObservableDRLFile(); @Inject  ObservableDRLFile(final @Named("ioStrategy") IOService ioService); @Override boolean accept(final Path path);  }### Answer:
@Test public void testAcceptWithoutDRLFile() { doReturn("cheese.txt").when(path).getFileName(); assertFalse(observer.accept(path)); }
@Test public void testAcceptWithDRLFileDeclaringTypeSingleLine() { doReturn("cheese." + ObservableDRLFile.EXTENSION).when(path).getFileName(); doReturn("declare MyType end").when(ioService).readAllString(eq(nioPath)); assertTrue(observer.accept(path)); }
@Test public void testAcceptWithDRLFileDeclaringTypeMultipleLines() { doReturn("cheese." + ObservableDRLFile.EXTENSION).when(path).getFileName(); doReturn("declare MyType\nend").when(ioService).readAllString(eq(nioPath)); assertTrue(observer.accept(path)); }
@Test public void testAcceptWithDRLFileDeclaringTypeMidFile() { doReturn("cheese." + ObservableDRLFile.EXTENSION).when(path).getFileName(); doReturn("MyType declaration \ndeclare MyType\nend").when(ioService).readAllString(eq(nioPath)); assertTrue(observer.accept(path)); }
@Test public void testAcceptWithDRLFileNotDeclaringType() { doReturn("cheese." + ObservableDRLFile.EXTENSION).when(path).getFileName(); doReturn("rule test when then end").when(ioService).readAllString(eq(nioPath)); assertFalse(observer.accept(path)); }
@Test public void testAcceptWithNoSuchFileException() { doThrow(new NoSuchFileException()).when(path).getFileName(); assertFalse(observer.accept(path)); }