@Test
  public void test_CLOSED_INTERVAL() {
    when(filterPreferencesCache.getNexusFilterDescriptor())
        .thenReturn(
            new MockDescriptor("/kichwa1", Operation.CLOSED_INTERVAL, new String[] {"0", "1"}));
    assertFalse(select(ifile_kichwa1_2));

    when(filterPreferencesCache.getNexusFilterDescriptor())
        .thenReturn(
            new MockDescriptor("/kichwa1", Operation.CLOSED_INTERVAL, new String[] {"1", "2"}));
    assertTrue(select(ifile_kichwa1_2));

    when(filterPreferencesCache.getNexusFilterDescriptor())
        .thenReturn(
            new MockDescriptor("/kichwa1", Operation.CLOSED_INTERVAL, new String[] {"1", "3"}));
    assertTrue(select(ifile_kichwa1_2));

    when(filterPreferencesCache.getNexusFilterDescriptor())
        .thenReturn(
            new MockDescriptor("/kichwa1", Operation.CLOSED_INTERVAL, new String[] {"2", "3"}));
    assertTrue(select(ifile_kichwa1_2));

    when(filterPreferencesCache.getNexusFilterDescriptor())
        .thenReturn(
            new MockDescriptor("/kichwa1", Operation.CLOSED_INTERVAL, new String[] {"3", "4"}));
    assertFalse(select(ifile_kichwa1_2));
  }
  @Test
  public void test_NOT_EQUALS() {
    when(filterPreferencesCache.getNexusFilterDescriptor())
        .thenReturn(new MockDescriptor("/kichwa1", Operation.NOT_EQUALS, new String[] {"1"}));
    assertTrue(select(ifile_kichwa1_2));
    assertFalse(select(ifile_kichwa1_1));

    when(filterPreferencesCache.getNexusFilterDescriptor())
        .thenReturn(new MockDescriptor("/kichwa1", Operation.NOT_EQUALS, new String[] {"2"}));
    assertFalse(select(ifile_kichwa1_2));
    assertTrue(select(ifile_kichwa1_1));
  }
  @Before
  public void before() {
    filterPreferencesCache = mock(INexusFilterPreferencesCache.class);
    model = mock(IHierarchicalDataModel.class);
    nexusFilter = new NexusFilter(filterPreferencesCache, model);

    // Create a "fake" file system, refer to the files by their IFiles
    ifile_kichwa1_1 = makeIFile("kichwa1_1.nxs");
    ifile_kichwa1_2 = makeIFile("kichwa1_2.nxs");
    ifile_kichwa2_1 = makeIFile("kichwa2_1.nxs");
    ifile_non_nexus = makeIFile("not_nexus.txt");
    IHierarchicalDataFileModel makeFileModel_1_1 = makeFileModel("/kichwa1", 1);
    IHierarchicalDataFileModel makeFileModel_1_2 = makeFileModel("/kichwa1", 2);
    IHierarchicalDataFileModel makeFileModel_2_1 = makeFileModel("/kichwa2", 1);
    when(model.getFileModel(ifile_kichwa1_1)).thenReturn(makeFileModel_1_1);
    when(model.getFileModel(ifile_kichwa1_2)).thenReturn(makeFileModel_1_2);
    when(model.getFileModel(ifile_kichwa2_1)).thenReturn(makeFileModel_2_1);

    IHierarchicalDataFileModel ifile_non_nexus_contents;
    ifile_non_nexus_contents = mock(IHierarchicalDataFileModel.class);
    when(model.getFileModel(ifile_non_nexus)).thenReturn(ifile_non_nexus_contents);

    // default filter preferences is null
    when(filterPreferencesCache.getNexusFilterDescriptor()).thenReturn(null);
  }
  @Test
  public void testBehaviourWhenCompareFails() {
    // The behaviour in this case is hard to know what to do. If we are supposed to only
    // select things that match the filter, but we can't even run the comparison should
    // we show or hide the file. This is the case where we catch NumberFormatException
    boolean s = NexusFilter.SELECT_WHEN_COMPARE_FAILS_DUE_TO_NUMBERFORMATEXCEPTION;

    when(filterPreferencesCache.getNexusFilterDescriptor())
        .thenReturn(new MockDescriptor("/kichwa1", Operation.EQUALS, new String[] {"1"}));
    assertEquals(s, select(ifile_kichwa2_1));

    when(filterPreferencesCache.getNexusFilterDescriptor())
        .thenReturn(
            new MockDescriptor("/kichwa1", Operation.EQUALS, new String[] {"not_a_number"}));
    assertEquals(s, select(ifile_kichwa1_1));
  }
 @Test
 public void testBasic() {
   when(filterPreferencesCache.getNexusFilterDescriptor()).thenReturn(null);
   assertTrue(select(1));
   assertTrue(select(""));
   assertTrue(select(ifile_non_nexus));
   assertTrue(select(ifile_kichwa1_1));
   assertTrue(select(ifile_kichwa1_2));
   assertTrue(select(ifile_kichwa2_1));
 }
  @Test
  public void test_DOES_NOT_CONTAIN() {
    when(filterPreferencesCache.getNexusFilterDescriptor())
        .thenReturn(new MockDescriptor("/kichwa1", Operation.DOES_NOT_CONTAIN, null));
    assertFalse(select(ifile_kichwa1_2));
    assertTrue(select(ifile_kichwa2_1));

    when(filterPreferencesCache.getNexusFilterDescriptor())
        .thenReturn(new MockDescriptor("/kichwa2", Operation.DOES_NOT_CONTAIN, null));
    assertTrue(select(ifile_kichwa1_2));
    assertFalse(select(ifile_kichwa2_1));

    when(filterPreferencesCache.getNexusFilterDescriptor())
        .thenReturn(new MockDescriptor("/kichwa3", Operation.DOES_NOT_CONTAIN, null));
    assertTrue(select(ifile_kichwa1_2));
    assertTrue(select(ifile_kichwa2_1));

    // we always let through non-Nexus files
    assertTrue(select(1));
    assertTrue(select(""));
    assertTrue(select(ifile_non_nexus));
  }
  @Test
  public void testInverseInterval() {
    // The GUI/creator of INexusFilterDescriptor is expected to create intervals which
    // are logical (i.e. op0 < op1).
    // If the INexusFilterDescriptor returns such a case, then nothing matches...
    when(filterPreferencesCache.getNexusFilterDescriptor())
        .thenReturn(
            new MockDescriptor("/kichwa1", Operation.OPEN_INTERVAL, new String[] {"2", "0"}));
    assertFalse(select(ifile_kichwa1_1));
    assertFalse(select(ifile_kichwa1_2));

    // ... except files which the comparison fails on
    assertTrue(select(ifile_kichwa2_1));
  }
  @Test
  public void test_LEFT_OPEN_RIGHT_CLOSED_INTERVAL() {
    Operation leftOpenRightClosedInterval = Operation.LEFT_OPEN_RIGHT_CLOSED_INTERVAL;
    when(filterPreferencesCache.getNexusFilterDescriptor())
        .thenReturn(
            new MockDescriptor("/kichwa1", leftOpenRightClosedInterval, new String[] {"0", "1"}));
    assertFalse(select(ifile_kichwa1_2));

    when(filterPreferencesCache.getNexusFilterDescriptor())
        .thenReturn(
            new MockDescriptor("/kichwa1", leftOpenRightClosedInterval, new String[] {"0", "2"}));
    assertTrue(select(ifile_kichwa1_2));

    when(filterPreferencesCache.getNexusFilterDescriptor())
        .thenReturn(
            new MockDescriptor("/kichwa1", leftOpenRightClosedInterval, new String[] {"0", "3"}));
    assertTrue(select(ifile_kichwa1_2));

    when(filterPreferencesCache.getNexusFilterDescriptor())
        .thenReturn(
            new MockDescriptor("/kichwa1", leftOpenRightClosedInterval, new String[] {"1", "2"}));
    assertTrue(select(ifile_kichwa1_2));

    when(filterPreferencesCache.getNexusFilterDescriptor())
        .thenReturn(
            new MockDescriptor("/kichwa1", leftOpenRightClosedInterval, new String[] {"1", "3"}));
    assertTrue(select(ifile_kichwa1_2));

    when(filterPreferencesCache.getNexusFilterDescriptor())
        .thenReturn(
            new MockDescriptor("/kichwa1", leftOpenRightClosedInterval, new String[] {"2", "3"}));
    assertFalse(select(ifile_kichwa1_2));

    when(filterPreferencesCache.getNexusFilterDescriptor())
        .thenReturn(
            new MockDescriptor("/kichwa1", leftOpenRightClosedInterval, new String[] {"3", "4"}));
    assertFalse(select(ifile_kichwa1_2));
  }