This repository has been archived by the owner on Mar 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #9 by adding persistence support
- Do not use Selenium Action interface since we wait for a retest type like AbstractAction. Instead use an ID to distinguish between actions. - Remove unnecessary mock and Selenium dependencies. - Add clear() methods to remove all state machines from the memory. - Add save() and load() support for persistence.
- Loading branch information
Showing
14 changed files
with
192 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 15 additions & 7 deletions
22
src/main/scala/de/retest/guistatemachine/api/impl/GuiStateMachineApiImpl.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,31 @@ | ||
package de.retest.guistatemachine.api.impl | ||
|
||
import de.retest.guistatemachine.api.{GuiStateMachine, GuiStateMachineApi, Id} | ||
import java.io.{FileInputStream, FileOutputStream, ObjectInputStream, ObjectOutputStream} | ||
|
||
import scala.collection.immutable.HashMap | ||
import de.retest.guistatemachine.api.{GuiStateMachine, GuiStateMachineApi, Id} | ||
|
||
object GuiStateMachineApiImpl extends GuiStateMachineApi { | ||
val stateMachines = IdMap(new HashMap[Id, GuiStateMachine]) | ||
var stateMachines = IdMap[GuiStateMachine] | ||
|
||
override def createStateMachine(): Id = stateMachines.addNewElement(new GuiStateMachineImpl) | ||
|
||
override def removeStateMachine(id: Id): Boolean = stateMachines.removeElement(id) | ||
|
||
override def getStateMachine(id: Id): Option[GuiStateMachine] = stateMachines.getElement(id) | ||
|
||
override def persist(): Unit = { | ||
// TODO #9 store on the disk | ||
override def clear(): Unit = stateMachines.clear() | ||
|
||
override def save(filePath: String): Unit = { | ||
val oos = new ObjectOutputStream(new FileOutputStream(filePath)) | ||
oos.writeObject(stateMachines) | ||
oos.close | ||
} | ||
|
||
override def load(): Unit = { | ||
// TODO #9 Load from the disk | ||
override def load(filePath: String): Unit = { | ||
clear() | ||
val ois = new ObjectInputStream(new FileInputStream(filePath)) | ||
val readStateMachines = ois.readObject.asInstanceOf[IdMap[GuiStateMachine]] | ||
ois.close | ||
stateMachines = readStateMachines | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/test/scala/de/retest/guistatemachine/api/ActionSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package de.retest.guistatemachine.api | ||
|
||
import org.scalatest.{Matchers, WordSpec} | ||
|
||
class ActionSpec extends WordSpec with Matchers { | ||
|
||
"Action" should { | ||
"equal and not equal" in { | ||
val action0 = Action(Id(0)) | ||
val action1 = Action(Id(1)) | ||
action0.equals(action0) shouldEqual true | ||
action0.equals(action1) shouldEqual false | ||
} | ||
|
||
"toString" in { | ||
val action0 = Action(Id(0)) | ||
action0.toString shouldEqual "Action(Id(0))" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.