0

I have a service layer (Code Below:)

@Service
public class EquityFeedsService {

    @Autowired
    private EquityFeedsRedisRepositoryImpl equityFeedsRedisRepositoryImpl;

    public void save(EquityFeeds equityFeeds) {

        logger.info("Inside the save method of EquityFeedsService.");

        equityFeedsRedisRepositoryImpl.save(equityFeeds);
    }

   // other methods 
}

Now I am trying to write a Unit Test case for the above method below:

@ExtendWith(SpringExtension.class)
@AutoConfigureMockMvc
public class EquityFeedsServiceTest {

    private MockMvc mockMvc;

    @InjectMocks
    private EquityFeedsService equityFeedsService;

    @Mock
    private EquityFeedsRedisRepositoryImpl equityFeedsRedisRepositoryImpl;

    @BeforeEach
    public void setUp() {
        mockMvc = MockMvcBuilders.standaloneSetup(equityFeedsService).build();
    }

    @Test
    public void testSaveMethod() {
        EquityFeeds equityFeeds = new EquityFeeds(423,"SAPEXTXN1", "GS");

        when(equityFeedsRedisRepositoryImpl.save(any(EquityFeeds.class))).thenReturn(new EquityFeeds());


    }
}

This code gives me the below Exception: in line (any(EquityFeeds.class))

Required type:
EquityFeeds (This is my model class) 

Provided:
Matcher <com.investmentbank.equityfeedsprocessingupdated.model.EquityFeeds> (This is the fully qualified path name of the mode class) 
no instance(s) of type variable(s) T exist so that Matcher<T> conforms to EquityFeeds

and Exception :

Cannot resolve method 'thenReturn(com.investmentbank.equityfeedsprocessingupdated.model.EquityFeeds)'     

What is wrong with my Unit Test Case? How do i solve this?

sidd
  • 195
  • 3
  • 20

0 Answers0