-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCountyAddressTests.java
175 lines (159 loc) · 4.41 KB
/
CountyAddressTests.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
166
167
168
169
170
171
172
173
174
175
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 CountyAddressTests extends TestCase {
private Address address;
private BufferedReader reader1;
private BufferedReader reader2;
public CountyAddressTests(String name) {
super(name);
}
@Before
public void setUp() {
try {
this.address = new Address();
this.reader1 = new BufferedReader(new FileReader("CountiesCorrect.txt"));
this.reader2 = new BufferedReader(new FileReader("CountiesWrong.txt"));
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
@Test
public void testCountyAddressCorrect() {
try {
this.address.setCountry("România");
this.address.setCounty("Dâmbovița");
assertEquals("Dâmbovița", this.address.getCounty());
} catch (Exception ex) {
System.out.println(ex.getMessage());
fail(ex.getMessage());
}
}
@Test
public void testCountiesAddressCorrectUsingFile() {
try {
String line = reader1.readLine();
while (line != null) {
this.address.setCountry("România");
this.address.setCounty(line);
System.out.print(this.address.getCounty() + " ");
assertEquals(line, this.address.getCounty());
line = reader1.readLine();
}
System.out.println();
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
@Test(expected = AssertionError.class)
public void testCountiesAddressWrongUsingFile() {
String line = null;
try {
line = reader2.readLine();
while (line != null) {
try {
this.address.setCountry("România");
this.address.setCounty(line);
assertEquals(line, this.address.getCounty());
System.out.print(this.address.getCounty() + " ");
} catch (Exception ex) {
System.out.println(ex.getMessage());
assertEquals(line, this.address.getCounty());
}
line = reader2.readLine();
}
System.out.println();
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
@Test
public void testCountyAddressWrong1() {
try {
this.address.setCountry("România");
this.address.setCounty(null);
} catch (Exception ex) {
System.out.println(ex.getMessage());
assertNull(address.getCounty());
// fail(ex.getMessage());
}
}
@Test(expected = AssertionError.class)
public void testCountyAddressWrong2() {
try {
this.address.setCountry("România");
this.address.setCounty("Dâmbovițaaaaaaaaaaaaaaaaaaaaaaaa");
} catch (Exception ex) {
System.out.println(ex.getMessage());
// fail(ex.getMessage());
assertEquals("Dâmbovițaaaaaaaaaaaaaaaaaaaaaaaa",
this.address.getCounty());
}
}
@Test(expected = AssertionError.class)
public void testCountyAddressWrong3() {
try {
this.address.setCountry("România");
this.address.setCounty("Dâ");
} catch (Exception ex) {
System.out.println(ex.getMessage());
// fail(ex.getMessage());
assertEquals("Dâ", this.address.getCounty());
}
}
@Test(expected = AssertionError.class)
public void testCountyAddressWrong4() {
try {
this.address.setCountry("România");
this.address.setCounty("Dâmbovița123");
} catch (Exception ex) {
System.out.println(ex.getMessage());
// fail(ex.getMessage());
assertEquals("Dâmbovița123", this.address.getCounty());
}
}
@Test(expected = AssertionError.class)
public void testCountyAddressWrong5() {
try {
this.address.setCountry("România");
this.address.setCounty("dâmbovița");
} catch (Exception ex) {
System.out.println(ex.getMessage());
// fail(ex.getMessage());
assertEquals("dâmbovița", this.address.getCounty());
}
}
@Test(expected = AssertionError.class)
public void testCountyAddressWrong6() {
try {
this.address.setCountry("România");
this.address.setCounty("Satu MARE");
} catch (Exception ex) {
System.out.println(ex.getMessage());
// fail(ex.getMessage());
assertEquals("Satu MARE", this.address.getCounty());
}
}
@Test(expected = AssertionError.class)
public void testCountyAddressWrong7() {
try {
this.address.setCountry("România");
this.address.setCounty("Moldova");
} catch (Exception ex) {
System.out.println(ex.getMessage());
// fail(ex.getMessage());
assertEquals("Moldova", this.address.getCounty());
}
}
@After
public void tearDown() throws Exception {
this.address = null;
this.reader1.close();
this.reader2.close();
}
}