Skip to content

Commit 127ee73

Browse files
committedFeb 27, 2014
Further prepare skeleton of test classes and implement first tips.
1 parent 54ca094 commit 127ee73

15 files changed

+281
-6
lines changed
 

‎.gitignore

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
*.class
22

33
# Package Files #
4-
*.jar
5-
*.war
6-
*.ear
4+
#*.war
5+
#*.ear

‎JavaTips/.classpath

+2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
<classpathentry kind="src" path="src"/>
44
<classpathentry kind="src" path="test"/>
55
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
6+
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
7+
<classpathentry kind="lib" path="ext-lib/commons-lang3-3.2.1.jar"/>
68
<classpathentry kind="output" path="target"/>
79
</classpath>
376 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,35 @@
11
package com.kosi2801.javatips;
22

3+
import org.junit.Test;
4+
35
/**
46
* Example for the Java Tip #1: Use StringBuilder instead of StringBuffer
57
*
68
* @author kosi2801
7-
* @see http://kosi2801.freepgs.com/2010/04/17/java_tip_1_use_stringbuilder_instead_of_stringbuffer.html
9+
* @see http://kosi2801.freepgs.com/2010/04/17/
10+
* java_tip_1_use_stringbuilder_instead_of_stringbuffer.html
811
*
912
*/
1013
public class Tip01UseStringBuilderForStringBuffer {
1114

15+
/**
16+
* @deprecated Using StringBuffer is discouraged. Use StringBuilder instead.
17+
* Use StringBuffer only if synchronisation is required.
18+
* @see after_1()
19+
*/
20+
@Test
21+
@Deprecated
22+
public void before_1() {
23+
StringBuffer str = new StringBuffer();
24+
str.append("foo");
25+
String x = str.toString();
26+
}
27+
28+
@Test
29+
public void after_1() {
30+
StringBuilder str = new StringBuilder();
31+
str.append("foo");
32+
String x = str.toString();
33+
}
34+
1235
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,39 @@
11
package com.kosi2801.javatips;
22

3+
import org.junit.Test;
4+
35
/**
46
* Example for the Java Tip #2: Use StringBuilder for String concatenation
57
*
68
* @author kosi2801
7-
* @see http://kosi2801.freepgs.com/2010/04/23/java_tip_2_use_stringbuilder_for_string_concatenation.html
9+
* @see http://kosi2801.freepgs.com/2010/04/23/
10+
* java_tip_2_use_stringbuilder_for_string_concatenation.html
811
*
912
*/
1013
public class Tip02UseStringBuilderForStringConcats {
1114

15+
/**
16+
* @deprecated Unbuffered String concatenation is very slow as it requires
17+
* multiple String instances and copying contents. Use
18+
* StringBuilder instead.
19+
* @see after_1()
20+
*/
21+
@Test
22+
@Deprecated
23+
public void before_1() {
24+
String test = "";
25+
for (int i = 0; i < 50000; i++) {
26+
test += "abc";
27+
}
28+
}
29+
30+
@Test
31+
public void after_1() {
32+
StringBuilder testBuilder = new StringBuilder();
33+
for (int i = 0; i < 50000; i++) {
34+
testBuilder.append("abc");
35+
}
36+
String test = testBuilder.toString();
37+
}
38+
1239
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,65 @@
11
package com.kosi2801.javatips;
22

3+
import org.apache.commons.lang3.StringUtils;
4+
import org.junit.Test;
5+
36
/**
47
* Example for the Java Tip #3: Use Apache Commons StringUtils for String checks
58
*
69
* @author kosi2801
7-
* @see http://kosi2801.freepgs.com/2010/05/13/java_tip_3_use_apache_commons_stringutils_for_string_checks.html
10+
* @see http://kosi2801.freepgs.com/2010/05/13/
11+
* java_tip_3_use_apache_commons_stringutils_for_string_checks.html
812
*
913
*/
1014
public class Tip03UseStringUtilsForStringChecks {
1115

16+
/**
17+
* @deprecated Checking Strings manually requires additional null-checks, is
18+
* not very readable and prone for errors when refactoring. Use
19+
* StringUtils instead.
20+
* @see after_1()
21+
*/
22+
@Test
23+
@Deprecated
24+
public void before_1() {
25+
String str = "";
26+
27+
// Check 1
28+
if (str != null && !str.equals("")) { /* */
29+
}
30+
31+
// Check 2
32+
if (str != null && !str.trim().equals("")) { /* */
33+
}
34+
35+
// Check 3
36+
if ("".equals(str)) { /* */
37+
}
38+
39+
// Check 4
40+
if (str == null || "".equals(str.trim())) { /* */
41+
}
42+
}
43+
44+
@Test
45+
public void after_1() {
46+
String str = "";
47+
48+
// Check 1
49+
if (StringUtils.isNotEmpty(str)) { /* */
50+
}
51+
52+
// Check 2
53+
if (StringUtils.isNotBlank(str)) { /* */
54+
}
55+
56+
// Check 3
57+
if (StringUtils.isEmpty(str)) { /* */
58+
}
59+
60+
// Check 4
61+
if (StringUtils.isBlank(str)) { /* */
62+
}
63+
}
64+
1265
}

‎JavaTips/test/com/kosi2801/javatips/Tip04UseImplicitNullChecksWithConstants.java

+19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package com.kosi2801.javatips;
22

3+
import static org.junit.Assert.fail;
4+
5+
import org.junit.Test;
6+
37
/**
48
* Example for the Java Tip #4: Use implicit NULL checks on constants
59
*
@@ -9,4 +13,19 @@
913
*/
1014
public class Tip04UseImplicitNullChecksWithConstants {
1115

16+
/**
17+
* @deprecated bla
18+
* @see after_1()
19+
*/
20+
@Test
21+
@Deprecated
22+
public void before_1() {
23+
fail("not yet implemented");
24+
}
25+
26+
@Test
27+
public void after_1() {
28+
fail("not yet implemented");
29+
}
30+
1231
}

‎JavaTips/test/com/kosi2801/javatips/Tip05UseDateUtilsForDateCalculations.java

+19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package com.kosi2801.javatips;
22

3+
import static org.junit.Assert.fail;
4+
5+
import org.junit.Test;
6+
37
/**
48
* Example for the Java Tip #5: Use Apache Commons DateUtils when dealing with dates
59
*
@@ -9,4 +13,19 @@
913
*/
1014
public class Tip05UseDateUtilsForDateCalculations {
1115

16+
/**
17+
* @deprecated bla
18+
* @see after_1()
19+
*/
20+
@Test
21+
@Deprecated
22+
public void before_1() {
23+
fail("not yet implemented");
24+
}
25+
26+
@Test
27+
public void after_1() {
28+
fail("not yet implemented");
29+
}
30+
1231
}

‎JavaTips/test/com/kosi2801/javatips/Tip06UseJava5ForEach.java

+19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package com.kosi2801.javatips;
22

3+
import static org.junit.Assert.fail;
4+
5+
import org.junit.Test;
6+
37
/**
48
* Example for the Java Tip #6: Use the for-each of Java5 whenever possible
59
*
@@ -9,4 +13,19 @@
913
*/
1014
public class Tip06UseJava5ForEach {
1115

16+
/**
17+
* @deprecated bla
18+
* @see after_1()
19+
*/
20+
@Test
21+
@Deprecated
22+
public void before_1() {
23+
fail("not yet implemented");
24+
}
25+
26+
@Test
27+
public void after_1() {
28+
fail("not yet implemented");
29+
}
30+
1231
}

‎JavaTips/test/com/kosi2801/javatips/Tip07MinimizeMapProcessing.java

+19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package com.kosi2801.javatips;
22

3+
import static org.junit.Assert.fail;
4+
5+
import org.junit.Test;
6+
37
/**
48
* Example for the Java Tip #7: Minimize Map processing
59
*
@@ -9,4 +13,19 @@
913
*/
1014
public class Tip07MinimizeMapProcessing {
1115

16+
/**
17+
* @deprecated bla
18+
* @see after_1()
19+
*/
20+
@Test
21+
@Deprecated
22+
public void before_1() {
23+
fail("not yet implemented");
24+
}
25+
26+
@Test
27+
public void after_1() {
28+
fail("not yet implemented");
29+
}
30+
1231
}

‎JavaTips/test/com/kosi2801/javatips/Tip08UseStringUtilsForStringArrayConcatenations.java

+19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package com.kosi2801.javatips;
22

3+
import static org.junit.Assert.fail;
4+
5+
import org.junit.Test;
6+
37
/**
48
* Example for the Java Tip #8: Use StringUtils for concatenating Strings from Arrays or Lists
59
*
@@ -9,4 +13,19 @@
913
*/
1014
public class Tip08UseStringUtilsForStringArrayConcatenations {
1115

16+
/**
17+
* @deprecated bla
18+
* @see after_1()
19+
*/
20+
@Test
21+
@Deprecated
22+
public void before_1() {
23+
fail("not yet implemented");
24+
}
25+
26+
@Test
27+
public void after_1() {
28+
fail("not yet implemented");
29+
}
30+
1231
}

‎JavaTips/test/com/kosi2801/javatips/Tip09UseCollectionUtilsForCollectionManipulation.java

+19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package com.kosi2801.javatips;
22

3+
import static org.junit.Assert.fail;
4+
5+
import org.junit.Test;
6+
37
/**
48
* Example for the Java Tip #9: Use CollectionUtils for evaluation and manipulation of Collections
59
*
@@ -9,4 +13,19 @@
913
*/
1014
public class Tip09UseCollectionUtilsForCollectionManipulation {
1115

16+
/**
17+
* @deprecated bla
18+
* @see after_1()
19+
*/
20+
@Test
21+
@Deprecated
22+
public void before_1() {
23+
fail("not yet implemented");
24+
}
25+
26+
@Test
27+
public void after_1() {
28+
fail("not yet implemented");
29+
}
30+
1231
}

‎JavaTips/test/com/kosi2801/javatips/Tip10UseInstanceOfOperatorForNullCheck.java

+19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package com.kosi2801.javatips;
22

3+
import static org.junit.Assert.fail;
4+
5+
import org.junit.Test;
6+
37
/**
48
* Example for the Java Tip #10: The instanceof-operator is null-safe
59
*
@@ -9,4 +13,19 @@
913
*/
1014
public class Tip10UseInstanceOfOperatorForNullCheck {
1115

16+
/**
17+
* @deprecated bla
18+
* @see after_1()
19+
*/
20+
@Test
21+
@Deprecated
22+
public void before_1() {
23+
fail("not yet implemented");
24+
}
25+
26+
@Test
27+
public void after_1() {
28+
fail("not yet implemented");
29+
}
30+
1231
}

0 commit comments

Comments
 (0)
Please sign in to comment.