Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use MockTextTerminal #33

Open
cdprete opened this issue Nov 15, 2021 · 7 comments
Open

How to use MockTextTerminal #33

cdprete opened this issue Nov 15, 2021 · 7 comments

Comments

@cdprete
Copy link

cdprete commented Nov 15, 2021

Hi.
Can you please provide some documentation or guidance on how to use the MockTextTerminal?
I would like to unit-test my business logic and the example in the repository with the Robot is not really adequate for unit tests (given the definition of unit test).

Kind regards and thanks in advance.

@siordache
Copy link
Member

Hi! What testing framework do you use? JUnit4? JUnit5? Spock? TestNG?

@siordache
Copy link
Member

I put up an example project that shows how to use the MockTextTerminal with JUnit 5.

@cdprete
Copy link
Author

cdprete commented Nov 16, 2021

Hi.
I'm using JUnit 5, but even JUnit 4 is fine if for you is better (I can convert the code accordingly).

@siordache
Copy link
Member

Did you see the example project I put up yesterday?

@cdprete
Copy link
Author

cdprete commented Nov 16, 2021

Sorry, I read just the comment about the test framework and I missed the next one ;)
I'll have a look at it.

Thank you.

@cdprete
Copy link
Author

cdprete commented Nov 19, 2021

Hi.
I can confirm the example works, but how to test prompt properties? For example, that a proper color is set?


Nevermind. I can of course fetch the properties and assert that they're there.

@cdprete cdprete closed this as completed Nov 19, 2021
@cdprete cdprete reopened this Nov 19, 2021
@cdprete
Copy link
Author

cdprete commented Nov 19, 2021

Hi.
I've just realized I cannot really assert what properties have been set when using executeWithPropertiesConfigurator.
Do you have any way to test this?

Edit:
For now, I've come up with

@Override
public void executeWithPropertiesConfigurator(Consumer<TerminalProperties<?>> propertiesConfigurator, Consumer<TextTerminal<MockTextTerminal>> action) {
    final Consumer<TerminalProperties<?>> propertiesHolder = terminalProperties -> {
        propertiesConfigurator.accept(terminalProperties);
        lastUsedProperties = new TerminalProperties<>(this);
        terminalProperties.getAllKeys().forEach(key -> lastUsedProperties.put(key, terminalProperties.getString(key)));
    };
    super.executeWithPropertiesConfigurator(propertiesHolder, action);
}

which works but it's not super nice (and not thread safe).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants