### Question:
EditorModel { public void selectNewBuffer() { final Buffer buffer = new BufferImplementation(m_resources, m_textSourceFactory.create(), createNewBufferName()); addBuffer(buffer); selectBuffer(buffer); } EditorModel(Resources resources,
                     TextSource.Factory textSourceFactory,
                     AgentCacheState agentCacheState,
                     FileChangeWatcher fileChangeWatcher); Buffer getSelectedBuffer(); void selectNewBuffer(); Buffer selectBufferForFile(File file); Buffer getBufferForFile(File file); Buffer[] getBuffers(); boolean isABufferDirty(); void selectBuffer(Buffer buffer); void closeBuffer(final Buffer buffer); File getSelectedPropertiesFile(); void setSelectedPropertiesFile(final File selectedProperties); void addListener(Listener listener); boolean isScriptFile(File f); boolean isPropertiesFile(File f); boolean isSelectedScript(File f); boolean isBoringFile(File f); void openWithExternalEditor(final File file); void setExternalEditor(File command, String arguments);  }### Answer:
@Test public void testSelectNewBuffer() throws Exception { final StringTextSource.Factory stringTextSourceFactory = new StringTextSource.Factory(); final DelegatingStubFactory<Factory> textSourceFactoryStubFactory = DelegatingStubFactory.create(stringTextSourceFactory); final RandomStubFactory<Listener> listener1StubFactory = RandomStubFactory.create(EditorModel.Listener.class); final EditorModel editorModel = new EditorModel(s_resources, textSourceFactoryStubFactory.getStub(), m_agentCacheState, m_fileChangeWatcher); final Buffer defaultBuffer = editorModel.getSelectedBuffer(); assertNull(defaultBuffer); editorModel.addListener(listener1StubFactory.getStub()); textSourceFactoryStubFactory.resetCallHistory(); editorModel.selectNewBuffer(); textSourceFactoryStubFactory.assertSuccess("create"); textSourceFactoryStubFactory.assertNoMoreCalls(); final Buffer buffer1 = editorModel.getSelectedBuffer(); assertNotSame(buffer1, defaultBuffer); listener1StubFactory.assertSuccess("bufferAdded", buffer1); listener1StubFactory.assertSuccess("bufferStateChanged", buffer1); listener1StubFactory.assertNoMoreCalls(); editorModel.selectNewBuffer(); final Buffer buffer2 = editorModel.getSelectedBuffer(); assertNotSame(buffer2, buffer1); listener1StubFactory.assertSuccess("bufferAdded", buffer2); listener1StubFactory.assertSuccess("bufferStateChanged", buffer1); listener1StubFactory.assertSuccess("bufferStateChanged", buffer2); listener1StubFactory.assertNoMoreCalls(); }