Skip to content

Commit 6ae6445

Browse files
authored
Merge pull request gooddata#564 from gooddata/jmi-fix
improve ResultHeader* constructors
2 parents ec905c3 + 1cd99db commit 6ae6445

4 files changed

Lines changed: 43 additions & 2 deletions

File tree

src/main/java/com/gooddata/executeafm/result/ResultHeaderItem.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import com.fasterxml.jackson.annotation.JsonTypeInfo;
1010
import com.gooddata.util.GoodDataToStringBuilder;
1111

12-
import static com.gooddata.util.Validate.notEmpty;
12+
import static com.gooddata.util.Validate.notNull;
1313

1414
/**
1515
* Represent header items available in {@link ExecutionResult}
@@ -25,7 +25,7 @@ public abstract class ResultHeaderItem {
2525
private final String name;
2626

2727
protected ResultHeaderItem(final String name) {
28-
this.name = notEmpty(name, "name");
28+
this.name = notNull(name, "name");
2929
}
3030

3131
/**

src/main/java/com/gooddata/executeafm/result/ResultTotalHeaderItem.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ public class ResultTotalHeaderItem extends ResultHeaderItem {
2424

2525
private final String type;
2626

27+
/**
28+
* Creates new instance of given total type, type is used for the name as well
29+
* @param type total type
30+
*/
31+
public ResultTotalHeaderItem(final String type) {
32+
this(type, type);
33+
}
34+
35+
/**
36+
* Creates new instance of given total type, type is used for the name as well
37+
* @param type total type
38+
*/
39+
public ResultTotalHeaderItem(final Total type) {
40+
this(notNull(type, "type").toString());
41+
}
42+
2743
/**
2844
* Creates new instance of given header name and total type
2945
* @param name header name

src/test/groovy/com/gooddata/executeafm/result/ResultHeaderItemTest.groovy

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,17 @@ class ResultHeaderItemTest extends Specification {
2525
typeClass << [AttributeHeaderItem, ResultMeasureHeaderItem, ResultTotalHeaderItem]
2626
type = typeClass.simpleName.uncapitalize()
2727
}
28+
29+
def "should allow empty name"() {
30+
expect:
31+
new ResultHeaderItem('') {}.name == ''
32+
}
33+
34+
def "should not allow null name"() {
35+
when:
36+
new ResultHeaderItem(null) {}
37+
38+
then:
39+
thrown(IllegalArgumentException)
40+
}
2841
}

src/test/groovy/com/gooddata/executeafm/result/ResultTotalHeaderItemTest.groovy

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,16 @@ class ResultTotalHeaderItemTest extends Specification {
3232
item.name == 'Some total'
3333
item.type == 'avg'
3434
}
35+
36+
def "should create from type only"() {
37+
expect:
38+
with(new ResultTotalHeaderItem('avg')) {
39+
name == 'avg'
40+
type == 'avg'
41+
}
42+
with(new ResultTotalHeaderItem(Total.SUM)) {
43+
name == 'sum'
44+
type == 'sum'
45+
}
46+
}
3547
}

0 commit comments

Comments
 (0)