I think you do need to cast it, but it shouldn’t be too bad:
Foo<Bar> mockFoo = (Foo<Bar>) mock(Foo.class);
when(mockFoo.getValue()).thenReturn(new Bar());
More Related Contents:
- Mockito.any() pass Interface with Generics
- mocking a method that return generics with wildcard using mockito
- Mocking static methods with Mockito
- Why don’t Java Generics support primitive types?
- How to mock a final class with mockito
- How to create a generic array in Java?
- Jackson and generic type reference
- Why does javac complain about generics unrelated to the class’ type arguments? [duplicate]
- How to avoid type safety warnings with Hibernate HQL results?
- Cast Object to Generic Type for returning
- How to cast List to List
- How do I clone a generic List in Java?
- Java generics T vs Object
- How to Autowire Bean of generic type in Spring?
- Calling static generic methods
- How to mock an enum singleton class using Mockito/Powermock?
- Bounded-wildcard related compiler error
- Understanding upper and lower bounds on ? in Java Generics
- Java generics – Make Generic to extends 2 interfaces
- Initialize Java Generic Array of Type Generic
- Heterogeneous container to store genericly typed objects in Java
- Mockito: Inject real objects into private @Autowired fields
- How can elements be added to a wildcard generic collection?
- What does List mean in java generics?
- How to mock RestTemplate in Java Spring?
- Mockito, @InjectMocks strange behaviour with final fields
- Collections.emptyList() returns a List?
- What does a tilde in angle brackets mean when creating a Java generic class?
- Cannot use Java 8 method with lambda arguments without specifying type arguments
- Java generic type