Skip to content

Commit e40b36f

Browse files
imetaxasimetaxas
imetaxas
authored and
imetaxas
committed
update readme
write better test method names
1 parent 352606b commit e40b36f

File tree

9 files changed

+89
-88
lines changed

9 files changed

+89
-88
lines changed

README.md

+27-4
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,51 @@ Reality Check is an open source Fluent Assertion framework for Java.
1010

1111
### Examples
1212

13+
#### Check files in system resources
14+
```
15+
Reality.checkThatSystemResource(csvResource.getName()).exists();
16+
Reality.checkThatSystemResource(csvResource1).hasSameContentAs(resource1);
17+
```
18+
#### Check CSV files in system resources
19+
```
20+
Reality.checkThatCsvResource(csvResource.getName()).exists();
21+
Reality.checkThatCsvResource(csvResource).doesNotExist();
22+
```
1323
#### Check files
1424
```
1525
Reality.checkThat(file).isNull();
1626
Reality.checkThat(file).hasSameContentAs(file);
27+
Reality.checkThatFile(filePath).exists();
1728
```
1829
#### Check CSV files
1930
```
20-
Reality.checkThatFileCsv(file1).hasSameContentAs(file2);
21-
Reality.checkThatFileCsv(file1).hasNotSameContentAs(file2);
31+
Reality.checkThatCsvFile(file1).hasSameContentAs(file1);
32+
Reality.checkThatCsvFile(file1).hasNotSameContentAs(file2);
33+
Reality.checkThatCsvFile(filename).headerHasNoDigits();
2234
```
2335
#### Check CSV strings
2436
```
25-
Reality.checkThatCsv(csvString1).hasSameContentAs(csvString2);
37+
Reality.checkThatCsv(csvString1).hasSameContentAs(csvString1);
2638
Reality.checkThatCsv(csvString1).hasNotSameContentAs(csvString2);
2739
```
2840
#### Check strings
2941
```
3042
Reality.checkThat(string).isNotNull();
3143
Reality.checkThat(string).hasLength(12);
3244
```
45+
#### Check integers
46+
```
47+
Reality.checkThat(1).isEqualTo(1);
48+
Reality.checkThat(1).isNotEqualTo(2);
49+
```
50+
#### Check booleans
51+
```
52+
Reality.checkThat(true).isTrue();
53+
Reality.checkThat(false).isFalse();
54+
```
3355
#### Check InputStreams
3456
```
35-
Reality.checkThat(new ByteArrayInputStream(byteArray1)).hasSameContentAs(new ByteArrayInputStream(byteArray2));
57+
Reality.checkThat(new ByteArrayInputStream(byteArray1)).hasSameContentAs(new ByteArrayInputStream(byteArray1));
3658
Reality.checkThat(new ByteArrayInputStream(byteArray1)).hasNotSameContentAs(new ByteArrayInputStream(byteArray2));
3759
```
3860
#### Check with custom message
@@ -41,6 +63,7 @@ Reality Check is an open source Fluent Assertion framework for Java.
4163
Reality.checkWithMessage("String has wrong length").that(string).hasLength(6);
4264
Reality.checkWithMessage("InputStream is NULL").that(new ByteArrayInputStream(byteArray)).isNotNull();
4365
Reality.checkWithMessage("Files have different content").thatCsvFile(file).hasSameContentAs(file);
66+
Reality.checkWithMessage("Boolean is false").that(true).isTrue();
4467
```
4568
#### Do multiple checks
4669
```

src/main/java/com/yanimetaxas/realitycheck/asserter/AbstractAssert.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,36 @@ public AbstractAssert(ACTUAL actual, String customMessage) {
2323
@Override
2424
public SELF isNull() {
2525
if (this.actual != null) {
26-
throwProperAssertionError("Subject is NULL");
26+
throwAssertionErrorWithCustomMessage("Subject is NULL");
2727
}
2828
return self;
2929
}
3030

3131
@Override
3232
public SELF isNotNull() {
3333
if (this.actual == null) {
34-
throwProperAssertionError("Subject is not NULL");
34+
throwAssertionErrorWithCustomMessage("Subject is not NULL");
3535
}
3636
return self;
3737
}
3838

3939
@Override
4040
public SELF isEqualTo(ACTUAL expected) {
4141
if (!this.actual.equals(expected)) {
42-
throwProperAssertionError("Subject is not equal");
42+
throwAssertionErrorWithCustomMessage("Subject is not equal");
4343
}
4444
return self;
4545
}
4646

4747
@Override
4848
public SELF isNotEqualTo(ACTUAL expected) {
4949
if (this.actual.equals(expected)) {
50-
throwProperAssertionError("Subject is equal");
50+
throwAssertionErrorWithCustomMessage("Subject is equal");
5151
}
5252
return self;
5353
}
5454

55-
void throwProperAssertionError(String defaultMessage) {
55+
void throwAssertionErrorWithCustomMessage(String defaultMessage) {
5656
if (customMessage == null) {
5757
throw new AssertionError(defaultMessage);
5858
} else {

src/main/java/com/yanimetaxas/realitycheck/asserter/AbstractReadableAssert.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ public AbstractReadableAssert(ACTUAL actual, String message, ValidationStrategy
3232

3333
public AbstractReadableAssert hasSameContentAs(InputStream expected) throws AssertionError {
3434
if(!IoUtil.contentEquals(new ByteArrayInputStream(getActualContent()), expected)){
35-
throwProperAssertionError("InputStreams are NOT exactly the same");
35+
throwAssertionErrorWithCustomMessage("InputStreams are NOT exactly the same");
3636
}
3737
return self;
3838
}
3939

4040
public AbstractReadableAssert hasNotSameContentAs(InputStream expected) throws AssertionError {
4141
if(IoUtil.contentEquals(new ByteArrayInputStream(getActualContent()), expected)){
42-
throwProperAssertionError("InputStreams are exactly the same");
42+
throwAssertionErrorWithCustomMessage("InputStreams are exactly the same");
4343
}
4444
return self;
4545
}

src/main/java/com/yanimetaxas/realitycheck/asserter/BooleanAssert.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ public BooleanAssert(Boolean aBoolean, String customMessage) {
1616

1717
public BooleanAssert isTrue() throws AssertionError {
1818
if(!actual) {
19-
throwProperAssertionError("Is false");
19+
throwAssertionErrorWithCustomMessage("Is false");
2020
}
2121
return self;
2222
}
2323

2424
public BooleanAssert isFalse() throws AssertionError {
2525
if(actual) {
26-
throwProperAssertionError("Is true");
26+
throwAssertionErrorWithCustomMessage("Is true");
2727
}
2828
return self;
2929
}

src/main/java/com/yanimetaxas/realitycheck/asserter/StringAssert.java

+13-13
Original file line numberDiff line numberDiff line change
@@ -15,91 +15,91 @@ public StringAssert(String string, String message) {
1515

1616
public StringAssert hasLength(int size) throws AssertionError {
1717
if(actual.length() != size) {
18-
throwProperAssertionError("Wrong length");
18+
throwAssertionErrorWithCustomMessage("Wrong length");
1919
}
2020
return self;
2121
}
2222

2323
public StringAssert equalsIgnoreCase(String expected) {
2424
if(!actual.equalsIgnoreCase(expected)) {
25-
throwProperAssertionError("Not equal");
25+
throwAssertionErrorWithCustomMessage("Not equal");
2626
}
2727
return self;
2828
}
2929

3030
public StringAssert doesNotEqualIgnoreCase(String expected) {
3131
if(actual.equalsIgnoreCase(expected)) {
32-
throwProperAssertionError("Equals");
32+
throwAssertionErrorWithCustomMessage("Equals");
3333
}
3434
return self;
3535
}
3636

3737
public StringAssert equals(String expected) {
3838
if(!actual.equals(expected)) {
39-
throwProperAssertionError("Not equal");
39+
throwAssertionErrorWithCustomMessage("Not equal");
4040
}
4141
return self;
4242
}
4343

4444
public StringAssert doesNotEqual(String expected) {
4545
if(actual.equals(expected)) {
46-
throwProperAssertionError("Equals");
46+
throwAssertionErrorWithCustomMessage("Equals");
4747
}
4848
return self;
4949
}
5050

5151
public StringAssert startsWith(String expected) {
5252
if(!actual.startsWith(expected)) {
53-
throwProperAssertionError("Not start with");
53+
throwAssertionErrorWithCustomMessage("Not start with");
5454
}
5555
return self;
5656
}
5757

5858
public StringAssert endsWith(String expected) {
5959
if(!actual.endsWith(expected)) {
60-
throwProperAssertionError("Not end with");
60+
throwAssertionErrorWithCustomMessage("Not end with");
6161
}
6262
return self;
6363
}
6464

6565
public StringAssert contains(String expected) {
6666
if(!actual.contains(expected)) {
67-
throwProperAssertionError("Is not contained");
67+
throwAssertionErrorWithCustomMessage("Is not contained");
6868
}
6969
return self;
7070
}
7171

7272
public StringAssert doesNotContain(String expected) {
7373
if(actual.contains(expected)) {
74-
throwProperAssertionError("Is contained");
74+
throwAssertionErrorWithCustomMessage("Is contained");
7575
}
7676
return self;
7777
}
7878

7979
public StringAssert isEmpty() {
8080
if(!actual.isEmpty()) {
81-
throwProperAssertionError("Is not empty");
81+
throwAssertionErrorWithCustomMessage("Is not empty");
8282
}
8383
return self;
8484
}
8585

8686
public StringAssert isNotEmpty() {
8787
if(actual.isEmpty()) {
88-
throwProperAssertionError("Is empty");
88+
throwAssertionErrorWithCustomMessage("Is empty");
8989
}
9090
return self;
9191
}
9292

9393
public StringAssert matches(String regex) {
9494
if(!actual.matches(regex)) {
95-
throwProperAssertionError("Regex not matched");
95+
throwAssertionErrorWithCustomMessage("Regex not matched");
9696
}
9797
return self;
9898
}
9999

100100
public StringAssert doesNotMatch(String regex) {
101101
if(actual.matches(regex)) {
102-
throwProperAssertionError("Regex matched");
102+
throwAssertionErrorWithCustomMessage("Regex matched");
103103
}
104104
return self;
105105
}

src/main/java/com/yanimetaxas/realitycheck/util/IoUtil.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ private static File isResourceDirectory(String filename) {
3232
if(dir.isDirectory()){
3333
return dir;
3434
}
35-
return null;
35+
return new File("");
3636
}
3737

3838
public static File toFile(String filepath) {

0 commit comments

Comments
 (0)