Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan D. Brooks2011-03-21 20:30:22 -0400
committerRyan D. Brooks2011-03-21 20:30:22 -0400
commit06a4dfce54d5cb9ae1d1e0d49915150f3ef44fae (patch)
treef8d41b3c0526367b3d411bc7eb724210102aa2eb
parentbe68ff422aeca2c7a78e05cb8f166137984d4598 (diff)
downloadorg.eclipse.osee-06a4dfce54d5cb9ae1d1e0d49915150f3ef44fae.tar.gz
org.eclipse.osee-06a4dfce54d5cb9ae1d1e0d49915150f3ef44fae.tar.xz
org.eclipse.osee-06a4dfce54d5cb9ae1d1e0d49915150f3ef44fae.zip
refactor: Remove code redundancy from operation loggers by utilizing WriterOperationLogger
-rw-r--r--plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/operation/ConsoleLogger.java11
-rw-r--r--plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/operation/StringOperationLogger.java28
-rw-r--r--plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/operation/WriterOperationLogger.java47
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/importing/parsers/WordMLExtractorDelegateTableOfContentsTest.java21
4 files changed, 83 insertions, 24 deletions
diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/operation/ConsoleLogger.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/operation/ConsoleLogger.java
index 1002319b23..5938d4f0f0 100644
--- a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/operation/ConsoleLogger.java
+++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/operation/ConsoleLogger.java
@@ -13,15 +13,10 @@ package org.eclipse.osee.framework.core.operation;
/**
* @author Ryan D. Brooks
*/
-public class ConsoleLogger extends OperationLogger {
+public class ConsoleLogger extends WriterOperationLogger {
- @Override
- public void log(String... row) {
- for (String cell : row) {
- System.out.print(cell);
- System.out.print(" ");
- }
- System.out.println();
+ public ConsoleLogger() {
+ super(System.out);
}
@Override
diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/operation/StringOperationLogger.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/operation/StringOperationLogger.java
new file mode 100644
index 0000000000..7ce7d323c4
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/operation/StringOperationLogger.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Boeing.
+ * 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:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.operation;
+
+import java.io.StringWriter;
+
+/**
+ * @author Ryan D. Brooks
+ */
+public class StringOperationLogger extends WriterOperationLogger {
+
+ public StringOperationLogger() {
+ super(new StringWriter());
+ }
+
+ @Override
+ public String toString() {
+ return getWriter().toString();
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/operation/WriterOperationLogger.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/operation/WriterOperationLogger.java
new file mode 100644
index 0000000000..9809b4ef20
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/operation/WriterOperationLogger.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Boeing.
+ * 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:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.operation;
+
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.io.Writer;
+
+/**
+ * @author Ryan D. Brooks
+ */
+public class WriterOperationLogger extends OperationLogger {
+ private final PrintWriter writer;
+
+ public WriterOperationLogger(Writer writer) {
+ this(new PrintWriter(writer));
+ }
+
+ public WriterOperationLogger(PrintWriter writer) {
+ this.writer = writer;
+ }
+
+ public WriterOperationLogger(PrintStream stream) {
+ this(new PrintWriter(stream));
+ }
+
+ @Override
+ public void log(String... row) {
+ for (String cell : row) {
+ writer.print(cell);
+ writer.print(" ");
+ }
+ writer.println();
+ }
+
+ public PrintWriter getWriter() {
+ return writer;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/importing/parsers/WordMLExtractorDelegateTableOfContentsTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/importing/parsers/WordMLExtractorDelegateTableOfContentsTest.java
index 7225fa9110..23bc4d030a 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/importing/parsers/WordMLExtractorDelegateTableOfContentsTest.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/importing/parsers/WordMLExtractorDelegateTableOfContentsTest.java
@@ -14,10 +14,10 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.junit.Assert;
-import org.eclipse.osee.framework.core.operation.OperationLogger;
+import org.eclipse.osee.framework.core.operation.StringOperationLogger;
import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.framework.skynet.core.importing.parsers.WordOutlineExtractorDelegate;
+import org.junit.Assert;
import org.junit.Test;
/**
@@ -33,22 +33,11 @@ public final class WordMLExtractorDelegateTableOfContentsTest {
private static final String TABLE_OF_CONTENTS_FILE = "tableOfContentsHyperlinkTest.xml";
private final WordOutlineExtractorDelegate delegate = new WordOutlineExtractorDelegate();
- private class TestOperationLogger extends OperationLogger {
- public final StringBuilder warningMsgs = new StringBuilder();
-
- @Override
- public void log(String... row) {
- for (String warningMessage : row) {
- warningMsgs.append(warningMessage);
- }
- }
- }
-
@Test
public void tableOfContentsLinksInput() throws Exception {
delegate.initialize();
- TestOperationLogger logger = new TestOperationLogger();
+ StringOperationLogger logger = new StringOperationLogger();
Matcher matcher = PARAGRAPHREGEX.matcher(getFileAsString(TABLE_OF_CONTENTS_FILE));
boolean foundSomething = false;
@@ -57,8 +46,8 @@ public final class WordMLExtractorDelegateTableOfContentsTest {
delegate.processContent(logger, null, false, false, null, null, null, matcher.group(), false);
}
- Assert.assertTrue("Warnings generated and Table of Contents in WordML should be detected",
- logger.warningMsgs.length() > 0);
+ Assert.assertFalse("Warnings generated and Table of Contents in WordML should be detected",
+ logger.toString().isEmpty());
Assert.assertTrue(foundSomething);
}

Back to the top