-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpruebas.patch
More file actions
98 lines (96 loc) · 3.09 KB
/
pruebas.patch
File metadata and controls
98 lines (96 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
diff --git a/build.gradle b/build.gradle
index b5605b8..cecc2c6 100644
--- a/build.gradle
+++ b/build.gradle
@@ -33,6 +33,7 @@ repositories {
dependencies {
annotationProcessor("org.seasar.doma:doma-processor:${dependentVersion}")
+ implementation 'org.springframework.boot:spring-boot-starter-validation:2.3.0.RC1'
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-jdbc")
@@ -42,9 +43,22 @@ dependencies {
implementation("com.h2database:h2")
implementation("org.webjars:jquery:2.1.1")
compileOnly("org.springframework.boot:spring-boot-devtools")
- testImplementation("junit:junit")
+
+ testImplementation 'org.springframework.boot:spring-boot-starter-test:2.3.0.RC1'
+ testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.6.2'
+ testImplementation 'org.mockito:mockito-junit-jupiter:3.3.3'
+
+ //Agregado esto para poder usar JUnit3-4 y probar con el framework de JUnit5
+ testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
+ testCompileOnly 'junit:junit:4.13'
+ testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
+}
+
+test {
+ useJUnitPlatform()
}
+
eclipse {
classpath {
file {
diff --git a/src/test/java/model/CartTest.java b/src/test/java/model/CartTest.java
new file mode 100644
index 0000000..f0e3254
--- /dev/null
+++ b/src/test/java/model/CartTest.java
@@ -0,0 +1,55 @@
+package test.java.model;
+
+
+import org.junit.jupiter.api.Test;
+import org.springframework.context.i18n.LocaleContextHolder;
+import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+import java.util.Locale;
+
+import sample.model.Cart;
+import sample.model.CartItem;
+import sample.entity.Item;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class ShoppingCartTest {
+
+ private Validator createValidator() {
+ LocalValidatorFactoryBean localValidatorFactoryBean = new LocalValidatorFactoryBean();
+ localValidatorFactoryBean.afterPropertiesSet();
+ return localValidatorFactoryBean;
+ }
+
+ @Test
+ public void addOneItem() {
+ LocaleContextHolder.setLocale(Locale.ENGLISH);
+
+ Cart c = new Cart();
+ assertThat(c.getNumberOfItems()).isEqualTo(0);
+ assertThat(c.isEmpty()).isTrue();
+
+ Item i = new Item();
+ i.setItemId("1");
+ i.setProductId("1");
+ i.setQuantity(3);
+ i.setProductName("Producto 1");
+
+ c.addItem(i, true);
+ assertThat(c.getNumberOfItems()).isEqualTo(1);
+ assertThat(c.isEmpty()).isFalse();
+
+ CartItem ci = c.getCartItem("1");
+ assertThat(ci).isNotNull();
+ assertThat(ci.getQuantity()).isEqualTo(1);
+ assertThat(ci.isInStock()).isTrue();
+
+ Item i1 = ci.getItem();
+ assertThat(i1.getQuantity()).isEqualTo(3);
+ assertThat(i1.getProductId()).isEqualTo("1");
+
+ }
+
+}
\ No newline at end of file