title: Spring boot test: Test passes, but should not (false positive)
body: <p>I have Spring Boot project with test that does not fail (but should).</p>
  
  <p>Am I doing something wrong or it is a issue with Spring?</p>
  
  <p>For an small example I have created a small project with 2 entities (User and Category) and one Controller class that has DELETE method (<a href="https://github.com/sk8ter/demo" rel="nofollow">https://github.com/sk8ter/demo</a>).</p>
  
  <p>Category entity has an id of User entity without <em>cascade</em> option, so it should fail while deleting a User that has category:</p>
  
  <pre><code>@Entity
  @Table(name = "user")
  public class User {
  
      @Id
      @GeneratedValue
      private long id;
      private String name;
      ...
  }
  
  @Entity
  @Table(name = "category")
  public class Category {
  
      @Id
      @GeneratedValue
      private long id;
      private String name;
  
      @ManyToOne
      @JoinColumn(name = "user_id", nullable = false)
      private User user;
      ...
  }
  </code></pre>
  
  <p>Controller is also is pretty simple:</p>
  
  <pre><code>@RestController
  @RequestMapping(value = "/users", produces = "application/json;charset=UTF-8")
  public class UserCategory {
  
      @Autowired
      private UserRepository userRepository;
  
      @ResponseStatus(HttpStatus.OK)
      @RequestMapping(value = "/{id}", method = DELETE, consumes =   MediaType.ALL_VALUE)
      public void deleteCategory(@PathVariable Long id) {
          User user = userRepository.getOne(id);
          userRepository.delete(user);
      }
  }
  </code></pre>
  
  <p>And finally a test:</p>
  
  <pre><code>@Transactional
  @WebAppConfiguration
  @RunWith(SpringJUnit4ClassRunner.class)
  @SpringApplicationConfiguration(classes = DemoApplication.class)
  public class DemoApplicationTests {
  
      @Autowired
      protected WebApplicationContext context;
  
      protected MockMvc mockMvc;
  
      @Before
      public void setUp() {
          mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build();
      }
  
      @Test
      public void testName() throws Exception {
          mockMvc.perform(delete("/users/1"))
                  .andExpect(status().isOk());
  
  //      EntityManagerFactory entityManagerFactory = context.getBean(EntityManagerFactory.class);
  //      SessionFactory sessionFactory = entityManagerFactory.unwrap(SessionFactory.class);
  //      sessionFactory.getCurrentSession().flush();
      }
  }
  </code></pre>
  
  <p>Test will fail in case I remove <strong>@Transactional</strong> annotation from <em>DemoApplicationTests</em>, but in this case changes will be committed to a DB.</p>
  
  <p>Commented 3 lines in the test does not help either.</p>