-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
256 additions
and
45 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
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
53 changes: 53 additions & 0 deletions
53
...zed/memoized-core/src/main/java/com/pragmaticobjects/oo/memoized/core/AssertDisposal.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,53 @@ | ||
/*- | ||
* =========================================================================== | ||
* memoized-core | ||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
* Copyright (C) 2019 - 2022 Kapralov Sergey | ||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
* ============================================================================ | ||
*/ | ||
package com.pragmaticobjects.oo.memoized.core; | ||
|
||
import com.pragmaticobjects.oo.tests.Assertion; | ||
import io.vavr.collection.List; | ||
import org.assertj.core.api.Assertions; | ||
|
||
import java.util.Optional; | ||
|
||
public class AssertDisposal implements Assertion { | ||
private final Memory memoryUnderTest; | ||
private final List<MemoizedCallable<?>> preparationCallables; | ||
private final MemoizedCallable<?> callableToDispose; | ||
private final Optional<?> expectedDisposedValue; | ||
|
||
public AssertDisposal(Memory memoryUnderTest, List<MemoizedCallable<?>> preparationCallables, MemoizedCallable<?> callableToDispose, Optional<?> expectedDisposedValue) { | ||
this.memoryUnderTest = memoryUnderTest; | ||
this.preparationCallables = preparationCallables; | ||
this.callableToDispose = callableToDispose; | ||
this.expectedDisposedValue = expectedDisposedValue; | ||
} | ||
|
||
@Override | ||
public final void check() throws Exception { | ||
preparationCallables.forEach(memoryUnderTest::memoized); | ||
Optional<?> disposedValue = memoryUnderTest.dispose(callableToDispose); | ||
Assertions.assertThat(disposedValue).isEqualTo(expectedDisposedValue); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...oized/memoized-core/src/main/java/com/pragmaticobjects/oo/memoized/core/TestCallable.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,44 @@ | ||
/*- | ||
* =========================================================================== | ||
* memoized-core | ||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
* Copyright (C) 2019 - 2022 Kapralov Sergey | ||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
* ============================================================================ | ||
*/ | ||
package com.pragmaticobjects.oo.memoized.core; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
// NOTE: equals, hashCode and toString are implicitly generated | ||
// by equivalence-maven-plugin | ||
class TestCallable implements MemoizedCallable { | ||
private final AtomicInteger counter; | ||
|
||
public TestCallable(AtomicInteger counter) { | ||
this.counter = counter; | ||
} | ||
|
||
@Override | ||
public final Object call() { | ||
counter.incrementAndGet(); | ||
return null; | ||
} | ||
} |
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
54 changes: 54 additions & 0 deletions
54
...memoized-core/src/test/java/com/pragmaticobjects/oo/memoized/core/AssertDisposalTest.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,54 @@ | ||
/*- | ||
* =========================================================================== | ||
* memoized-core | ||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
* Copyright (C) 2019 - 2022 Kapralov Sergey | ||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
* ============================================================================ | ||
*/ | ||
package com.pragmaticobjects.oo.memoized.core; | ||
|
||
import com.pragmaticobjects.oo.tests.AssertAssertionPasses; | ||
import com.pragmaticobjects.oo.tests.TestCase; | ||
import com.pragmaticobjects.oo.tests.junit5.TestsSuite; | ||
import io.vavr.collection.List; | ||
|
||
import java.util.Optional; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
public class AssertDisposalTest extends TestsSuite { | ||
public AssertDisposalTest() { | ||
super( | ||
new TestCase( | ||
"blunt disposal", | ||
new AssertAssertionPasses( | ||
new AssertDisposal( | ||
new BluntMemory(), | ||
List.empty(), | ||
new TestCallable( | ||
new AtomicInteger() | ||
), | ||
Optional.empty() | ||
) | ||
) | ||
) | ||
); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...moized/memoized-core/src/test/java/com/pragmaticobjects/oo/memoized/core/BluntMemory.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,48 @@ | ||
/*- | ||
* =========================================================================== | ||
* memoized-core | ||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
* Copyright (C) 2019 - 2022 Kapralov Sergey | ||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
* ============================================================================ | ||
*/ | ||
package com.pragmaticobjects.oo.memoized.core; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* Test {@link Memory} implementation that memoises nothing | ||
*/ | ||
class BluntMemory implements Memory { | ||
@Override | ||
public final <T> T memoized(MemoizedCallable<T> callable) { | ||
return callable.call(); | ||
} | ||
|
||
@Override | ||
public final <T> Optional<T> dispose(MemoizedCallable<T> callable) { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public final void clean() { | ||
// Do Nothing | ||
} | ||
} |