Skip to content

Commit b059c84

Browse files
Added CheckEmptyHelper
1 parent 75c46b0 commit b059c84

File tree

3 files changed

+132
-0
lines changed

3 files changed

+132
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.fugerit.java.core.lang.compare;
2+
3+
import org.fugerit.java.core.lang.helpers.StringUtils;
4+
5+
public class CheckEmptyHelper {
6+
7+
public static boolean isEmpty( Object v ) {
8+
boolean empty = ( v == null );
9+
if ( !empty ) {
10+
if( v instanceof String ) {
11+
empty = StringUtils.isEmpty( (String)v );
12+
} else if ( v instanceof CheckEmpty ) {
13+
empty = ((CheckEmpty)v).isEmpty();
14+
}
15+
}
16+
return empty;
17+
}
18+
19+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package test.org.fugerit.java.core.lang.compare;
2+
3+
import java.io.Serializable;
4+
5+
import org.fugerit.java.core.lang.compare.CheckEmpty;
6+
import org.fugerit.java.core.lang.helpers.StringUtils;
7+
8+
public class CheckEmptyModel implements Serializable, CheckEmpty {
9+
10+
/**
11+
*
12+
*/
13+
private static final long serialVersionUID = 7042054220652894764L;
14+
15+
private String prop1;
16+
17+
private String prop2;
18+
19+
public String getProp1() {
20+
return prop1;
21+
}
22+
23+
public void setProp1(String prop1) {
24+
this.prop1 = prop1;
25+
}
26+
27+
public String getProp2() {
28+
return prop2;
29+
}
30+
31+
public void setProp2(String prop2) {
32+
this.prop2 = prop2;
33+
}
34+
35+
public CheckEmptyModel(String prop1, String prop2) {
36+
super();
37+
this.prop1 = prop1;
38+
this.prop2 = prop2;
39+
}
40+
41+
@Override
42+
public boolean isEmpty() {
43+
return StringUtils.isEmpty( this.getProp1() ) && StringUtils.isEmpty( this.getProp2() );
44+
}
45+
46+
47+
48+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package test.org.fugerit.java.core.lang.compare;
2+
3+
import static org.junit.Assert.fail;
4+
5+
import org.fugerit.java.core.lang.compare.CheckEmptyHelper;
6+
import org.junit.Test;
7+
8+
import test.org.fugerit.java.BasicTest;
9+
10+
public class TestCheckEmpty extends BasicTest {
11+
12+
public static boolean EMPTY = true;
13+
14+
public static boolean NOT_EMPTY = false;
15+
16+
private void checkEmptyHelper( Object value, boolean shouldBeEmpty ) {
17+
boolean empty = CheckEmptyHelper.isEmpty( value );
18+
if ( empty && !shouldBeEmpty ) {
19+
fail( "Value is empty is not expected" );
20+
} else if ( !empty && shouldBeEmpty ) {
21+
fail( "Value is not empty is expected" );
22+
}
23+
}
24+
25+
@Test
26+
public void test001() {
27+
this.checkEmptyHelper( "test" , NOT_EMPTY );
28+
}
29+
30+
@Test
31+
public void test002() {
32+
this.checkEmptyHelper( "" , EMPTY );
33+
}
34+
35+
@Test
36+
public void test003() {
37+
this.checkEmptyHelper( null , EMPTY );
38+
}
39+
40+
@Test
41+
public void test004() {
42+
this.checkEmptyHelper( new CheckEmptyModel( "", "" ) , EMPTY );
43+
}
44+
45+
@Test
46+
public void test005() {
47+
this.checkEmptyHelper( new CheckEmptyModel( "1", "2" ) , NOT_EMPTY );
48+
}
49+
50+
@Test
51+
public void test006() {
52+
this.checkEmptyHelper( new CheckEmptyModel( "1", null ) , NOT_EMPTY );
53+
}
54+
55+
@Test
56+
public void test007() {
57+
this.checkEmptyHelper( new CheckEmptyModel( null, "2" ) , NOT_EMPTY );
58+
}
59+
60+
@Test
61+
public void test008() {
62+
this.checkEmptyHelper( new CheckEmptyModel( null, null ) , EMPTY );
63+
}
64+
65+
}

0 commit comments

Comments
 (0)