Skip to content

Commit

Permalink
#2863 replace anonymous class by single implementation to reduce code…
Browse files Browse the repository at this point in the history
… duplicatoin
  • Loading branch information
c71n93 committed Mar 5, 2024
1 parent 67d14ee commit 85ce4c3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/simian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ jobs:
- run: |
wget --quiet http://public.yegor256.com/simian.jar -O /tmp/simian.jar
- run: |
java -jar /tmp/simian.jar -threshold=25 -excludes=**/gen -excludes=**/it **/*.java
java -jar /tmp/simian.jar -threshold=16 -excludes=**/gen -excludes=**/it **/*.java
92 changes: 28 additions & 64 deletions eo-runtime/src/test/java/org/eolang/DataizedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,7 @@ void logsCorrectly() {
final Level before = log.getLevel();
log.setLevel(Level.ALL);
final List<LogRecord> logs = new LinkedList<>();
final Handler hnd = new Handler() {
@Override
public void publish(final LogRecord record) {
logs.add(record);
}

@Override
public void flush() {
throw new UnsupportedOperationException("#flush()");
}

@Override
public void close() throws SecurityException {
throw new UnsupportedOperationException("#close()");
}
};
final Handler hnd = new TestHandler(logs);
log.addHandler(hnd);
new Dataized(new Data.ToPhi(1L), log).take();
log.setLevel(before);
Expand All @@ -83,22 +68,7 @@ void logsWhenException() {
final Level before = log.getLevel();
log.setLevel(Level.ALL);
final List<LogRecord> logs = new LinkedList<>();
final Handler hnd = new Handler() {
@Override
public void publish(final LogRecord record) {
logs.add(record);
}

@Override
public void flush() {
throw new UnsupportedOperationException("#flush()");
}

@Override
public void close() throws SecurityException {
throw new UnsupportedOperationException("#close()");
}
};
final Handler hnd = new TestHandler(logs);
log.addHandler(hnd);
final Phi wrong = new PhIncorrect(Phi.Φ);
IntStream.range(0, 5).forEach(
Expand All @@ -125,22 +95,7 @@ void printsShortLogs() throws InterruptedException {
final Level before = log.getLevel();
log.setLevel(Level.ALL);
final List<LogRecord> logs = new LinkedList<>();
final Handler hnd = new Handler() {
@Override
public void publish(final LogRecord record) {
logs.add(record);
}

@Override
public void flush() {
throw new UnsupportedOperationException("#flush()");
}

@Override
public void close() throws SecurityException {
throw new UnsupportedOperationException("#close()");
}
};
final Handler hnd = new TestHandler(logs);
log.addHandler(hnd);
final Thread thread = new Thread(
() -> {
Expand Down Expand Up @@ -170,22 +125,7 @@ void printsLongLogs() throws InterruptedException {
final Level before = log.getLevel();
log.setLevel(Level.ALL);
final List<LogRecord> logs = new LinkedList<>();
final Handler hnd = new Handler() {
@Override
public void publish(final LogRecord record) {
logs.add(record);
}

@Override
public void flush() {
throw new UnsupportedOperationException("#flush()");
}

@Override
public void close() throws SecurityException {
throw new UnsupportedOperationException("#close()");
}
};
final Handler hnd = new TestHandler(logs);
log.addHandler(hnd);
final Thread thread = new Thread(
() -> {
Expand Down Expand Up @@ -261,4 +201,28 @@ public static class PhiDec extends PhDefault {
}
}

private static class TestHandler extends Handler {
final List<LogRecord> logs;

TestHandler(final List<LogRecord> logs) {
this.logs = logs;
}

@Override
public void publish(final LogRecord record) {
logs.add(record);
}

@Override
public void flush() {
throw new UnsupportedOperationException("#flush()");
}

@Override
public void close() throws SecurityException {
throw new UnsupportedOperationException("#close()");
}

}

}

0 comments on commit 85ce4c3

Please sign in to comment.