-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved failsafe ness of WebDriver properties
- Loading branch information
Mike Reiche
committed
Oct 19, 2021
1 parent
552756c
commit 089203b
Showing
9 changed files
with
169 additions
and
49 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
25 changes: 25 additions & 0 deletions
25
core/src/main/java/eu/tsystems/mms/tic/testframework/utils/DefaultExecutionUtils.java
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,25 @@ | ||
/* | ||
* Testerra | ||
* | ||
* (C) 2021, Mike Reiche, T-Systems MMS GmbH, Deutsche Telekom AG | ||
* | ||
* Deutsche Telekom AG and all other contributors / | ||
* copyright owners license this file to you under the Apache | ||
* License, Version 2.0 (the "License"); you may not use this | ||
* file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package eu.tsystems.mms.tic.testframework.utils; | ||
|
||
public class DefaultExecutionUtils implements ExecutionUtils { | ||
} |
38 changes: 38 additions & 0 deletions
38
core/src/main/java/eu/tsystems/mms/tic/testframework/utils/ExecutionUtils.java
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,38 @@ | ||
/* | ||
* Testerra | ||
* | ||
* (C) 2021, Mike Reiche, T-Systems MMS GmbH, Deutsche Telekom AG | ||
* | ||
* Deutsche Telekom AG and all other contributors / | ||
* copyright owners license this file to you under the Apache | ||
* License, Version 2.0 (the "License"); you may not use this | ||
* file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package eu.tsystems.mms.tic.testframework.utils; | ||
|
||
import eu.tsystems.mms.tic.testframework.logging.Loggable; | ||
import java.util.Optional; | ||
import java.util.function.Supplier; | ||
|
||
public interface ExecutionUtils extends Loggable { | ||
default <T> Optional<T> getFailsafe(Supplier<T> supplier) { | ||
try { | ||
T returnVal = supplier.get(); | ||
return Optional.ofNullable(returnVal); | ||
} catch (Throwable e) { | ||
log().warn("Unable to supply property", e); | ||
return Optional.empty(); | ||
} | ||
} | ||
} |
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
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
65 changes: 65 additions & 0 deletions
65
...-tests/src/test/java/eu/tsystems/mms/tic/testframework/test/utils/ExecutionUtilsTest.java
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,65 @@ | ||
/* | ||
* Testerra | ||
* | ||
* (C) 2021, Mike Reiche, T-Systems MMS GmbH, Deutsche Telekom AG | ||
* | ||
* Deutsche Telekom AG and all other contributors / | ||
* copyright owners license this file to you under the Apache | ||
* License, Version 2.0 (the "License"); you may not use this | ||
* file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package eu.tsystems.mms.tic.testframework.test.utils; | ||
|
||
import eu.tsystems.mms.tic.testframework.common.Testerra; | ||
import eu.tsystems.mms.tic.testframework.internal.utils.ExceptionUtils; | ||
import eu.tsystems.mms.tic.testframework.testing.TesterraTest; | ||
import eu.tsystems.mms.tic.testframework.utils.ExecutionUtils; | ||
import java.util.Optional; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
public class ExecutionUtilsTest extends TesterraTest { | ||
|
||
@Test | ||
public void test_getFailsafe() { | ||
String expected = "katze"; | ||
ExecutionUtils executionUtils = Testerra.getInjector().getInstance(ExecutionUtils.class); | ||
Optional<Object> failsafe = executionUtils.getFailsafe(() -> { | ||
return expected; | ||
}); | ||
|
||
Assert.assertEquals(failsafe.get(), expected); | ||
} | ||
|
||
@Test | ||
public void test_getFailsafe_null() { | ||
ExecutionUtils executionUtils = Testerra.getInjector().getInstance(ExecutionUtils.class); | ||
Optional<Object> failsafe = executionUtils.getFailsafe(() -> { | ||
return null; | ||
}); | ||
|
||
Assert.assertFalse(failsafe.isPresent()); | ||
} | ||
|
||
@Test | ||
public void test_getFailsafe_NPE() { | ||
ExecutionUtils executionUtils = Testerra.getInjector().getInstance(ExecutionUtils.class); | ||
Optional<Object> failsafe = executionUtils.getFailsafe(() -> { | ||
String expected = null; | ||
return expected.trim(); | ||
}); | ||
|
||
Assert.assertFalse(failsafe.isPresent()); | ||
} | ||
} |