Skip to content

Commit 1ac8d25

Browse files
imetaxasimetaxas
imetaxas
authored and
imetaxas
committed
rename asserts to checks
move the checks outside their package
1 parent e82c660 commit 1ac8d25

File tree

66 files changed

+546
-598
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+546
-598
lines changed

pom.xml

+11-5
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44

55
<groupId>com.yanimetaxas</groupId>
66
<artifactId>realitycheck</artifactId>
7-
<version>0.5.8-SNAPSHOT</version>
7+
<version>0.5.9-SNAPSHOT</version>
88

99
<name>Reality Check</name>
1010
<url>https://github.com/imetaxas/realitycheck</url>
11+
<description>Fluent Java Code Test Checks.</description>
1112

1213
<scm>
1314
<url>https://github.com/imetaxas/realitycheck</url>
1415
<connection>scm:git:git@github.com:imetaxas/realitycheck.git</connection>
1516
<developerConnection>scm:git:git@github.com:imetaxas/realitycheck.git</developerConnection>
16-
<tag>realitycheck-0.5.8</tag>
17+
<tag>realitycheck-0.5.9</tag>
1718
</scm>
1819

1920
<issueManagement>
@@ -25,8 +26,6 @@
2526
<url>https://travis-ci.org/imetaxas/realitycheck</url>
2627
</ciManagement>
2728

28-
<description>https://github.com/imetaxas/realitycheck.git</description>
29-
3029
<parent>
3130
<groupId>org.sonatype.oss</groupId>
3231
<artifactId>oss-parent</artifactId>
@@ -41,17 +40,24 @@
4140
</license>
4241
</licenses>
4342

43+
<organization>
44+
<name>Yani (Ioannis) Metaxas</name>
45+
<url>http://yanimetaxas.com</url>
46+
</organization>
47+
4448
<developers>
4549
<developer>
4650
<id>imetaxas</id>
4751
<name>Yani (Ioannis) Metaxas</name>
4852
<email>imetaxas@gmail.com</email>
49-
<url>http://yanimetaxas.info</url>
53+
<url>http://yanimetaxas.com</url>
5054
<roles>
5155
<role>creator</role>
5256
<role>developer</role>
5357
</roles>
5458
<timezone>+1</timezone>
59+
<organization>Yani (Ioannis) Metaxas</organization>
60+
<organizationUrl>http://yanimetaxas.com</organizationUrl>
5561
</developer>
5662
</developers>
5763

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
package com.yanimetaxas.realitycheck.asserter;
1+
package com.yanimetaxas.realitycheck;
22

33
import com.yanimetaxas.realitycheck.util.GenericClass;
44
import java.util.Optional;
55

66
/**
77
* @author yanimetaxas
88
*/
9-
public abstract class AbstractAssert<SELF extends AbstractAssert<SELF, ACTUAL>, ACTUAL> implements
10-
Assertable<SELF, ACTUAL> {
9+
public abstract class AbstractCheck<SELF extends AbstractCheck<SELF, ACTUAL>, ACTUAL> implements
10+
Checkable<SELF, ACTUAL> {
1111

1212
final ACTUAL actual;
1313
final SELF self;
1414
final String customMessage;
1515

16-
public AbstractAssert(ACTUAL actual, String customMessage) {
16+
AbstractCheck(ACTUAL actual, String customMessage) {
1717
GenericClass<SELF> genericClass = new GenericClass(getClass());
1818
self = genericClass.getType().cast(this);
1919
this.actual = actual;

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

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package com.yanimetaxas.realitycheck.asserter;
1+
package com.yanimetaxas.realitycheck;
22

33
import com.yanimetaxas.realitycheck.exception.ValidationException;
4-
import com.yanimetaxas.realitycheck.strategy.validation.ValidationStrategy;
4+
import com.yanimetaxas.realitycheck.strategy.ValidationStrategy;
55
import com.yanimetaxas.realitycheck.util.IoUtil;
66
import java.io.ByteArrayInputStream;
77
import java.io.InputStream;
@@ -13,31 +13,32 @@
1313
/**
1414
* @author yanimetaxas
1515
*/
16-
public abstract class AbstractReadableAssert<SELF extends AbstractReadableAssert<SELF, ACTUAL, STRATEGY>, ACTUAL, STRATEGY> extends AbstractAssert<SELF, ACTUAL> {
16+
public abstract class AbstractReadableCheck<SELF extends AbstractReadableCheck<SELF, ACTUAL, STRATEGY>, ACTUAL, STRATEGY> extends
17+
AbstractCheck<SELF, ACTUAL> {
1718

1819
private final byte[] actualContent;
1920
private final ValidationStrategy validationStrategy;
2021

21-
public AbstractReadableAssert(ACTUAL actual, String message) throws AssertionError {
22+
AbstractReadableCheck(ACTUAL actual, String message) throws AssertionError {
2223
super(actual, message);
2324
this.validationStrategy = getValidationStrategyFromType();
2425
this.actualContent = validateAndRead();
2526
}
2627

27-
public AbstractReadableAssert(ACTUAL actual, String message, ValidationStrategy strategy) throws AssertionError {
28+
AbstractReadableCheck(ACTUAL actual, String message, ValidationStrategy strategy) throws AssertionError {
2829
super(actual, message);
2930
this.validationStrategy = strategy;
3031
this.actualContent = validateAndRead();
3132
}
3233

33-
public AbstractReadableAssert hasSameContentAs(InputStream expected) throws AssertionError {
34+
AbstractReadableCheck hasSameContentAs(InputStream expected) throws AssertionError {
3435
if(!IoUtil.contentEquals(new ByteArrayInputStream(getActualContent()), expected)){
3536
throwAssertionErrorWithCustomMessage("InputStreams are NOT exactly the same");
3637
}
3738
return self;
3839
}
3940

40-
public AbstractReadableAssert hasNotSameContentAs(InputStream expected) throws AssertionError {
41+
AbstractReadableCheck hasNotSameContentAs(InputStream expected) throws AssertionError {
4142
if(IoUtil.contentEquals(new ByteArrayInputStream(getActualContent()), expected)){
4243
throwAssertionErrorWithCustomMessage("InputStreams are exactly the same");
4344
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.yanimetaxas.realitycheck;
2+
3+
/**
4+
* @author yanimetaxas
5+
* @since 18-Feb-18
6+
*/
7+
public final class BooleanCheck extends AbstractCheck<BooleanCheck, Boolean> {
8+
9+
BooleanCheck(Boolean aBoolean) {
10+
super(aBoolean, null);
11+
}
12+
13+
BooleanCheck(Boolean aBoolean, String customMessage) {
14+
super(aBoolean, customMessage);
15+
}
16+
17+
public BooleanCheck isTrue() throws AssertionError {
18+
if(!actual) {
19+
throwAssertionErrorWithCustomMessage("Is false");
20+
}
21+
return self;
22+
}
23+
24+
public BooleanCheck isFalse() throws AssertionError {
25+
if(actual) {
26+
throwAssertionErrorWithCustomMessage("Is true");
27+
}
28+
return self;
29+
}
30+
}

src/main/java/com/yanimetaxas/realitycheck/asserter/Assertable.java src/main/java/com/yanimetaxas/realitycheck/Checkable.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package com.yanimetaxas.realitycheck.asserter;
1+
package com.yanimetaxas.realitycheck;
22

33
/**
44
* @author yanimetaxas
55
*/
6-
public interface Assertable<SELF extends Assertable<SELF, ACTUAL>, ACTUAL> {
6+
interface Checkable<SELF extends Checkable<SELF, ACTUAL>, ACTUAL> {
77

88
SELF isNull();
99

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.yanimetaxas.realitycheck;
2+
3+
import com.yanimetaxas.realitycheck.exception.ValidationException;
4+
import com.yanimetaxas.realitycheck.strategy.CsvValidationStrategy;
5+
import com.yanimetaxas.realitycheck.util.IoUtil;
6+
import java.io.ByteArrayInputStream;
7+
8+
/**
9+
* @author yanimetaxas
10+
*/
11+
public final class CsvCheck extends
12+
AbstractReadableCheck<CsvCheck, String, CsvValidationStrategy> {
13+
14+
CsvCheck(String csv, String message) throws AssertionError {
15+
super(csv, message);
16+
}
17+
18+
CsvCheck hasSameContentAs(String expected) throws AssertionError {
19+
return (CsvCheck) super.hasSameContentAs(new ByteArrayInputStream(expected.getBytes()));
20+
}
21+
22+
public CsvCheck hasNotSameContentAs(String expected) throws AssertionError {
23+
return (CsvCheck) super.hasNotSameContentAs(new ByteArrayInputStream(expected.getBytes()));
24+
}
25+
26+
public CsvCheck headerHasNoDigits() throws AssertionError {
27+
try {
28+
String headers = IoUtil.readFirstLine(getActualContent());
29+
for(String header: headers.split(",")) {
30+
if (header.matches("[0-9]+")) {
31+
throw new ValidationException("Header has digits");
32+
}
33+
}
34+
} catch (Exception e) {
35+
throw new AssertionError(e);
36+
}
37+
return this;
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.yanimetaxas.realitycheck;
2+
3+
import com.yanimetaxas.realitycheck.strategy.CsvFileValidationStrategy;
4+
import com.yanimetaxas.realitycheck.strategy.CsvFilenameValidationStrategy;
5+
import com.yanimetaxas.realitycheck.util.IoUtil;
6+
import java.io.File;
7+
8+
/**
9+
* @author yanimetaxas
10+
*/
11+
public class CsvFileCheck extends FileCheck {
12+
13+
private CsvCheck csvCheck;
14+
15+
CsvFileCheck(String filepath, String message) throws AssertionError {
16+
super(IoUtil.toFile(filepath), message, new CsvFilenameValidationStrategy(filepath));
17+
}
18+
19+
CsvFileCheck(File csvFile, String message) throws AssertionError {
20+
super(csvFile, message, new CsvFileValidationStrategy(csvFile));
21+
csvCheck = new CsvCheck(new String(getActualContent()), message);
22+
}
23+
24+
public CsvCheck headerHasNoDigits() throws AssertionError {
25+
return csvCheck.headerHasNoDigits();
26+
}
27+
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.yanimetaxas.realitycheck;
2+
3+
import com.yanimetaxas.realitycheck.util.IoUtil;
4+
import java.io.File;
5+
6+
/**
7+
* @author yanimetaxas
8+
* @since 17-Feb-18
9+
*/
10+
public final class CsvResourceCheck extends CsvFileCheck {
11+
12+
CsvResourceCheck(String filename, String message) throws AssertionError {
13+
super(IoUtil.loadResource(filename), message);
14+
}
15+
16+
CsvResourceCheck(File file, String message) throws AssertionError {
17+
super(file, message);
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.yanimetaxas.realitycheck;
2+
3+
import com.yanimetaxas.realitycheck.custom.CustomObject;
4+
import com.yanimetaxas.realitycheck.exception.ValidationException;
5+
6+
/**
7+
* @author yanimetaxas
8+
* @since 18-Feb-18
9+
*/
10+
public final class CustomObjectCheck extends AbstractCheck<CustomObjectCheck, CustomObject> {
11+
12+
public CustomObjectCheck(CustomObject customObject) throws ValidationException {
13+
super(customObject, null);
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.yanimetaxas.realitycheck;
2+
3+
import com.yanimetaxas.realitycheck.custom.CustomReadableObject;
4+
import com.yanimetaxas.realitycheck.exception.ValidationException;
5+
import com.yanimetaxas.realitycheck.strategy.CustomReadableObjectValidationStrategy;
6+
7+
/**
8+
* @author yanimetaxas
9+
*/
10+
public final class CustomReadableObjectCheck extends
11+
AbstractReadableCheck<CustomReadableObjectCheck, CustomReadableObject, CustomReadableObjectValidationStrategy> {
12+
13+
public CustomReadableObjectCheck(CustomReadableObject customReadableObject) throws ValidationException {
14+
super(customReadableObject, null);
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,86 @@
1-
package com.yanimetaxas.realitycheck.asserter;
1+
package com.yanimetaxas.realitycheck;
22

3-
import com.yanimetaxas.realitycheck.strategy.validation.FileValidationStrategy;
4-
import com.yanimetaxas.realitycheck.strategy.validation.FilepathValidationStrategy;
5-
import com.yanimetaxas.realitycheck.strategy.validation.ValidationStrategy;
3+
import com.yanimetaxas.realitycheck.strategy.FileValidationStrategy;
4+
import com.yanimetaxas.realitycheck.strategy.FilepathValidationStrategy;
5+
import com.yanimetaxas.realitycheck.strategy.ValidationStrategy;
66
import com.yanimetaxas.realitycheck.util.IoUtil;
77
import java.io.ByteArrayInputStream;
88
import java.io.File;
99

1010
/**
1111
* @author yanimetaxas
1212
*/
13-
public class FileAssert extends AbstractReadableAssert<FileAssert, File, FileValidationStrategy> {
13+
public class FileCheck extends AbstractReadableCheck<FileCheck, File, FileValidationStrategy> {
1414

15-
16-
public FileAssert(String filepath, String message) throws AssertionError {
15+
FileCheck(String filepath, String message) throws AssertionError {
1716
super(IoUtil.toFile(filepath), message, new FilepathValidationStrategy(filepath));
1817
}
1918

20-
public FileAssert(File file, String message) throws AssertionError {
19+
FileCheck(File file, String message) throws AssertionError {
2120
super(file, message);
2221
}
2322

24-
public FileAssert(File file, String message, ValidationStrategy strategy) throws AssertionError {
23+
FileCheck(File file, String message, ValidationStrategy strategy) throws AssertionError {
2524
super(file, message, strategy);
2625
}
2726

28-
public FileAssert exists() {
27+
public FileCheck exists() {
2928
if (!getActual().exists()) {
3029
throw new AssertionError("File " + actual.getName() + " doesn't exist");
3130
}
3231
return self;
3332
}
3433

35-
public FileAssert doesNotExist() {
34+
public FileCheck doesNotExist() {
3635
if (getActual().exists()) {
3736
throw new AssertionError("File " + actual.getName() + " exists");
3837
}
3938
return self;
4039
}
4140

42-
public FileAssert isDirectory() {
41+
public FileCheck isDirectory() {
4342
if (!getActual().isDirectory()) {
4443
throw new AssertionError("File " + actual.getName() + " is NOT directory");
4544
}
4645
return self;
4746
}
4847

49-
public FileAssert isNotDirectory() {
48+
public FileCheck isNotDirectory() {
5049
if (getActual().isDirectory()) {
5150
throw new AssertionError("File " + actual.getName() + " is directory");
5251
}
5352
return self;
5453
}
5554

56-
public FileAssert isHidden() {
55+
public FileCheck isHidden() {
5756
if (!getActual().isHidden()) {
5857
throw new AssertionError("File " + actual.getName() + " is NOT hidden");
5958
}
6059
return self;
6160
}
6261

63-
public FileAssert isNotHidden() {
62+
public FileCheck isNotHidden() {
6463
if (getActual().isHidden()) {
6564
throw new AssertionError("File " + actual.getName() + " is hidden");
6665
}
6766
return self;
6867
}
6968

70-
public FileAssert hasSameContentAs(String filepath) throws AssertionError {
69+
public FileCheck hasSameContentAs(String filepath) throws AssertionError {
7170
return hasSameContentAs(IoUtil.toFile(filepath));
7271
}
7372

74-
public FileAssert hasSameContentAs(File file) throws AssertionError {
75-
return (FileAssert) super
73+
public FileCheck hasSameContentAs(File file) throws AssertionError {
74+
return (FileCheck) super
7675
.hasSameContentAs(new ByteArrayInputStream(IoUtil.readFile(file.getAbsolutePath())));
7776
}
7877

79-
public FileAssert hasNotSameContentAs(File file) throws AssertionError {
80-
return (FileAssert) super
78+
public FileCheck hasNotSameContentAs(File file) throws AssertionError {
79+
return (FileCheck) super
8180
.hasNotSameContentAs(new ByteArrayInputStream(IoUtil.readFile(file.getAbsolutePath())));
8281
}
8382

84-
public FileAssert hasNotSameContentAs(String filepath) throws AssertionError {
83+
public FileCheck hasNotSameContentAs(String filepath) throws AssertionError {
8584
return hasNotSameContentAs(IoUtil.toFile(filepath));
8685
}
8786
}

0 commit comments

Comments
 (0)