Skip to content

Commit

Permalink
More tests to fix #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Suszyński Krzysztof committed Mar 29, 2016
1 parent d304268 commit baf45e1
Show file tree
Hide file tree
Showing 2 changed files with 260 additions and 32 deletions.
62 changes: 38 additions & 24 deletions src/main/java/pl/wavesoftware/eid/utils/EidPreconditions.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ protected EidPreconditions() {
*/
public static void checkArgument(final boolean expression, final String eid) {
if (!expression) {
throw new EidIllegalArgumentException(new Eid(eid));
throw new EidIllegalArgumentException(ensureEid(eid));
}
}

Expand All @@ -139,7 +139,7 @@ public static void checkArgument(final boolean expression, final String eid) {
public static void checkArgument(final boolean expression, final String eid,
final String messageFormat, final Object... parameters) {
if (!expression) {
throw new EidIllegalArgumentException(new Eid(eid), messageFormat, parameters);
throw new EidIllegalArgumentException(ensureEid(eid), messageFormat, parameters);
}
}

Expand All @@ -153,7 +153,7 @@ public static void checkArgument(final boolean expression, final String eid,
*/
public static void checkArgument(final boolean expression, final Eid eid) {
if (!expression) {
throw new EidIllegalArgumentException(eid);
throw new EidIllegalArgumentException(ensureEid(eid));
}
}

Expand All @@ -170,7 +170,7 @@ public static void checkArgument(final boolean expression, final Eid eid) {
public static void checkArgument(final boolean expression, final Eid eid,
final String messageFormat, final Object... parameters) {
if (!expression) {
throw new EidIllegalArgumentException(eid, messageFormat, parameters);
throw new EidIllegalArgumentException(ensureEid(eid), messageFormat, parameters);
}
}

Expand All @@ -185,7 +185,7 @@ public static void checkArgument(final boolean expression, final Eid eid,
*/
public static void checkState(final boolean expression, final String eid) {
if (!expression) {
throw new EidIllegalStateException(new Eid(eid));
throw new EidIllegalStateException(ensureEid(eid));
}
}

Expand All @@ -203,7 +203,7 @@ public static void checkState(final boolean expression, final String eid) {
public static void checkState(final boolean expression, final String eid,
final String messageFormat, final Object... parameters) {
if (!expression) {
throw new EidIllegalStateException(new Eid(eid), messageFormat, parameters);
throw new EidIllegalStateException(ensureEid(eid), messageFormat, parameters);
}
}

Expand All @@ -218,7 +218,7 @@ public static void checkState(final boolean expression, final String eid,
*/
public static void checkState(final Boolean expression, final Eid eid) {
if (!expression) {
throw new EidIllegalStateException(eid);
throw new EidIllegalStateException(ensureEid(eid));
}
}

Expand All @@ -236,7 +236,7 @@ public static void checkState(final Boolean expression, final Eid eid) {
public static void checkState(final boolean expression, final Eid eid,
final String messageFormat, final Object... parameters) {
if (!expression) {
throw new EidIllegalStateException(eid, messageFormat, parameters);
throw new EidIllegalStateException(ensureEid(eid), messageFormat, parameters);
}
}

Expand All @@ -252,7 +252,7 @@ public static void checkState(final boolean expression, final Eid eid,
*/
public static <T> T checkNotNull(@Nullable final T reference, final String eid) {
if (reference == null) {
throw new EidNullPointerException(new Eid(eid));
throw new EidNullPointerException(ensureEid(eid));
}
return reference;
}
Expand All @@ -272,7 +272,7 @@ public static <T> T checkNotNull(@Nullable final T reference, final String eid)
public static <T> T checkNotNull(@Nullable final T reference, final String eid,
final String messageFormat, final Object... parameters) {
if (reference == null) {
throw new EidNullPointerException(new Eid(eid), messageFormat, parameters);
throw new EidNullPointerException(ensureEid(eid), messageFormat, parameters);
}
return reference;
}
Expand All @@ -289,7 +289,7 @@ public static <T> T checkNotNull(@Nullable final T reference, final String eid,
*/
public static <T> T checkNotNull(@Nullable final T reference, final Eid eid) {
if (reference == null) {
throw new EidNullPointerException(eid);
throw new EidNullPointerException(ensureEid(eid));
}
return reference;
}
Expand All @@ -310,7 +310,7 @@ public static <T> T checkNotNull(@Nullable final T reference, final Eid eid) {
public static <T> T checkNotNull(@Nullable final T reference, final Eid eid,
final String messageFormat, final Object... parameters) {
if (reference == null) {
throw new EidNullPointerException(eid, messageFormat, parameters);
throw new EidNullPointerException(ensureEid(eid), messageFormat, parameters);
}
return reference;
}
Expand All @@ -328,10 +328,10 @@ public static <T> T checkNotNull(@Nullable final T reference, final Eid eid,
*/
public static int checkElementIndex(int index, int size, final String eid) {
if (isSizeIllegal(size)) {
throw new EidIllegalArgumentException(new Eid(eid));
throw new EidIllegalArgumentException(ensureEid(eid));
}
if (isIndexAndSizeIllegal(index, size)) {
throw new EidIndexOutOfBoundsException(new Eid(eid));
throw new EidIndexOutOfBoundsException(ensureEid(eid));
}
return index;
}
Expand All @@ -352,10 +352,10 @@ public static int checkElementIndex(int index, int size, final String eid) {
public static int checkElementIndex(int index, int size, final String eid,
final String messageFormat, final Object... parameters) {
if (isSizeIllegal(size)) {
throw new EidIllegalArgumentException(new Eid(eid), messageFormat, parameters);
throw new EidIllegalArgumentException(ensureEid(eid), messageFormat, parameters);
}
if (isIndexAndSizeIllegal(index, size)) {
throw new EidIndexOutOfBoundsException(new Eid(eid), messageFormat, parameters);
throw new EidIndexOutOfBoundsException(ensureEid(eid), messageFormat, parameters);
}
return index;
}
Expand All @@ -373,10 +373,10 @@ public static int checkElementIndex(int index, int size, final String eid,
*/
public static int checkElementIndex(int index, int size, final Eid eid) {
if (isSizeIllegal(size)) {
throw new EidIllegalArgumentException(eid);
throw new EidIllegalArgumentException(ensureEid(eid));
}
if (isIndexAndSizeIllegal(index, size)) {
throw new EidIndexOutOfBoundsException(eid);
throw new EidIndexOutOfBoundsException(ensureEid(eid));
}
return index;
}
Expand All @@ -397,10 +397,10 @@ public static int checkElementIndex(int index, int size, final Eid eid) {
public static int checkElementIndex(int index, int size, final Eid eid, final String messageFormat,
final Object... parameters) {
if (isSizeIllegal(size)) {
throw new EidIllegalArgumentException(eid, messageFormat, parameters);
throw new EidIllegalArgumentException(ensureEid(eid), messageFormat, parameters);
}
if (isIndexAndSizeIllegal(index, size)) {
throw new EidIndexOutOfBoundsException(eid, messageFormat, parameters);
throw new EidIndexOutOfBoundsException(ensureEid(eid), messageFormat, parameters);
}
return index;
}
Expand All @@ -427,7 +427,7 @@ public static <R> R tryToExecute(final UnsafeSupplier<R> supplier, final String
try {
return supplier.get();
} catch (Exception throwable) {
throw new EidRuntimeException(new Eid(eid), throwable);
throw new EidRuntimeException(ensureEid(eid), throwable);
}
}

Expand All @@ -443,7 +443,7 @@ public static void tryToExecute(final UnsafeProcedure procedure, final String ei
try {
procedure.execute();
} catch (Exception throwable) {
throw new EidRuntimeException(new Eid(eid), throwable);
throw new EidRuntimeException(ensureEid(eid), throwable);
}
}

Expand Down Expand Up @@ -473,7 +473,7 @@ public static <R> R tryToExecute(final UnsafeSupplier<R> supplier, final Eid eid
try {
return supplier.get();
} catch (Exception throwable) {
throw new EidRuntimeException(eid, throwable);
throw new EidRuntimeException(ensureEid(eid), throwable);
}
}

Expand All @@ -500,7 +500,7 @@ public static void tryToExecute(final UnsafeProcedure procedure, final Eid eid)
try {
procedure.execute();
} catch (Exception throwable) {
throw new EidRuntimeException(eid, throwable);
throw new EidRuntimeException(ensureEid(eid), throwable);
}
}

Expand Down Expand Up @@ -536,4 +536,18 @@ public interface UnsafeProcedure {
*/
void execute() throws Exception;
}

private static Eid ensureEid(@Nullable Eid eid) {
if (eid == null) {
return new Eid("20160329:132823", "EID-NULL");
}
return eid;
}

private static Eid ensureEid(@Nullable String eid) {
if (eid == null) {
return new Eid("20160329:133052", "EID-NULL");
}
return new Eid(eid);
}
}
Loading

0 comments on commit baf45e1

Please sign in to comment.