19
19
import org .junit .jupiter .api .Test ;
20
20
21
21
import static org .assertj .core .api .Assertions .assertThatThrownBy ;
22
+ import static org .assertj .core .api .AssertionsForClassTypes .assertThat ;
22
23
23
24
/**
24
25
* Unit tests for {@link Query}.
@@ -39,4 +40,42 @@ void whenTextIsEmptyThenThrow() {
39
40
.hasMessageContaining ("text cannot be null or empty" );
40
41
}
41
42
43
+ @ Test
44
+ void whenTextIsBlankThenThrow () {
45
+ assertThatThrownBy (() -> new Query (" " )).isInstanceOf (IllegalArgumentException .class )
46
+ .hasMessageContaining ("text cannot be null or empty" );
47
+ }
48
+
49
+ @ Test
50
+ void whenTextIsTabsAndSpacesThenThrow () {
51
+ assertThatThrownBy (() -> new Query ("\t \n \r " )).isInstanceOf (IllegalArgumentException .class )
52
+ .hasMessageContaining ("text cannot be null or empty" );
53
+ }
54
+
55
+ @ Test
56
+ void whenMultipleQueriesWithSameTextThenEqual () {
57
+ String text = "Same query text" ;
58
+ Query query1 = new Query (text );
59
+ Query query2 = new Query (text );
60
+
61
+ assertThat (query1 ).isEqualTo (query2 );
62
+ assertThat (query1 .hashCode ()).isEqualTo (query2 .hashCode ());
63
+ }
64
+
65
+ @ Test
66
+ void whenQueriesWithDifferentTextThenNotEqual () {
67
+ Query query1 = new Query ("First query" );
68
+ Query query2 = new Query ("Second query" );
69
+
70
+ assertThat (query1 ).isNotEqualTo (query2 );
71
+ assertThat (query1 .hashCode ()).isNotEqualTo (query2 .hashCode ());
72
+ }
73
+
74
+ @ Test
75
+ void whenCompareQueryToNullThenNotEqual () {
76
+ Query query = new Query ("Test query" );
77
+
78
+ assertThat (query ).isNotEqualTo (null );
79
+ }
80
+
42
81
}
0 commit comments