forked from vmware-archive/xenon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce "TestRequestSender" to provide send operation API for test. The change also includes exception handling(convert checked exception to unchecked). This will be an ongoing effort to replace/cleanup existing tests. As a first example, `TestUserService` has been updated to use new API. Change-Id: I11f237eb34c57c7d5f12461d99329ceabf9c3ccc
- Loading branch information
Showing
5 changed files
with
361 additions
and
90 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
xenon-common/src/test/java/com/vmware/xenon/common/test/ExceptionTestUtils.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,47 @@ | ||
/* | ||
* Copyright (c) 2014-2016 VMware, Inc. All Rights Reserved. | ||
* | ||
* Licensed 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 com.vmware.xenon.common.test; | ||
|
||
/** | ||
* Utility class for handling java exceptions for test. | ||
*/ | ||
public class ExceptionTestUtils { | ||
private ExceptionTestUtils() { | ||
} | ||
|
||
/** | ||
* Throw any {@link Throwable} as unchecked exception. | ||
* This does not wrap the {@link Throwable}, rather uses java trick to throw it as is. | ||
* TODO: more documentation | ||
*/ | ||
public static RuntimeException throwAsUnchecked(Throwable throwable) { | ||
throwsUnchecked(throwable); | ||
|
||
// allowing this method to be used with return statement. this line will never be executed. | ||
return null; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private static <T extends Exception> void throwsUnchecked(Throwable throwable) throws T { | ||
throw (T) throwable; | ||
} | ||
|
||
public static void executeSafely(ExecutableBlock block) { | ||
try { | ||
block.execute(); | ||
} catch (Throwable throwable) { | ||
throwsUnchecked(throwable); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
xenon-common/src/test/java/com/vmware/xenon/common/test/ExecutableBlock.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,22 @@ | ||
/* | ||
* Copyright (c) 2014-2016 VMware, Inc. All Rights Reserved. | ||
* | ||
* Licensed 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 com.vmware.xenon.common.test; | ||
|
||
/** | ||
* Represent code block that may throw {@link Throwable} | ||
*/ | ||
@FunctionalInterface | ||
public interface ExecutableBlock { | ||
void execute() throws Throwable; | ||
} |
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.