private JavaxMailFolder makeMockFolderWithMessages(int numMessages, JavaxMailFolder... folders) { JavaxMailFolder javaxMailFolder = mock(JavaxMailFolder.class); when(javaxMailFolder.getType()) .thenReturn(Folder.HOLDS_FOLDERS | Folder.HOLDS_MESSAGES); when(javaxMailFolder.getMessageCount()) .thenReturn(numMessages); when(javaxMailFolder.getMessage(Matchers.intThat(new LessOrEqual<>(numMessages)))) .thenReturn(mock(JavaxMailMessage.class)); when(javaxMailFolder.getMessage(Matchers.intThat(new GreaterThan<>(numMessages)))) .thenThrow(new RuntimeMessagingException( new MessagingException("crap"))); when(javaxMailFolder.list()).thenReturn(folders); return javaxMailFolder; }
@Test public void mocking_test() { LinkedList mockedList = mock(LinkedList.class); if (mockedList != null) { when(mockedList.get(0)).thenReturn("first"); } org.mockito.Mockito.verify(mockedList).get(0); verify(mockedList).get(anyObject()); verify(mocked).someMethod(anyBoolean(), anyByte(), anyChar(), anyInt(), anyLong(), anyFloat(), anyDouble()); verify(mocked).someOtherMethod(anyShort(), anyString(), anyList(), anySet(), anyMap(), anyCollection(), anyIterable()); verify(mocked).someOtherOtherMethod(any(), any(String.class), isA(String.class), isNull(), isNotNull(), notNull(), anyListOf(Object.class), anySetOf(Object.class), anyCollectionOf(Object.class), anyMapOf(Long.class, List.class)); verify(mocked).someOtherOtherOtherMethod(startsWith("prefix")); verify(mocked).method1(intThat(new ArgumentMatcher<Integer>() { @Override public boolean matches(Integer actual) { return actual < 4; } })); verify(mocked).method1(intThat(new LessOrEqual<>(4))); verify(mockedList, never()).clear(); verify(mockedList, times(cardinality())).size(); verify(mockedList, atLeastOnce()).size(); verify(mockedList, Mockito.atLeast(2)).size(); verify(mockedList, org.mockito.Mockito.atMost(4)).size(); verifyNoMoreInteractions(mockedList); }
/** * comparable argument less than or equal the given value details. * <p> * See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return <code>null</code>. */ public static <T extends Comparable<T>> T leq(Comparable<T> value) { return reportMatcher(new LessOrEqual<T>(value)).<T>returnNull(); }
/** * byte argument less than or equal to the given value. * <p> * See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return <code>0</code>. */ public static byte leq(byte value) { return reportMatcher(new LessOrEqual<Byte>(value)).returnZero(); }
/** * double argument less than or equal to the given value. * <p> * See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return <code>0</code>. */ public static double leq(double value) { return reportMatcher(new LessOrEqual<Double>(value)).returnZero(); }
/** * float argument less than or equal to the given value. * <p> * See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return <code>0</code>. */ public static float leq(float value) { return reportMatcher(new LessOrEqual<Float>(value)).returnZero(); }
/** * int argument less than or equal to the given value. * <p> * See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return <code>0</code>. */ public static int leq(int value) { return reportMatcher(new LessOrEqual<Integer>(value)).returnZero(); }
/** * long argument less than or equal to the given value. * <p> * See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return <code>0</code>. */ public static long leq(long value) { return reportMatcher(new LessOrEqual<Long>(value)).returnZero(); }
/** * short argument less than or equal to the given value. * <p> * See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return <code>0</code>. */ public static short leq(short value) { return reportMatcher(new LessOrEqual<Short>(value)).returnZero(); }