Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- interface Context {
- fun init()
- fun destroy()
- } // subset of opengl.Context methods
- class OpenGLContext : Context {
- // wrapper for OpenGLContext
- // holds logic and possible interactions with opengl.Context
- // but hides so much as possible
- override fun init() {
- if (opengl.getContext() != null) {
- throw IllegalStateException("context is already initalized")
- }
- opengl.init()
- }
- override fun destroy() {
- if (opengl.getContext() == null) {
- throw IllegalStateException("context is alredy destroyed")
- }
- opengl.destroy()
- }
- }
- // GameEngine doesn't have to know it uses OpenGLContext,
- // knows only about Context from the app
- // and it doesn't care about the static shit in the 3rd party library
- class GameEngine(private val context: Context) {
- fun stop() {
- // ...
- this.context.destroy()
- }
- }
- fun GameEngineRunning_Stop_DestroyContext() {
- // given
- val contextMock = mockk.Create<Context>()
- val engine = GameEngine(contextMock)
- // when
- engine.stop()
- // then
- verify(exactly = 1) {
- contextMock.destroy()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement