OAuth2ScriptsEditor extends JPanel { public List<String> getJavaScripts() { List<String> scripts = new ArrayList<String>(); for (RSyntaxTextArea scriptField : scriptFields) { scripts.add(scriptField.getText()); } return scripts; } OAuth2ScriptsEditor(final OAuth2Profile profile); List<String> getJavaScripts();  }
@Test public void canBeInitializedWithoutExistingScripts() throws Exception { assertThat(editor.getJavaScripts(), is(Arrays.asList("", ""))); }
@Test public void getsJavaScriptsEnteredByUser() throws Exception { final String firstScript = "alert('first')"; final String secondScript = "alert('second')"; enterScript(0, firstScript); enterScript(1, secondScript); assertThat(editor.getJavaScripts(), is(Arrays.asList(firstScript, secondScript))); }
@Test public void getsJavaScriptsFromInitialization() throws Exception { List<String> scripts = Arrays.asList("alert('hello')", "window.status='hello'"); OAuth2ScriptsEditor editorWithExistingScripts = new OAuth2ScriptsEditor(createProfileWith(scripts)); assertThat(editorWithExistingScripts.getJavaScripts(), is(scripts)); }
@Test public void canAddScriptToEditor() throws Exception { final String newScript = "callSomeFunction();"; containerWalker.findButtonWithName(OAuth2ScriptsEditor.ADD_SCRIPT_BUTTON_NAME).doClick(); containerWalker.rebuildIndex(); containerWalker.findTextComponent("Page 3").setText(newScript); List<String> javaScripts = editor.getJavaScripts(); assertThat(javaScripts, is(aCollectionWithSize(3))); assertThat(javaScripts.get(2), is(newScript)); }
@Test public void canRemoveScriptFromEditor() throws Exception { removeInputPanel("Input panel 2"); List<String> javaScripts = editor.getJavaScripts(); assertThat(javaScripts, is(aCollectionWithSize(1))); }