summaryrefslogtreecommitdiff
path: root/src/test/java/org/mockitousage/basicapi/MocksCreationTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/mockitousage/basicapi/MocksCreationTest.java')
-rw-r--r--src/test/java/org/mockitousage/basicapi/MocksCreationTest.java40
1 files changed, 31 insertions, 9 deletions
diff --git a/src/test/java/org/mockitousage/basicapi/MocksCreationTest.java b/src/test/java/org/mockitousage/basicapi/MocksCreationTest.java
index 98ab7d2..b5892ef 100644
--- a/src/test/java/org/mockitousage/basicapi/MocksCreationTest.java
+++ b/src/test/java/org/mockitousage/basicapi/MocksCreationTest.java
@@ -12,13 +12,21 @@ import org.mockito.exceptions.verification.SmartNullPointerException;
import org.mockitousage.IMethods;
import org.mockitoutil.TestBase;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
-import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.*;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.RETURNS_SMART_NULLS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.withSettings;
@SuppressWarnings("unchecked")
public class MocksCreationTest extends TestBase {
@@ -26,12 +34,12 @@ public class MocksCreationTest extends TestBase {
private class HasPrivateConstructor {}
@Test
- public void shouldCreateMockWhenConstructorIsPrivate() {
+ public void should_create_mock_when_constructor_is_private() {
assertNotNull(Mockito.mock(HasPrivateConstructor.class));
}
@Test
- public void shouldCombineMockNameAndSmartNulls() {
+ public void should_combine_mock_name_and_smart_nulls() {
//given
IMethods mock = mock(IMethods.class, withSettings()
.defaultAnswer(RETURNS_SMART_NULLS)
@@ -51,7 +59,7 @@ public class MocksCreationTest extends TestBase {
}
@Test
- public void shouldCombineMockNameAndExtraInterfaces() {
+ public void should_combine_mock_name_and_extra_interfaces() {
//given
IMethods mock = mock(IMethods.class, withSettings()
.extraInterfaces(List.class)
@@ -67,7 +75,7 @@ public class MocksCreationTest extends TestBase {
}
@Test
- public void shouldSpecifyMockNameViaSettings() {
+ public void should_specify_mock_name_via_settings() {
//given
IMethods mock = mock(IMethods.class, withSettings().name("great mockie"));
@@ -79,7 +87,7 @@ public class MocksCreationTest extends TestBase {
}
@Test
- public void shouldScreamWhenSpyCreatedWithWrongType() {
+ public void should_scream_when_spy_created_with_wrong_type() {
//given
List list = new LinkedList();
try {
@@ -92,14 +100,28 @@ public class MocksCreationTest extends TestBase {
@SuppressWarnings({"CheckReturnValue", "MockitoUsage"})
@Test
- public void shouldAllowCreatingSpiesWithCorrectType() {
+ public void should_allow_creating_spies_with_correct_type() {
List list = new LinkedList();
mock(LinkedList.class, withSettings().spiedInstance(list));
}
@Test
- public void shouldAllowInlineMockCreation() throws Exception {
+ public void should_allow_inline_mock_creation() {
when(mock(Set.class).isEmpty()).thenReturn(false);
}
+ @Retention(RetentionPolicy.RUNTIME)
+ @interface SomeAnnotation {}
+
+ @SomeAnnotation static class Foo {}
+
+ @Test
+ public void should_strip_annotations() {
+ Foo withAnnotations = mock(Foo.class);
+ Foo withoutAnnotations = mock(Foo.class, withSettings().withoutAnnotations());
+
+ //expect:
+ assertTrue(withAnnotations.getClass().isAnnotationPresent(SomeAnnotation.class));
+ assertFalse(withoutAnnotations.getClass().isAnnotationPresent(SomeAnnotation.class));
+ }
}