Created
June 28, 2019 22:07
-
-
Save alwarren/1140719c30be879c39f918ff3261f435 to your computer and use it in GitHub Desktop.
A Generic API Unit Test
This file contains hidden or 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
/** | |
* Name: MyObject | |
* Date: | |
* Description: Tests used to create an empty API for an immutable type MyObject | |
* using test driven design (TDD). | |
* | |
* API Specification: | |
* | |
* public class MyObject { | |
* public MyObject(Object[] objects) // a general constructor description | |
* public int someMethod() // what someMethod does | |
* public int[] someOtherMethod() // what someOtherMethod does | |
* } | |
* | |
* Corner Cases | |
* - Throw a java.lang.IllegalArgumentException if any argument is null. | |
*/ | |
@DisplayName("MyObject Api") | |
class TestMyObjectApi { | |
@DisplayName("Verify methods") | |
@Test | |
void should_verify_api_methods() { | |
List<String> expected = expectedMethodNames(); | |
List<String> actual = actualMethodNames(); | |
assertEquals(expected, actual); | |
} | |
List<String> expectedMethodNames() { | |
List<String> names = Arrays.asList("someMethod", "someOtherMethod"); | |
Collections.sort(names); | |
return names; | |
} | |
List<String> actualMethodNames() { | |
return Spy.publicMethodNames(MyObject.class) | |
.stream() | |
.filter(s -> !s.equals("main")) | |
.sorted() | |
.collect(Collectors.toList()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment