-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(
Inspector
): add method Inspector.verifyWrapperChainContracts
…
… ⚖️
- Loading branch information
Showing
2 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/test/java/io/foldright/inspectablewrappers/SpecificationContractsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package io.foldright.inspectablewrappers; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.concurrent.Executor; | ||
|
||
import static io.foldright.inspectablewrappers.Inspector.verifyWrapperChainContracts; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
|
||
class SpecificationContractsTest { | ||
|
||
private static final Executor DUMMY = command -> { | ||
}; | ||
|
||
@Test | ||
void test_null_unwrap() { | ||
Executor w = new WrapperImpl(null); | ||
|
||
NullPointerException e = Assertions.assertThrowsExactly(NullPointerException.class, () -> verifyWrapperChainContracts(w)); | ||
String expected = "unwrap of Wrapper(io.foldright.inspectablewrappers.SpecificationContractsTest$WrapperImpl) is null"; | ||
assertEquals(expected, e.getMessage()); | ||
} | ||
|
||
@Test | ||
void test_null_adaptee() { | ||
Executor w = new WrapperAdapterImpl(DUMMY, null); | ||
|
||
NullPointerException e = Assertions.assertThrowsExactly(NullPointerException.class, () -> verifyWrapperChainContracts(w)); | ||
String expected = "adaptee of WrapperAdapter(io.foldright.inspectablewrappers.SpecificationContractsTest$WrapperAdapterImpl) is null"; | ||
assertEquals(expected, e.getMessage()); | ||
} | ||
|
||
@Test | ||
void test_Wrap_type_adaptee() { | ||
Executor w = new WrapperAdapterImpl(DUMMY, new WrapperImpl(null)); | ||
|
||
IllegalStateException e = Assertions.assertThrowsExactly(IllegalStateException.class, () -> verifyWrapperChainContracts(w)); | ||
String expected = "adaptee(io.foldright.inspectablewrappers.SpecificationContractsTest$WrapperImpl)" + | ||
" of WrapperAdapter(io.foldright.inspectablewrappers.SpecificationContractsTest$WrapperAdapterImpl) is type Wrapper," + | ||
" adapting a Wrapper to a Wrapper is unnecessary!"; | ||
assertEquals(expected, e.getMessage()); | ||
} | ||
|
||
private static class WrapperImpl implements Wrapper<Executor>, Executor { | ||
private final Executor instance; | ||
|
||
WrapperImpl(Executor instance) { | ||
this.instance = instance; | ||
} | ||
|
||
@Override | ||
public Executor unwrap() { | ||
return instance; | ||
} | ||
|
||
@Override | ||
public void execute(Runnable command) { | ||
} | ||
} | ||
|
||
private static class WrapperAdapterImpl implements WrapperAdapter<Executor>, Executor { | ||
private final Executor wrapper; | ||
private final Executor adaptee; | ||
|
||
WrapperAdapterImpl(Executor wrapper, Executor adaptee) { | ||
this.wrapper = wrapper; | ||
this.adaptee = adaptee; | ||
} | ||
|
||
@Override | ||
public Executor unwrap() { | ||
return wrapper; | ||
} | ||
|
||
@Override | ||
public Executor adaptee() { | ||
return adaptee; | ||
} | ||
|
||
@Override | ||
public void execute(Runnable command) { | ||
} | ||
} | ||
} |