Skip to main content
summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorBrian Vosburgh2012-10-11 18:42:17 -0400
committerBrian Vosburgh2012-10-12 17:22:20 -0400
commit862d9dcae22f346ab7602e80c10ccb6d7fa00a6f (patch)
tree008fe50c103df94a0416f1ed49659c150ca43598 /common
parentb831c64068effde7cf2b69baddd12e0705d3e44b (diff)
downloadwebtools.dali-862d9dcae22f346ab7602e80c10ccb6d7fa00a6f.tar.gz
webtools.dali-862d9dcae22f346ab7602e80c10ccb6d7fa00a6f.tar.xz
webtools.dali-862d9dcae22f346ab7602e80c10ccb6d7fa00a6f.zip
add some utility tests
Diffstat (limited to 'common')
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CancelExceptionTests.java31
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CollectingExceptionHandlerTests.java70
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CompositeExceptionHandlerTests.java127
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CompositeExceptionTests.java48
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CompositeMultiThreadedExceptionHandlerTests.java48
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/JptCommonUtilityTests.java8
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/PrintStreamExceptionHandlerTests.java43
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/PrintWriterExceptionHandlerTests.java43
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/SimpleAssociationTests.java12
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/StackTraceTests.java31
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/io/JptCommonUtilityIOTests.java1
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/io/StringBuilderWriterTests.java67
12 files changed, 521 insertions, 8 deletions
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CancelExceptionTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CancelExceptionTests.java
new file mode 100644
index 0000000000..7efc3dbbf7
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CancelExceptionTests.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.tests.internal;
+
+import junit.framework.TestCase;
+import org.eclipse.jpt.common.utility.internal.CancelException;
+
+public class CancelExceptionTests
+ extends TestCase
+{
+ public CancelExceptionTests(String name) {
+ super(name);
+ }
+
+ public void testConstruction() {
+ CancelException ex = new CancelException();
+ assertNotNull(ex);
+ }
+
+ public void testToString() {
+ CancelException ex = new CancelException();
+ assertNotNull(ex.toString());
+ }
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CollectingExceptionHandlerTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CollectingExceptionHandlerTests.java
new file mode 100644
index 0000000000..166fb9df1f
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CollectingExceptionHandlerTests.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.tests.internal;
+
+import junit.framework.TestCase;
+import org.eclipse.jpt.common.utility.internal.CollectingExceptionHandler;
+import org.eclipse.jpt.common.utility.internal.iterable.IterableTools;
+
+public class CollectingExceptionHandlerTests
+ extends TestCase
+{
+ public CollectingExceptionHandlerTests(String name) {
+ super(name);
+ }
+
+ public void testHandleException() {
+ CollectingExceptionHandler exceptionHandler = new CollectingExceptionHandler();
+ Exception npe1 = new NullPointerException();
+ exceptionHandler.handleException(npe1);
+ Exception npe2 = new NullPointerException();
+ exceptionHandler.handleException(npe2);
+
+ Iterable<Throwable> exceptions = exceptionHandler.getExceptions();
+ assertEquals(2, IterableTools.size(exceptions));
+ }
+
+ public void testGetExceptions() {
+ CollectingExceptionHandler exceptionHandler = new CollectingExceptionHandler();
+ Exception npe1 = new NullPointerException();
+ exceptionHandler.handleException(npe1);
+ Exception npe2 = new NullPointerException();
+ exceptionHandler.handleException(npe2);
+
+ Iterable<Throwable> exceptions = exceptionHandler.getExceptions();
+ assertEquals(2, IterableTools.size(exceptions));
+ assertTrue(IterableTools.contains(exceptions, npe1));
+ assertTrue(IterableTools.contains(exceptions, npe2));
+ }
+
+ public void testClearExceptions() {
+ CollectingExceptionHandler exceptionHandler = new CollectingExceptionHandler();
+ Exception npe1 = new NullPointerException();
+ exceptionHandler.handleException(npe1);
+ Exception npe2 = new NullPointerException();
+ exceptionHandler.handleException(npe2);
+
+ Iterable<Throwable> exceptions = exceptionHandler.clearExceptions();
+ assertEquals(2, IterableTools.size(exceptions));
+ assertTrue(IterableTools.contains(exceptions, npe1));
+ assertTrue(IterableTools.contains(exceptions, npe2));
+
+ exceptions = exceptionHandler.clearExceptions();
+ assertTrue(IterableTools.isEmpty(exceptions));
+
+ exceptions = exceptionHandler.getExceptions();
+ assertTrue(IterableTools.isEmpty(exceptions));
+ }
+
+ public void testToString() {
+ CollectingExceptionHandler exceptionHandler = new CollectingExceptionHandler();
+ assertNotNull(exceptionHandler.toString());
+ }
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CompositeExceptionHandlerTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CompositeExceptionHandlerTests.java
new file mode 100644
index 0000000000..ddb7a643a6
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CompositeExceptionHandlerTests.java
@@ -0,0 +1,127 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.tests.internal;
+
+import junit.framework.TestCase;
+import org.eclipse.jpt.common.utility.ExceptionHandler;
+import org.eclipse.jpt.common.utility.internal.CompositeExceptionHandler;
+import org.eclipse.jpt.common.utility.internal.iterable.IterableTools;
+
+@SuppressWarnings("nls")
+public class CompositeExceptionHandlerTests
+ extends TestCase
+{
+ public CompositeExceptionHandlerTests(String name) {
+ super(name);
+ }
+
+ public void testHandleException() {
+ TestExceptionHandler handler1 = new TestExceptionHandler();
+ TestExceptionHandler handler2 = new TestExceptionHandler();
+ CompositeExceptionHandler exceptionHandler = new CompositeExceptionHandler(handler1, handler2);
+ Exception npe = new NullPointerException();
+ exceptionHandler.handleException(npe);
+
+ assertEquals(npe, handler1.throwable);
+ assertEquals(npe, handler2.throwable);
+ }
+
+ public void testGetExceptionHandlers() {
+ TestExceptionHandler handler1 = new TestExceptionHandler();
+ TestExceptionHandler handler2 = new TestExceptionHandler();
+ CompositeExceptionHandler exceptionHandler = new CompositeExceptionHandler(handler1, handler2);
+
+ Iterable<ExceptionHandler> handlers = exceptionHandler.getExceptionHandlers();
+ assertTrue(IterableTools.contains(handlers, handler1));
+ assertTrue(IterableTools.contains(handlers, handler2));
+ }
+
+ public void testAddExceptionHandler() {
+ TestExceptionHandler handler1 = new TestExceptionHandler();
+ CompositeExceptionHandler exceptionHandler = new CompositeExceptionHandler(handler1);
+ TestExceptionHandler handler2 = new TestExceptionHandler();
+ exceptionHandler.addExceptionHandler(handler2);
+ Exception npe = new NullPointerException();
+ exceptionHandler.handleException(npe);
+
+ Iterable<ExceptionHandler> handlers = exceptionHandler.getExceptionHandlers();
+ assertTrue(IterableTools.contains(handlers, handler1));
+ assertTrue(IterableTools.contains(handlers, handler2));
+
+ assertEquals(npe, handler1.throwable);
+ assertEquals(npe, handler2.throwable);
+ }
+
+ public void testAddExceptionHandler_exception() {
+ TestExceptionHandler handler1 = new TestExceptionHandler();
+ CompositeExceptionHandler exceptionHandler = new CompositeExceptionHandler(handler1);
+ try {
+ exceptionHandler.addExceptionHandler(handler1);
+ fail();
+ } catch (IllegalArgumentException ex) {
+ assertTrue(ex.getMessage().contains("duplicate handler"));
+ }
+ }
+
+ public void testRemoveExceptionHandler() {
+ TestExceptionHandler handler1 = new TestExceptionHandler();
+ CompositeExceptionHandler exceptionHandler = new CompositeExceptionHandler(handler1);
+ TestExceptionHandler handler2 = new TestExceptionHandler();
+ exceptionHandler.addExceptionHandler(handler2);
+ Exception npe = new NullPointerException();
+ exceptionHandler.handleException(npe);
+
+ Iterable<ExceptionHandler> handlers = exceptionHandler.getExceptionHandlers();
+ assertTrue(IterableTools.contains(handlers, handler1));
+ assertTrue(IterableTools.contains(handlers, handler2));
+
+ assertEquals(npe, handler1.throwable);
+ assertEquals(npe, handler2.throwable);
+
+ handler1.throwable = null;
+ handler2.throwable = null;
+ exceptionHandler.removeExceptionHandler(handler2);
+ exceptionHandler.handleException(npe);
+
+ handlers = exceptionHandler.getExceptionHandlers();
+ assertTrue(IterableTools.contains(handlers, handler1));
+ assertFalse(IterableTools.contains(handlers, handler2));
+
+ assertEquals(npe, handler1.throwable);
+ assertNull(handler2.throwable);
+ }
+
+ public void testRemoveExceptionHandler_exception() {
+ TestExceptionHandler handler1 = new TestExceptionHandler();
+ CompositeExceptionHandler exceptionHandler = new CompositeExceptionHandler(handler1);
+ TestExceptionHandler handler2 = new TestExceptionHandler();
+ try {
+ exceptionHandler.removeExceptionHandler(handler2);
+ fail();
+ } catch (IllegalArgumentException ex) {
+ assertTrue(ex.getMessage().contains("handler not registered"));
+ }
+ }
+
+ public void testToString() {
+ CompositeExceptionHandler exceptionHandler = new CompositeExceptionHandler();
+ assertNotNull(exceptionHandler.toString());
+ }
+
+
+ public static class TestExceptionHandler
+ implements ExceptionHandler
+ {
+ public volatile Throwable throwable = null;
+ public void handleException(Throwable t) {
+ this.throwable = t;
+ }
+ }
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CompositeExceptionTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CompositeExceptionTests.java
new file mode 100644
index 0000000000..4a1a4fdc3a
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CompositeExceptionTests.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.tests.internal;
+
+import junit.framework.TestCase;
+import org.eclipse.jpt.common.utility.internal.CompositeException;
+import org.eclipse.jpt.common.utility.internal.iterable.IterableTools;
+
+@SuppressWarnings("nls")
+public class CompositeExceptionTests
+ extends TestCase
+{
+ public CompositeExceptionTests(String name) {
+ super(name);
+ }
+
+ public void testGetException() {
+ Exception npe = new NullPointerException();
+ Exception iae = new IllegalArgumentException();
+ CompositeException ex = new CompositeException(npe, iae);
+
+ Iterable<Throwable> exceptions = ex.getExceptions();
+ assertEquals(2, IterableTools.size(exceptions));
+ assertTrue(IterableTools.contains(exceptions, npe));
+ assertTrue(IterableTools.contains(exceptions, iae));
+ }
+
+ public void testGetMessage() {
+ Exception npe = new NullPointerException();
+ Exception iae = new IllegalArgumentException();
+ CompositeException ex = new CompositeException(npe, iae);
+
+ assertTrue(ex.getMessage().contains("NullPointerException"));
+ assertTrue(ex.getMessage().contains("IllegalArgumentException"));
+ }
+
+ public void testToString() {
+ CompositeException ex = new CompositeException();
+ assertNotNull(ex.toString());
+ }
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CompositeMultiThreadedExceptionHandlerTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CompositeMultiThreadedExceptionHandlerTests.java
new file mode 100644
index 0000000000..e3dd8ecc30
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CompositeMultiThreadedExceptionHandlerTests.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.tests.internal;
+
+import junit.framework.TestCase;
+import org.eclipse.jpt.common.utility.MultiThreadedExceptionHandler;
+import org.eclipse.jpt.common.utility.internal.CompositeMultiThreadedExceptionHandler;
+import org.eclipse.jpt.common.utility.tests.internal.CompositeExceptionHandlerTests.TestExceptionHandler;
+
+public class CompositeMultiThreadedExceptionHandlerTests
+ extends TestCase
+{
+ public CompositeMultiThreadedExceptionHandlerTests(String name) {
+ super(name);
+ }
+
+ public void testHandleException() {
+ TestMultiThreadedExceptionHandler handler1 = new TestMultiThreadedExceptionHandler();
+ TestMultiThreadedExceptionHandler handler2 = new TestMultiThreadedExceptionHandler();
+ CompositeMultiThreadedExceptionHandler exceptionHandler = new CompositeMultiThreadedExceptionHandler(handler1, handler2);
+ Exception npe = new NullPointerException();
+ Thread thread = Thread.currentThread();
+ exceptionHandler.handleException(thread, npe);
+
+ assertEquals(npe, handler1.throwable);
+ assertEquals(thread, handler1.thread);
+ assertEquals(npe, handler2.throwable);
+ assertEquals(thread, handler2.thread);
+ }
+
+ public static class TestMultiThreadedExceptionHandler
+ extends TestExceptionHandler
+ implements MultiThreadedExceptionHandler
+ {
+ public volatile Thread thread = null;
+ public void handleException(Thread t, Throwable ex) {
+ this.thread = t;
+ this.throwable = ex;
+ }
+ }
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/JptCommonUtilityTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/JptCommonUtilityTests.java
index 63629ce44c..1a81c3fc8a 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/JptCommonUtilityTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/JptCommonUtilityTests.java
@@ -49,20 +49,28 @@ public class JptCommonUtilityTests {
suite.addTestSuite(BitToolsTests.class);
suite.addTestSuite(BooleanToolsTests.class);
suite.addTestSuite(ByteArrayToolsTests.class);
+ suite.addTestSuite(CancelExceptionTests.class);
suite.addTestSuite(CharacterToolsTests.class);
suite.addTestSuite(CharArrayToolsTests.class);
suite.addTestSuite(ClassToolsTests.class);
suite.addTestSuite(ClassNameToolsTests.class);
suite.addTestSuite(ClasspathTests.class);
+ suite.addTestSuite(CollectingExceptionHandlerTests.class);
+ suite.addTestSuite(CompositeExceptionHandlerTests.class);
+ suite.addTestSuite(CompositeExceptionTests.class);
+ suite.addTestSuite(CompositeMultiThreadedExceptionHandlerTests.class);
suite.addTestSuite(ExceptionHandlerTests.class);
suite.addTestSuite(ListenerListTests.class);
suite.addTestSuite(NameToolsTests.class);
suite.addTestSuite(ObjectToolsTests.class);
+ suite.addTestSuite(PrintStreamExceptionHandlerTests.class);
+ suite.addTestSuite(PrintWriterExceptionHandlerTests.class);
suite.addTestSuite(RangeTests.class);
suite.addTestSuite(ReverseComparatorTests.class);
suite.addTestSuite(SimpleAssociationTests.class);
suite.addTestSuite(SimpleJavaTypeTests.class);
suite.addTestSuite(SimpleMethodSignatureTests.class);
+ suite.addTestSuite(StackTraceTests.class);
suite.addTestSuite(StringToolsTests.class);
suite.addTestSuite(StringBufferToolsTests.class);
suite.addTestSuite(StringBuilderToolsTests.class);
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/PrintStreamExceptionHandlerTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/PrintStreamExceptionHandlerTests.java
new file mode 100644
index 0000000000..a30aab860a
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/PrintStreamExceptionHandlerTests.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.tests.internal;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import junit.framework.TestCase;
+import org.eclipse.jpt.common.utility.ExceptionHandler;
+import org.eclipse.jpt.common.utility.internal.CompositeExceptionHandler;
+import org.eclipse.jpt.common.utility.internal.PrintStreamExceptionHandler;
+
+@SuppressWarnings("nls")
+public class PrintStreamExceptionHandlerTests
+ extends TestCase
+{
+ public PrintStreamExceptionHandlerTests(String name) {
+ super(name);
+ }
+
+ public void testHandleException() {
+ OutputStream out = new ByteArrayOutputStream();
+ PrintStream stream = new PrintStream(out);
+ ExceptionHandler exceptionHandler = new PrintStreamExceptionHandler(stream);
+ Exception npe = new NullPointerException();
+ exceptionHandler.handleException(npe);
+ stream.flush();
+
+ assertTrue(out.toString().contains("NullPointerException"));
+ }
+
+ public void testToString() {
+ CompositeExceptionHandler exceptionHandler = new CompositeExceptionHandler();
+ assertNotNull(exceptionHandler.toString());
+ }
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/PrintWriterExceptionHandlerTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/PrintWriterExceptionHandlerTests.java
new file mode 100644
index 0000000000..7e695f2960
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/PrintWriterExceptionHandlerTests.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.tests.internal;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import junit.framework.TestCase;
+import org.eclipse.jpt.common.utility.ExceptionHandler;
+import org.eclipse.jpt.common.utility.internal.CompositeExceptionHandler;
+import org.eclipse.jpt.common.utility.internal.PrintWriterExceptionHandler;
+
+@SuppressWarnings("nls")
+public class PrintWriterExceptionHandlerTests
+ extends TestCase
+{
+ public PrintWriterExceptionHandlerTests(String name) {
+ super(name);
+ }
+
+ public void testHandleException() {
+ OutputStream out = new ByteArrayOutputStream();
+ PrintWriter stream = new PrintWriter(out);
+ ExceptionHandler exceptionHandler = new PrintWriterExceptionHandler(stream);
+ Exception npe = new NullPointerException();
+ exceptionHandler.handleException(npe);
+ stream.flush();
+
+ assertTrue(out.toString().contains("NullPointerException"));
+ }
+
+ public void testToString() {
+ CompositeExceptionHandler exceptionHandler = new CompositeExceptionHandler();
+ assertNotNull(exceptionHandler.toString());
+ }
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/SimpleAssociationTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/SimpleAssociationTests.java
index 8850a576d0..9bcdfa0962 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/SimpleAssociationTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/SimpleAssociationTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,20 +9,16 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.tests.internal;
-import junit.framework.Test;
import junit.framework.TestCase;
-import junit.framework.TestSuite;
import org.eclipse.jpt.common.utility.Association;
import org.eclipse.jpt.common.utility.internal.SimpleAssociation;
@SuppressWarnings("nls")
-public class SimpleAssociationTests extends TestCase {
+public class SimpleAssociationTests
+ extends TestCase
+{
private SimpleAssociation<String, String> assoc;
- public static Test suite() {
- return new TestSuite(SimpleAssociationTests.class);
- }
-
public SimpleAssociationTests(String name) {
super(name);
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/StackTraceTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/StackTraceTests.java
new file mode 100644
index 0000000000..4b6ad2a921
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/StackTraceTests.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.tests.internal;
+
+import junit.framework.TestCase;
+import org.eclipse.jpt.common.utility.internal.StackTrace;
+
+public class StackTraceTests
+ extends TestCase
+{
+ public StackTraceTests(String name) {
+ super(name);
+ }
+
+ public void testToString() throws Exception {
+ StackTrace st = new StackTrace();
+ assertTrue(st.toString().contains(this.getClass().getName()));
+ }
+
+ public void testToString_noTestClass() throws Exception {
+ StackTrace st = new StackTrace(this.getClass());
+ assertFalse(st.toString().contains(this.getClass().getName()));
+ }
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/io/JptCommonUtilityIOTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/io/JptCommonUtilityIOTests.java
index 1df23b47f1..7a25d75544 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/io/JptCommonUtilityIOTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/io/JptCommonUtilityIOTests.java
@@ -29,6 +29,7 @@ public class JptCommonUtilityIOTests {
suite.addTestSuite(NullWriterTests.class);
suite.addTestSuite(PipeTests.class);
suite.addTestSuite(StringBufferWriterTests.class);
+ suite.addTestSuite(StringBuilderWriterTests.class);
suite.addTestSuite(CompositeOutputStreamTests.class);
suite.addTestSuite(CompositeWriterTests.class);
suite.addTestSuite(WriterToolsTests.class);
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/io/StringBuilderWriterTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/io/StringBuilderWriterTests.java
new file mode 100644
index 0000000000..185494e18d
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/io/StringBuilderWriterTests.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.tests.internal.io;
+
+import junit.framework.TestCase;
+import org.eclipse.jpt.common.utility.internal.io.StringBuilderWriter;
+import org.eclipse.jpt.common.utility.tests.internal.TestTools;
+
+@SuppressWarnings("nls")
+public class StringBuilderWriterTests
+ extends TestCase
+{
+ private StringBuilderWriter writer;
+
+
+ public StringBuilderWriterTests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.writer = new StringBuilderWriter();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ TestTools.clear(this);
+ super.tearDown();
+ }
+
+ public void testWriteInt() throws Exception {
+ this.writer.write('a');
+ this.writer.write('b');
+ this.writer.write('c');
+ assertEquals(3, this.writer.getBuilder().length());
+ assertEquals("abc", this.writer.toString());
+ }
+
+ public void testWriteCharArray() throws Exception {
+ this.writer.write(new char[] {'a', 'b', 'c'});
+ this.writer.write(new char[] {'a', 'b', 'c'});
+ assertEquals(6, this.writer.getBuilder().length());
+ assertEquals("abcabc", this.writer.toString());
+ }
+
+ public void testWriteString() throws Exception {
+ this.writer.write("abc");
+ this.writer.write("abc");
+ assertEquals(6, this.writer.getBuilder().length());
+ assertEquals("abcabc", this.writer.toString());
+ }
+
+ public void testWriteStringIntInt() throws Exception {
+ this.writer.write("abc", 1, 2);
+ this.writer.write("abc", 2, 1);
+ assertEquals(3, this.writer.getBuilder().length());
+ assertEquals("bcc", this.writer.toString());
+ }
+}

Back to the top