habuma / spring-in-action-5-samples

Home for example code from Spring in Action 5.
Apache License 2.0
1.21k stars 1.04k forks source link

Suggestions for DesignTacoControllerTest.java in chapter 3 jpa example #39

Open aCodeRancher opened 5 years ago

aCodeRancher commented 5 years ago

I have a suggestion for this test case: In the setup method, add these three lines after design.setName("Test Taco"): design.setId(1L); when (designRepository.findByName("Test Taco")).thenReturn(design); when (designRepository.findById(1L)).thenReturn(Optional.of(design));

In the processDesign(), add these unit test cases: Optional mytaco = designRepository.findById(1L) ;

Assert.notNull(mytaco.get(), "taco created");
Long id = mytaco.get().getId();
Assert.isTrue(id==1L,"id is 1");
Taco t = designRepository.findByName("Test Taco");
Assert.isTrue(t.getName().equals("Test Taco"), "taco is test taco");

In TacoRepository.java, add public Taco findByName(String name);