-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCountryAddressTests.java
165 lines (149 loc) · 4.07 KB
/
CountryAddressTests.java
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package tests;
import java.io.BufferedReader;
import java.io.FileReader;
import junit.framework.TestCase;
import models.Address;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class CountryAddressTests extends TestCase {
private Address address;
private BufferedReader reader1;
private BufferedReader reader2;
public CountryAddressTests(String name) {
super(name);
}
@Before
public void setUp() {
try {
this.address = new Address();
this.reader1 = new BufferedReader(new FileReader("CountriesCorrect.txt"));
this.reader2 = new BufferedReader(new FileReader("CountriesWrong.txt"));
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
@Test
public void testCountryAddressCorrect() {
try {
this.address.setCountry("România");
assertEquals("România", this.address.getCountry());
} catch (Exception ex) {
System.out.println(ex.getMessage());
fail(ex.getMessage());
}
}
@Test
public void testCountriesAddressCorrectUsingFile() {
try {
String line = reader1.readLine();
while (line != null) {
this.address.setCountry(line);
System.out.print(this.address.getCountry() + " ");
assertEquals(line, this.address.getCountry());
line = reader1.readLine();
}
System.out.println();
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
@Test(expected = AssertionError.class)
public void testCountriesAddressWrongUsingFile() {
String line = null;
try {
line = reader2.readLine();
while (line != null) {
try {
this.address.setCountry(line);
assertEquals(line, this.address.getCountry());
System.out.print(this.address.getCountry() + " ");
} catch (Exception ex) {
System.out.println(ex.getMessage());
assertEquals(line, this.address.getCountry());
}
line = reader2.readLine();
}
System.out.println();
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
@Test
public void testCountryAddressWrong1() {
try {
this.address.setCountry(null);
} catch (Exception ex) {
System.out.println(ex.getMessage());
// fail(ex.getMessage());
assertNull(this.address.getCountry());
}
}
@Test(expected = AssertionError.class)
public void testCountryAddressWrong2() {
try {
this.address.setCountry("Ro");
} catch (Exception ex) {
System.out.println(ex.getMessage());
// fail(ex.getMessage());
assertEquals("Ro", this.address.getCountry());
}
}
@Test(expected = AssertionError.class)
public void testCountryAddressWrong3() {
try {
this.address.setCountry("Româniaaaaaaaaaaaaaaaaaaaaaaaaaa");
} catch (Exception ex) {
System.out.println(ex.getMessage());
// fail(ex.getMessage());
assertEquals("Româniaaaaaaaaaaaaaaaaaaaaaaaaaa",
this.address.getCountry());
}
}
@Test(expected = AssertionError.class)
public void testCountryAddressWrong4() {
try {
this.address.setCountry("România#$%");
} catch (Exception ex) {
System.out.println(ex.getMessage());
// fail(ex.getMessage());
assertEquals("România#$%", this.address.getCountry());
}
}
@Test(expected = AssertionError.class)
public void testCountryAddressWrong5() {
try {
this.address.setCountry("românia");
} catch (Exception ex) {
System.out.println(ex.getMessage());
// fail(ex.getMessage());
assertEquals("românia", this.address.getCountry());
}
}
@Test(expected = AssertionError.class)
public void testCountryAddressWrong6() {
try {
this.address.setCountry("Republica moldova");
} catch (Exception ex) {
System.out.println(ex.getMessage());
// fail(ex.getMessage());
assertEquals("Republica moldova", this.address.getCountry());
}
}
@Test(expected = AssertionError.class)
public void testCountryAddressWrong7() {
try {
this.address.setCountry("Republica MOLDOVA");
} catch (Exception ex) {
System.out.println(ex.getMessage());
// fail(ex.getMessage());
assertEquals("Republica MOLDOVA", this.address.getCountry());
}
}
@After
public void tearDown() throws Exception {
this.reader1.close();
this.reader2.close();
this.address = null;
}
}