Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,12 @@
</rule>
</rules>
<excludes>
<exclude>**/*ExampleRunner*</exclude>
<exclude>**/AppCommandLineRunner*</exclude>
<exclude>**/ExamplesCommandLineRunner*</exclude>
<exclude>**/ProducerConsumerExampleRunner*</exclude>
<exclude>**/Consumer*</exclude>
<exclude>**/JavaPatternsAndConstructsApplication*</exclude>
<exclude>**/MainWindow*</exclude>
<exclude>**/Messages*</exclude>
<exclude>**/ApplicationProperties*</exclude>
<exclude>**/HyperlinkMouseListener*</exclude>
<exclude>**/ObservableAbstract*</exclude>
</excludes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public void run() {
try {
queue.put(i);
} catch (InterruptedException finish) {
Thread.currentThread().interrupt();
return;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.penapereira.example.constructs.app.ui;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.awt.EventQueue;

import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.LoggingEvent;
Expand All @@ -25,4 +29,21 @@ void appendsMessageToOutputSink() throws Exception {

assertEquals("test message" + System.lineSeparator(), output.toString());
}

@Test
void attachesItselfToRootLoggerWhenInitialized() throws Exception {
GuiAppender appender = new GuiAppender(text -> {});
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory
.getLogger(Logger.ROOT_LOGGER_NAME);
assertFalse(root.isAttached(appender));
try {
appender.afterPropertiesSet();

assertTrue(appender.isStarted());
assertTrue(root.isAttached(appender));
} finally {
root.detachAppender(appender);
appender.stop();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,21 @@ void chainProcessesNumbers() {
assertEquals("zero", negative.handle(0));
assertEquals("positive", negative.handle(5));
}

@Test
void requestNobodyHandlesIsReportedAsUnhandled() {
Handler negative = new NegativeHandler();
Handler zero = new ZeroHandler();
negative.setNext(zero);

assertEquals("unhandled", negative.handle(5));
}

@Test
void lastHandlerWithoutNextReturnsUnhandled() {
Handler positive = new PositiveHandler();

assertEquals("positive", positive.handle(1));
assertEquals("unhandled", positive.handle(-1));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ void factoryCreatesConcreteProducts() {
assertEquals("Concrete Product A", a.name());
assertEquals("Concrete Product B", b.name());
}

@Test
void factoryRejectsUnknownType() {
ProductFactory factory = new ProductFactory();
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> factory.createProduct("C"));
assertEquals("Unknown type: C", ex.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,21 @@ void producerAddsElements() throws InterruptedException {
assertEquals(2, queue.take());
assertEquals(3, queue.take());
}

@Test
void producerStopsWhenInterrupted() throws InterruptedException {
BlockingQueue<Integer> queue = new LinkedBlockingDeque<>(1);
Thread t = new Thread(new Producer(queue));
t.start();
while (queue.isEmpty()) {
Thread.onSpinWait();
}

t.interrupt();
t.join(5_000);

assertFalse(t.isAlive());
assertEquals(1, queue.size());
assertEquals(1, queue.take());
}
}