summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrien Hopkins <ahopk127@my.yorku.ca>2022-01-29 15:51:26 -0500
committerAdrien Hopkins <ahopk127@my.yorku.ca>2022-01-29 15:51:26 -0500
commit47b71bb5170fc2c3e1e052452864890826e6848d (patch)
tree64fef7a57b3c81b861ac8367770338791d63b0c7 /src
parentda3a5098602f8177f6d5dac4a322f70d6fdf9126 (diff)
Created the ViewBot in preparation for GUI testing
Diffstat (limited to 'src')
-rw-r--r--src/main/java/sevenUnitsGUI/UnitConversionView.java10
-rw-r--r--src/main/java/sevenUnitsGUI/ViewBot.java230
2 files changed, 238 insertions, 2 deletions
diff --git a/src/main/java/sevenUnitsGUI/UnitConversionView.java b/src/main/java/sevenUnitsGUI/UnitConversionView.java
index f653051..97ec30f 100644
--- a/src/main/java/sevenUnitsGUI/UnitConversionView.java
+++ b/src/main/java/sevenUnitsGUI/UnitConversionView.java
@@ -32,6 +32,12 @@ import sevenUnits.utils.ObjectProduct;
*/
public interface UnitConversionView extends View {
/**
+ * @return dimensions available for filtering
+ * @since 2022-01-29
+ */
+ List<NamedObjectProduct<BaseDimension>> getDimensions();
+
+ /**
* @return unit to convert <em>from</em>
* @since 2021-12-15
*/
@@ -42,13 +48,13 @@ public interface UnitConversionView extends View {
* string provided by the user)
* @since 2021-12-15
*/
- Optional<String> getInputValue();
+ String getInputValue();
/**
* @return selected dimension
* @since 2021-12-15
*/
- Optional<ObjectProduct<BaseDimension>> getSelectedDimension();
+ Optional<? extends ObjectProduct<BaseDimension>> getSelectedDimension();
/**
* @return unit to convert <em>to</em>
diff --git a/src/main/java/sevenUnitsGUI/ViewBot.java b/src/main/java/sevenUnitsGUI/ViewBot.java
new file mode 100644
index 0000000..bc4103c
--- /dev/null
+++ b/src/main/java/sevenUnitsGUI/ViewBot.java
@@ -0,0 +1,230 @@
+/**
+ * Copyright (C) 2022 Adrien Hopkins
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+package sevenUnitsGUI;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+
+import sevenUnits.unit.BaseDimension;
+import sevenUnits.unit.Unit;
+import sevenUnits.utils.NamedObjectProduct;
+import sevenUnits.utils.ObjectProduct;
+
+/**
+ * A class that simulates a View (supports both unit and expression conversion)
+ * for testing. Getters and setters work as expected.
+ *
+ * @author Adrien Hopkins
+ * @since 2022-01-29
+ */
+final class ViewBot implements UnitConversionView, ExpressionConversionView {
+ /** The presenter that works with this ViewBot */
+ private final Presenter presenter;
+
+ /** The dimensions available to select from */
+ private List<NamedObjectProduct<BaseDimension>> dimensions;
+ /** The expression in the From field */
+ private String fromExpression;
+ /** The expression in the To field */
+ private String toExpression;
+ /**
+ * The user-provided string representing the value in {@code fromSelection}
+ */
+ private String inputValue;
+ /** The unit selected in the From selection */
+ private Optional<Unit> fromSelection;
+ /** The unit selected in the To selection */
+ private Optional<Unit> toSelection;
+ /** The currently selected dimension */
+ private Optional<? extends ObjectProduct<BaseDimension>> selectedDimension;
+ /** The units available in the From selection */
+ private List<? extends Unit> fromUnits;
+ /** The units available in the To selection */
+ private List<? extends Unit> toUnits;
+
+ /**
+ * Creates a new {@code ViewBot} with a new presenter.
+ *
+ * @since 2022-01-29
+ */
+ public ViewBot() {
+ this.presenter = new Presenter(this);
+ }
+
+ /**
+ * @return the available dimensions
+ * @since 2022-01-29
+ */
+ @Override
+ public List<NamedObjectProduct<BaseDimension>> getDimensions() {
+ return this.dimensions;
+ }
+
+ @Override
+ public String getFromExpression() {
+ return this.fromExpression;
+ }
+
+ @Override
+ public Optional<Unit> getFromSelection() {
+ return this.fromSelection;
+ }
+
+ /**
+ * @return the units available for selection in From
+ * @since 2022-01-29
+ */
+ public List<? extends Unit> getFromUnits() {
+ return this.fromUnits;
+ }
+
+ @Override
+ public String getInputValue() {
+ return this.inputValue;
+ }
+
+ /**
+ * @return the presenter associated with tihs view
+ * @since 2022-01-29
+ */
+ public Presenter getPresenter() {
+ return this.presenter;
+ }
+
+ @Override
+ public Optional<? extends ObjectProduct<BaseDimension>> getSelectedDimension() {
+ return this.selectedDimension;
+ }
+
+ @Override
+ public String getToExpression() {
+ return this.toExpression;
+ }
+
+ @Override
+ public Optional<Unit> getToSelection() {
+ return this.toSelection;
+ }
+
+ /**
+ * @return the units available for selection in To
+ * @since 2022-01-29
+ */
+ public List<? extends Unit> getToUnits() {
+ return this.toUnits;
+ }
+
+ @Override
+ public void setDimensions(
+ List<NamedObjectProduct<BaseDimension>> dimensions) {
+ this.dimensions = Objects.requireNonNull(dimensions,
+ "dimensions may not be null");
+ }
+
+ /**
+ * Sets the From expression (as in {@link #getFromExpression}).
+ *
+ * @param fromExpression the expression to convert from
+ * @throws NullPointerException if {@code fromExpression} is null
+ * @since 2022-01-29
+ */
+ public void setFromExpression(String fromExpression) {
+ this.fromExpression = Objects.requireNonNull(fromExpression,
+ "fromExpression cannot be null.");
+ }
+
+ /**
+ * @param fromSelection the fromSelection to set
+ * @since 2022-01-29
+ */
+ public void setFromSelection(Optional<Unit> fromSelection) {
+ this.fromSelection = Objects.requireNonNull(fromSelection,
+ "fromSelection cannot be null");
+ }
+
+ @Override
+ public void setFromUnits(List<? extends Unit> units) {
+ this.fromUnits = Objects.requireNonNull(units, "units may not be null");
+ }
+
+ /**
+ * @param inputValue the inputValue to set
+ * @since 2022-01-29
+ */
+ public void setInputValue(String inputValue) {
+ this.inputValue = inputValue;
+ }
+
+ /**
+ * @param selectedDimension the selectedDimension to set
+ * @since 2022-01-29
+ */
+ public void setSelectedDimension(
+ Optional<? extends ObjectProduct<BaseDimension>> selectedDimension) {
+ this.selectedDimension = selectedDimension;
+ }
+
+ /**
+ * Sets the To expression (as in {@link #getToExpression}).
+ *
+ * @param toExpression the expression to convert to
+ * @throws NullPointerException if {@code toExpression} is null
+ * @since 2022-01-29
+ */
+ public void setToExpression(String toExpression) {
+ this.toExpression = Objects.requireNonNull(toExpression,
+ "toExpression cannot be null.");
+ }
+
+ /**
+ * @param toSelection the toSelection to set
+ * @since 2022-01-29
+ */
+ public void setToSelection(Optional<Unit> toSelection) {
+ this.toSelection = Objects.requireNonNull(toSelection,
+ "toSelection cannot be null.");
+ }
+
+ @Override
+ public void setToUnits(List<? extends Unit> units) {
+ this.toUnits = Objects.requireNonNull(units, "units may not be null");
+ }
+
+ @Override
+ public void showErrorMessage(String title, String message) {
+ System.err.printf("%s: %s%n", title, message);
+ }
+
+ @Override
+ public void showExpressionConversionOutput(String fromExpression,
+ String toExpression, double value) {
+ System.out.printf("Expression Conversion: %s = %d * (%s)%n",
+ fromExpression, value, toExpression);
+ }
+
+ @Override
+ public void showUnitConversionOutput(String outputString) {
+ System.out.println("Unit conversion: " + outputString);
+ }
+
+ @Override
+ public String toString() {
+ return super.toString() + String.format("[presenter=%s]", this.presenter);
+ }
+
+}