title: Spring JpaRepository save() does not mock using Mockito
body: <p>I am new to Mockito library and stuck somewhere. </p>
  
  <p>Problem is when I mock save method of Spring jpaRepository I always get null. I am using such code in my project but for testing I have made a dummy code for testing. These are my code :</p>
  
  <pre><code>// This is the class for which I am making test case
      @Service("deviceManagementService")
      @Scope(BRASSConstants.SCOPE_SESSION)
      @Transactional
      public class DeviceManagementServiceImpl implements DeviceManagementService {
  
          public String  show(){
              Device device = new Device() ;
              device.setContactName("abc");
              Device deviceEntity = deviceDao.save(device);
              System.out.println(deviceEntity);  // i get this null always Why ???
              return "demo";
          }
      }
  </code></pre>
  
  <p>And the test case I am writing is :</p>
  
  <pre><code>    @RunWith(MockitoJUnitRunner.class)
      public class DemoTest {
  
          @InjectMocks
          private DeviceManagementServiceImpl deviceManagementServiceImpl;
  
          @Mock
          private DeviceDao deviceDao;
  
          @Before
          public void setUp() throws Exception {
              MockitoAnnotations.initMocks(this);
          }
  
          @Test
          public void show(){
              Device device = new Device() ;
              Device deviceEntity = new Device() ;
              deviceEntity.setDeviceId(12L);
              Mockito.when(deviceDao.save(device)).thenReturn(deviceEntity);
  
              Mockito.when(deviceManagementServiceImpl.show()).thenReturn(null) ;
          }
  
      }
  </code></pre>
  
  <p>If I use something like this</p>
  
  <pre><code>Mockito.when(deviceDao.findByDeviceSerialNo("234er")).thenReturn(deviceEntity); 
  </code></pre>
  
  <p>Then it works and give me not null object of Device.</p>
  
  <p>What is the reason for this?</p>