View Javadoc
1   /*
2    *    Copyright 2010-2022 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       https://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  package org.mybatis.jpetstore.mapper;
17  
18  import static org.assertj.core.api.Assertions.assertThat;
19  
20  import java.util.Comparator;
21  import java.util.List;
22  
23  import org.junit.jupiter.api.Test;
24  import org.junit.jupiter.api.extension.ExtendWith;
25  import org.mybatis.jpetstore.domain.Category;
26  import org.springframework.beans.factory.annotation.Autowired;
27  import org.springframework.test.context.ContextConfiguration;
28  import org.springframework.test.context.junit.jupiter.SpringExtension;
29  import org.springframework.transaction.annotation.Transactional;
30  
31  @ExtendWith(SpringExtension.class)
32  @ContextConfiguration(classes = MapperTestContext.class)
33  @Transactional
34  class CategoryMapperTest {
35  
36    @Autowired
37    private CategoryMapper mapper;
38  
39    @Test
40    void getCategoryList() {
41      // given
42  
43      // when
44      List<Category> categories = mapper.getCategoryList();
45  
46      // then
47      categories.sort(Comparator.comparing(Category::getCategoryId));
48      assertThat(categories).hasSize(5);
49      assertThat(categories.get(0).getCategoryId()).isEqualTo("BIRDS");
50      assertThat(categories.get(0).getName()).isEqualTo("Birds");
51      assertThat(categories.get(0).getDescription())
52          .isEqualTo("<image src=\"../images/birds_icon.gif\"><font size=\"5\" color=\"blue\"> Birds</font>");
53      assertThat(categories.get(1).getCategoryId()).isEqualTo("CATS");
54      assertThat(categories.get(1).getName()).isEqualTo("Cats");
55      assertThat(categories.get(1).getDescription())
56          .isEqualTo("<image src=\"../images/cats_icon.gif\"><font size=\"5\" color=\"blue\"> Cats</font>");
57      assertThat(categories.get(2).getCategoryId()).isEqualTo("DOGS");
58      assertThat(categories.get(2).getName()).isEqualTo("Dogs");
59      assertThat(categories.get(2).getDescription())
60          .isEqualTo("<image src=\"../images/dogs_icon.gif\"><font size=\"5\" color=\"blue\"> Dogs</font>");
61      assertThat(categories.get(3).getCategoryId()).isEqualTo("FISH");
62      assertThat(categories.get(3).getName()).isEqualTo("Fish");
63      assertThat(categories.get(3).getDescription())
64          .isEqualTo("<image src=\"../images/fish_icon.gif\"><font size=\"5\" color=\"blue\"> Fish</font>");
65      assertThat(categories.get(4).getCategoryId()).isEqualTo("REPTILES");
66      assertThat(categories.get(4).getName()).isEqualTo("Reptiles");
67      assertThat(categories.get(4).getDescription())
68          .isEqualTo("<image src=\"../images/reptiles_icon.gif\"><font size=\"5\" color=\"blue\"> Reptiles</font>");
69    }
70  
71    @Test
72    void getCategory() {
73      // given
74      String categoryId = "BIRDS";
75  
76      // when
77      Category category = mapper.getCategory(categoryId);
78  
79      // then
80      assertThat(category.getCategoryId()).isEqualTo("BIRDS");
81      assertThat(category.getName()).isEqualTo("Birds");
82      assertThat(category.getDescription())
83          .isEqualTo("<image src=\"../images/birds_icon.gif\"><font size=\"5\" color=\"blue\"> Birds</font>");
84    }
85  
86  }