forked from task032015/stringProblem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoveCharStringMethodTest.java
More file actions
108 lines (83 loc) · 3.48 KB
/
Copy pathRemoveCharStringMethodTest.java
File metadata and controls
108 lines (83 loc) · 3.48 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
99
100
101
102
103
104
105
106
107
108
package com.apple;
import java.util.regex.PatternSyntaxException;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class RemoveCharStringMethodTest {
RemoveChar rc = new RemoveChar();
@Test(description="stringProblem test with positive test data",
groups="positive",dataProvider="getPositiveTestData" , dataProviderClass = RemoveCharIterateTest.class)
public void charReplaceAllTest(String testString, char testChar, String expected) {
String actual;
rc.setOrgWord(testString);
rc.setOrgChar(testChar);
actual = rc.removeCharV1(rc.getOrgWord(), rc.getOrgChar());
System.out.println("Org Word is: \"" + rc.getOrgWord() +
"\", Char to remove is \'" + rc.getOrgChar() +
"\', String Method: replaceAll - Updated word : " + actual);
Assert.assertEquals(actual.equals(expected), true);
}
@Test(description="stringProblem with negative test data",
groups="negative",dataProvider="getNegativeTestData")
public void charReplaceAllNegativeTest(String testString, char testChar, String expected) {
String actual = "";
boolean pass = false;
rc.setOrgWord(testString);
rc.setOrgChar(testChar);
try {
actual = rc.removeCharV1(rc.getOrgWord(), rc.getOrgChar());
} catch ( PatternSyntaxException err) {
if(testChar == '*' || testChar == '?'){
System.out.println("PatternSyntaxException is thrown which is expected");
pass = true;
} else {
throw new PatternSyntaxException(err.getDescription(), err.getPattern(), err.getIndex());
}
}
System.out.println("Org Word is: \"" + rc.getOrgWord() +
"\", Char to remove is \'" + rc.getOrgChar() +
"\', String Method: replaceAll - Updated word : " + actual);
if(actual == null) {
Assert.assertNull(expected);
} else if(!pass){
Assert.assertEquals(actual.equals(expected), true);
}
}
@AfterClass
public void anyCleanup() {
System.out.println(" ----Complete ---- 2. Find a method in the String class that can solve this in one line");
}
@DataProvider(name="getNegativeTestData")
public Object[][] getNegativeTestData() {
return new Object[][]{
{"Java",' ',"Java"},
{null,' ',null},
{"",' ',""},
{"1234567890000000000",'0',"123456789"},
{"aaaaaaaaaaaaaaaaaaaa\\aaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaa",'a',"\\"},
{"This is some text to test stringProblem",'@',"This is some text to test stringProblem"},
{"!@#$%^&*()_+~",'@',"!#$%^&*()_+~"},
{"abcdefghijklmnopqrstuvwxyz1234567890-=][';/.,?><+_!@#$%^&*()~:",'*',"abcdefghijklmnopqrstuvwxyz1234567890-=][';/.,?><+_!@#$%^&()~:"},
{"a-=][';/.,?><+_!@#$%^&*()~:",'.',""},
{"Is it really a test?",'?',"Is it really a test"},
{"public void charIterateNegativeTest(String testString, char testChar, String expected) {"
+ "String actual;"
+ "rc.setOrgWord(testString);"
+ "rc.setOrgChar(testChar);"
+ "actual = rc.removeCharV2(rc.getOrgWord(), rc.getOrgChar());"
+ "System.out.println(\"Org Word is: \"\" + rc.getOrgWord() +"
+ "\"\\\", Char to remove is \'\" + rc.getOrgChar() +"
+ "\"\', Iterate Method Updated word : \" + actual);"
+ "if(actual == null) {"
+ "Assert.assertNull(expected);"
+ "} else {"
+ "Assert.assertEquals(actual.equals(expected), true);"
+ "}"
+ "}",'.',""}
};
}
}