use of jakarta.mail.search.NotTerm in project spring-integration by spring-projects.
the class ImapMailSearchTermsTests method validateSearchTermsWhenShouldMarkAsReadWithExistingFlags.
@Test
public void validateSearchTermsWhenShouldMarkAsReadWithExistingFlags() throws Exception {
ImapMailReceiver receiver = new ImapMailReceiver();
receiver.setShouldMarkMessagesAsRead(true);
receiver.setBeanFactory(mock(BeanFactory.class));
receiver.afterPropertiesSet();
Field folderField = AbstractMailReceiver.class.getDeclaredField("folder");
folderField.setAccessible(true);
Folder folder = mock(Folder.class);
when(folder.getPermanentFlags()).thenReturn(new Flags(Flags.Flag.USER));
folderField.set(receiver, folder);
Method compileSearchTerms = ReflectionUtils.findMethod(receiver.getClass(), "compileSearchTerms", Flags.class);
compileSearchTerms.setAccessible(true);
Flags flags = new Flags();
flags.add(Flag.ANSWERED);
SearchTerm searchTerms = (SearchTerm) compileSearchTerms.invoke(receiver, flags);
assertThat(searchTerms instanceof AndTerm).isTrue();
AndTerm andTerm = (AndTerm) searchTerms;
SearchTerm[] terms = andTerm.getTerms();
assertThat(terms.length).isEqualTo(2);
NotTerm notTerm = (NotTerm) terms[0];
assertThat(((FlagTerm) notTerm.getTerm()).getFlags().contains(Flag.ANSWERED)).isTrue();
notTerm = (NotTerm) terms[1];
Flags siFlags = new Flags();
siFlags.add(AbstractMailReceiver.DEFAULT_SI_USER_FLAG);
assertThat(((FlagTerm) notTerm.getTerm()).getFlags().contains(siFlags)).isTrue();
}
use of jakarta.mail.search.NotTerm in project spring-integration by spring-projects.
the class ImapMailSearchTermsTests method validateSearchTermsWhenShouldMarkAsReadNoExistingFlagsGuts.
public void validateSearchTermsWhenShouldMarkAsReadNoExistingFlagsGuts(String userFlag, ImapMailReceiver receiver) throws NoSuchFieldException, IllegalAccessException, InvocationTargetException {
receiver.setShouldMarkMessagesAsRead(true);
receiver.setBeanFactory(mock(BeanFactory.class));
Field folderField = AbstractMailReceiver.class.getDeclaredField("folder");
folderField.setAccessible(true);
Folder folder = mock(Folder.class);
when(folder.getPermanentFlags()).thenReturn(new Flags(Flags.Flag.USER));
folderField.set(receiver, folder);
Method compileSearchTerms = ReflectionUtils.findMethod(receiver.getClass(), "compileSearchTerms", Flags.class);
compileSearchTerms.setAccessible(true);
Flags flags = new Flags();
SearchTerm searchTerms = (SearchTerm) compileSearchTerms.invoke(receiver, flags);
assertThat(searchTerms instanceof NotTerm).isTrue();
NotTerm notTerm = (NotTerm) searchTerms;
Flags siFlags = new Flags();
siFlags.add(userFlag);
assertThat(((FlagTerm) notTerm.getTerm()).getFlags()).isEqualTo(siFlags);
}
use of jakarta.mail.search.NotTerm in project spring-integration by spring-projects.
the class ImapMailSearchTermsTests method validateSearchTermsWhenShouldNotMarkAsReadNoExistingFlags.
@Test
public void validateSearchTermsWhenShouldNotMarkAsReadNoExistingFlags() throws Exception {
ImapMailReceiver receiver = new ImapMailReceiver();
receiver.setShouldMarkMessagesAsRead(false);
receiver.setBeanFactory(mock(BeanFactory.class));
receiver.afterPropertiesSet();
Field folderField = AbstractMailReceiver.class.getDeclaredField("folder");
folderField.setAccessible(true);
Folder folder = mock(Folder.class);
when(folder.getPermanentFlags()).thenReturn(new Flags(Flags.Flag.USER));
folderField.set(receiver, folder);
Method compileSearchTerms = ReflectionUtils.findMethod(receiver.getClass(), "compileSearchTerms", Flags.class);
compileSearchTerms.setAccessible(true);
Flags flags = new Flags();
SearchTerm searchTerms = (SearchTerm) compileSearchTerms.invoke(receiver, flags);
assertThat(searchTerms instanceof NotTerm).isTrue();
}
Aggregations