Skip to content

Commit

Permalink
better error messge
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Oct 28, 2024
1 parent af8a4bd commit 2c9a15e
Show file tree
Hide file tree
Showing 88 changed files with 305 additions and 308 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/cactoos/Fallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public int support(final Throwable exception) {
}

@Override
public X apply(final Throwable input) throws Exception {
public X apply(final Throwable input) {
throw new IllegalStateException(input);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/cactoos/io/CloseShieldInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public int read(final byte[] buffer, final int offset,
}

@Override
public void close() throws IOException {
public void close() {
this.inner.set(new DeadInputStream());
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/cactoos/io/CloseShieldOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void flush() throws IOException {
}

@Override
public void close() throws IOException {
public void close() {
this.inner.set(new DeadOutputStream());
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/cactoos/io/HeadInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public final class HeadInputStream extends InputStream {
public HeadInputStream(final InputStream orig, final int len) {
super();
this.origin = orig;
this.length = len;
this.length = (long) len;
}

@Override
Expand All @@ -67,7 +67,7 @@ public int read() throws IOException {
if (this.processed >= this.length) {
adjusted = -1;
} else {
this.processed += 1;
this.processed += 1L;
adjusted = this.origin.read();
}
return adjusted;
Expand Down Expand Up @@ -96,7 +96,7 @@ public void reset() throws IOException {
public int available() throws IOException {
final int available = this.origin.available();
final int adjusted;
if (this.processed + available > this.length) {
if (this.processed + (long) available > this.length) {
adjusted = (int) (this.length - this.processed);
} else {
adjusted = available;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/cactoos/io/LoggingInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public int read(final byte[] buf, final int offset, final int len)
final int byts = this.origin.read(buf, offset, len);
final Instant end = Instant.now();
if (byts > 0) {
this.bytes.getAndAdd(byts);
this.bytes.getAndAdd((long) byts);
final long millis = Duration.between(start, end).toMillis();
this.time.getAndAdd(millis);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/cactoos/io/LoggingOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void write(final byte[] buf, final int offset,
final Instant start = Instant.now();
this.origin.write(buf, offset, len);
final Instant end = Instant.now();
this.bytes.getAndAdd(len);
this.bytes.getAndAdd((long) len);
final long millis = Duration.between(start, end).toMillis();
this.time.getAndAdd(millis);
final Level level = this.logger.getLevel();
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/cactoos/io/ResourceOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,10 @@ public ResourceOf(final Text res, final ClassLoader ldr) {
input -> {
throw new IOException(
new FormattedText(
"The resource \"%s\" was not found in %s",
"The resource \"%s\" was not found in %s (%s)",
input,
ldr
ldr,
ldr.getClass().getCanonicalName()
).asString()
);
},
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/cactoos/number/AvgOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ public AvgOf(final Iterable<? extends Number> src) {
(Iterator<? extends Number> it) -> it.hasNext(),
it -> {
BigDecimal total = BigDecimal.ZERO;
long qty = 0;
long qty = 0L;
for (final Number value: new IterableOf<>(it)) {
qty += 1;
qty += 1L;
total = total.add(
new BigDecimal(value.toString())
);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/cactoos/scalar/Equality.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public Integer value() throws Exception {
() -> {
int result = 0;
for (int idx = rght.length - 1; idx >= 0; --idx) {
result = lft[idx] - rght[idx];
result = (int) lft[idx] - (int) rght[idx];
if (result != 0) {
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/cactoos/scalar/LengthOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public final class LengthOf extends ScalarEnvelope<Long> {
public LengthOf(final Iterable<?> items) {
this(() -> {
final Iterator<?> iterator = items.iterator();
long size = 0;
long size = 0L;
while (iterator.hasNext()) {
iterator.next();
++size;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/cactoos/text/Abbreviated.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public Abbreviated(final Text text, final int max) {
new Flattened(
new Ternary<>(
new ScalarOf<>(() -> new Sticky(text)),
(Text t) -> new LengthOf(t).value() <= max,
(Text t) -> new LengthOf(t).value() <= (long) max,
t -> t,
t -> new FormattedText(
"%s%s",
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/cactoos/text/HexOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public HexOf(final Bytes bytes) {
final char[] hex = new char[bts.length * 2];
int chr = -1;
for (final byte byt: bts) {
final int value = 0xff & byt;
final int value = 0xff & (int) byt;
hex[++chr] = HexOf.HEX_CHARS[value >>> 4];
hex[++chr] = HexOf.HEX_CHARS[value & 0x0f];
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/cactoos/text/TextOfString.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public TextOfString(final String input) {
}

@Override
public String asString() throws Exception {
public String asString() {
return this.input;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/cactoos/time/DateOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public DateOf(final CharSequence date, final DateTimeFormatter formatter) {
date,
new DateTimeFormatterBuilder()
.append(formatter)
.parseDefaulting(ChronoField.HOUR_OF_DAY, 0)
.parseDefaulting(ChronoField.HOUR_OF_DAY, 0L)
.toFormatter()
).toInstant(ZoneOffset.UTC)
)
Expand Down
6 changes: 2 additions & 4 deletions src/test/java/org/cactoos/bytes/EmptyClosableReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
package org.cactoos.bytes;

import java.io.IOException;
import java.io.Reader;
import org.cactoos.io.ReaderOf;

Expand All @@ -46,13 +45,12 @@ final class EmptyClosableReader extends Reader {
private boolean closed;

@Override
public int read(final char[] cbuf, final int off, final int len)
throws IOException {
public int read(final char[] cbuf, final int off, final int len) {
return -1;
}

@Override
public void close() throws IOException {
public void close() {
this.closed = true;
}

Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/cactoos/bytes/HexOfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void emptyText() throws Exception {
void validHex() throws Exception {
final byte[] bytes = new byte[256];
for (int index = 0; index < 256; ++index) {
bytes[index] = (byte) (index + Byte.MIN_VALUE);
bytes[index] = (byte) (index + (int) Byte.MIN_VALUE);
}
new Assertion<>(
"Must convert hexadecimal text to bytes",
Expand All @@ -67,7 +67,7 @@ void validHex() throws Exception {
}

@Test
void invalidHexLength() throws Exception {
void invalidHexLength() {
new Assertion<>(
"Must invalid hex length",
() -> new HexOf(new TextOf("ABF")).asBytes(),
Expand All @@ -79,7 +79,7 @@ void invalidHexLength() throws Exception {
}

@Test
void invalidHex() throws Exception {
void invalidHex() {
new Assertion<>(
"Must invalid hex",
() -> new HexOf(new TextOf("ABG!")).asBytes(),
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/cactoos/bytes/InputAsBytesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void readsLargeContent() throws Exception {
}

@Test
void readsInputIntoBytes() throws Exception {
void readsInputIntoBytes() {
new Assertion<>(
"must read bytes from Input",
new TextOf(
Expand All @@ -103,7 +103,7 @@ void readsInputIntoBytes() throws Exception {
}

@Test
void readsInputIntoBytesWithSmallBuffer() throws Exception {
void readsInputIntoBytesWithSmallBuffer() {
new Assertion<>(
"must read bytes from Input with a small reading buffer",
new TextOf(
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/cactoos/bytes/ReaderAsBytesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
final class ReaderAsBytesTest {

@Test
void readsString() throws Exception {
void readsString() {
final String source = "hello, друг!";
new Assertion<>(
"Must read string through a reader",
Expand Down
38 changes: 19 additions & 19 deletions src/test/java/org/cactoos/experimental/ThreadsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
*
* @since 1.0.0
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
@SuppressWarnings({ "PMD.AvoidDuplicateLiterals", "PMD.CloseResource" })
final class ThreadsTest {

/**
Expand All @@ -55,14 +55,14 @@ final class ThreadsTest {
* {@link ExecutorService} was initiated by someone else.
*/
@RepeatedTest(ThreadsTest.REPETITIONS)
void containsResults() throws Exception {
void containsResults() {
final ExecutorService extor = Executors.newFixedThreadPool(3);
try {
new Assertion<>(
"Must contain results from callables",
new Threads<String>(
new Threads<>(
extor,
Duration.ofSeconds(1),
Duration.ofSeconds(1L),
() -> {
this.sleep();
return "txt 1";
Expand Down Expand Up @@ -92,15 +92,15 @@ void containsResults() throws Exception {
* {@link ExecutorService} was initiated by someone else.
*/
@RepeatedTest(ThreadsTest.REPETITIONS)
void failsDueToTimeoutWithExternalExecutorService() throws Exception {
void failsDueToTimeoutWithExternalExecutorService() {
final ExecutorService extor = Executors.newFixedThreadPool(2);
try {
new Assertion<>(
"Must fail due to timeout",
() -> new LengthOf(
new Threads<String>(
new Threads<>(
extor,
Duration.ofMillis(1),
Duration.ofMillis(1L),
() -> {
this.sleep();
return "txt 1";
Expand Down Expand Up @@ -133,9 +133,9 @@ void failsDueToException() {
new Assertion<>(
"Must rethrow error",
() -> new LengthOf(
new Threads<String>(
new Threads<>(
extor,
Duration.ofSeconds(1),
Duration.ofSeconds(1L),
() -> {
this.sleep();
return "txt 1";
Expand All @@ -162,12 +162,12 @@ void failsDueToException() {
* {@link ExecutorService} was initiated by {@link Threads} itself.
*/
@RepeatedTest(ThreadsTest.REPETITIONS)
void containsValuesWithInlineExecutorService() throws Exception {
void containsValuesWithInlineExecutorService() {
new Assertion<>(
"Must contain results from the callables when using inline executor service",
new Threads<String>(
new Threads<>(
3,
Duration.ofSeconds(1),
Duration.ofSeconds(1L),
() -> {
this.sleep();
return "txt 1";
Expand All @@ -190,13 +190,13 @@ void containsValuesWithInlineExecutorService() throws Exception {
* {@link ExecutorService} was initiated by {@link Threads} itself.
*/
@RepeatedTest(ThreadsTest.REPETITIONS)
void failsDueToTimeoutWithInlineExecutorService() throws Exception {
void failsDueToTimeoutWithInlineExecutorService() {
new Assertion<>(
"Must fail due to timeout",
() -> new LengthOf(
new Threads<String>(
new Threads<>(
2,
Duration.ofMillis(1),
Duration.ofMillis(1L),
() -> {
this.sleep();
return "txt 1";
Expand All @@ -220,12 +220,12 @@ void failsDueToTimeoutWithInlineExecutorService() throws Exception {
* {@link ExecutorService} was initiated by someone else.
*/
@RepeatedTest(ThreadsTest.REPETITIONS)
void containsResultsNoTimeout() throws Exception {
void containsResultsNoTimeout() {
final ExecutorService extor = Executors.newFixedThreadPool(3);
try {
new Assertion<>(
"Must contain results from the callables without using timeout",
new Threads<String>(
new Threads<>(
extor,
() -> {
this.sleep();
Expand Down Expand Up @@ -258,7 +258,7 @@ void failsDueToExceptionNoTimeout() {
new Assertion<>(
"Must rethrow error",
() -> new LengthOf(
new Threads<String>(
new Threads<>(
extor,
() -> {
this.sleep();
Expand Down Expand Up @@ -289,7 +289,7 @@ void failsDueToExceptionNoTimeout() {
void containsValuesWithInlineExecutorServiceNoTimeout() {
new Assertion<>(
"Must contain results from the callables when using inline executor without timeout",
new Threads<String>(
new Threads<>(
3,
() -> {
this.sleep();
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/cactoos/func/AsyncTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void runsInBackgroundWithThreadFactory() {
new Satisfies<>(
future -> {
future.get();
return latch.getCount() == 0;
return latch.getCount() == 0L;
}
)
)
Expand Down Expand Up @@ -153,7 +153,7 @@ void runsInBackgroundWithExecutorService() {
new Satisfies<>(
future -> {
future.get();
return latch.getCount() == 0;
return latch.getCount() == 0L;
}
)
)
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/cactoos/func/BiFuncOfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
final class BiFuncOfTest {

@Test
void convertsFuncIntoBiFunc() throws Exception {
void convertsFuncIntoBiFunc() {
new Assertion<>(
"Must convert function into bi-function",
new BiFuncOf<>(
Expand All @@ -58,7 +58,7 @@ void convertsFuncIntoBiFunc() throws Exception {
}

@Test
void convertsProcIntoBiFunc() throws Exception {
void convertsProcIntoBiFunc() {
final AtomicReference<Object> done = new AtomicReference<>();
final Object result = new Object();
new Assertion<>(
Expand Down Expand Up @@ -90,7 +90,7 @@ void convertsScalarIntoBiFunc() throws Exception {
}

@Test
void convertsLambdaIntoBiFunc() throws Exception {
void convertsLambdaIntoBiFunc() {
new Assertion<>(
"Must convert lambda into bi-function",
new BiFuncOf<>((first, second) -> new Object[] {first, second}),
Expand Down
Loading

0 comments on commit 2c9a15e

Please sign in to comment.