Skip to content

Commit dffa01a

Browse files
committed
Fix major Sonar issues
1 parent 7df76e0 commit dffa01a

File tree

4 files changed

+35
-27
lines changed

4 files changed

+35
-27
lines changed

src/main/java/org/assertj/db/output/impl/PlainOutput.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,10 @@ private static List<Integer> getColumnSizesList(Row... rows) {
390390
}
391391
}
392392

393+
if (row0 == null) {
394+
return columnSizesList;
395+
}
396+
393397
List<String> columnsNameList = row0.getColumnsNameList();
394398
int index = 0;
395399
for (String columnName : columnsNameList) {

src/main/java/org/assertj/db/type/Table.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,14 @@ public OrderType getType() {
184184
return type;
185185
}
186186

187+
@Override
188+
public int hashCode() {
189+
int hash = 7;
190+
hash = 31 * hash + (type == null ? 0 : type.hashCode());
191+
hash = 31 * hash + (name == null ? 0 : name.hashCode());
192+
return hash;
193+
}
194+
187195
@Override
188196
public boolean equals(Object obj) {
189197
if (obj instanceof Order) {

src/test/java/org/assertj/db/type/Change_Exception_Test.java

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,48 +15,44 @@
1515
import org.assertj.db.common.AbstractTest;
1616
import org.junit.Test;
1717

18-
import java.util.Arrays;
19-
20-
import static org.assertj.core.api.Assertions.assertThat;
21-
import static org.junit.Assert.fail;
18+
import static java.util.Collections.singletonList;
19+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2220

2321
/**
2422
* Tests on the exceptions of Change
25-
*
23+
*
2624
* @author Régis Pouiller
27-
*
25+
*
2826
*/
2927
public class Change_Exception_Test extends AbstractTest {
3028

3129
/**
3230
* This method should fail because the data type must be not null.
3331
*/
3432
@Test
35-
public void should_fail_because_datatype_must_be_not_null() {
36-
try {
37-
getChange(null, "name", ChangeType.CREATION, getRow(Arrays.asList(""), Arrays.asList(""), Arrays.asList(getValue(
38-
null, null))),
39-
getRow(Arrays.asList(""), Arrays.asList(""), Arrays.asList(getValue(null, null))));
40-
41-
fail("An exception must be raised");
42-
} catch (Exception exception) {
43-
assertThat(exception.getCause().getLocalizedMessage()).isEqualTo("The type of the data must be not null");
44-
}
33+
public void should_fail_because_datatype_must_be_not_null() throws Exception {
34+
35+
Row start = getRow(singletonList(""), singletonList(""), singletonList(getValue(null, null)));
36+
Row end = getRow(singletonList(""), singletonList(""), singletonList(getValue(null, null)));
37+
38+
assertThatThrownBy(() -> getChange(null, "name", ChangeType.CREATION, start, end))
39+
.isInstanceOf(Exception.class)
40+
.getCause()
41+
.hasMessage("The type of the data must be not null");
4542
}
4643

4744
/**
4845
* This method should fail because the data name must be not null.
4946
*/
5047
@Test
51-
public void should_fail_because_dataname_must_be_not_null() {
52-
try {
53-
getChange(DataType.TABLE, null, ChangeType.CREATION, getRow(Arrays.asList(""), Arrays.asList(""), Arrays.asList(getValue(
54-
null, null))),
55-
getRow(Arrays.asList(""), Arrays.asList(""), Arrays.asList(getValue(null, null))));
56-
57-
fail("An exception must be raised");
58-
} catch (Exception exception) {
59-
assertThat(exception.getCause().getLocalizedMessage()).isEqualTo("The name of the data must be not null");
60-
}
48+
public void should_fail_because_dataname_must_be_not_null() throws Exception {
49+
50+
Row start = getRow(singletonList(""), singletonList(""), singletonList(getValue(null, null)));
51+
Row end = getRow(singletonList(""), singletonList(""), singletonList(getValue(null, null)));
52+
53+
assertThatThrownBy(() -> getChange(DataType.TABLE, null, ChangeType.CREATION, start, end))
54+
.isInstanceOf(Exception.class)
55+
.getCause()
56+
.hasMessage("The name of the data must be not null");
6157
}
6258
}

src/test/java/org/assertj/db/type/DateValue_Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ public void test_move_datetime() {
575575
assertThat(DateValue.of(2007, 12, 23).move(DateTimeValue.of(DateValue.of(0, -1, 0), TimeValue.of(0, 0)))).as("substract 1 month")
576576
.isEqualTo(DateTimeValue.of(DateValue.of(2007, 11, 23)));
577577
assertThat(DateValue.of(2007, 12, 23).move(DateTimeValue.of(DateValue.of(0, -2, 0), TimeValue.of(0, 0)))).as("substract 2 months")
578-
.isEqualTo(DateValue.of(2007, 10, 23));
578+
.isEqualTo(DateTimeValue.of(DateValue.of(2007, 10, 23)));
579579

580580
assertThat(DateValue.of(2007, 12, 23).move(DateTimeValue.of(DateValue.of(1, 0, 0), TimeValue.of(0, 0)))).as("add 1 year")
581581
.isEqualTo(DateTimeValue.of(DateValue.of(2008, 12, 23)));

0 commit comments

Comments
 (0)