我们正在使用Spring实现REST API(4.1.1.).对于某些HTTP请求,我们希望返回一个没有正文作为响应的头.但是,使用ResponseEntity<Void>似乎不起作用.使用MockMvc测试调用时,将返回406(不可接受).使用ResponseEntity<String>没有参数值(new ResponseEntity<String>( HttpStatus.NOT_FOUND ))工作正常.
方法:
@RequestMapping( method = RequestMethod.HEAD, value = Constants.KEY )
public ResponseEntity<Void> taxonomyPackageExists( @PathVariable final String key ) {
LOG.debug( "taxonomyPackageExists queried with key: {0}", key ); //$NON-NLS-1$
final TaxonomyKey taxonomyKey = TaxonomyKey.fromString( key );
LOG.debug( "Taxonomy key created: {0}", taxonomyKey ); //$NON-NLS-1$
if ( this.xbrlInstanceValidator.taxonomyPackageExists( taxonomyKey ) ) {
LOG.debug( "Taxonomy package with key: {0} exists.", taxonomyKey ); //$NON-NLS-1$
return new ResponseEntity<Void>( HttpStatus.OK );
} else { …Run Code Online (Sandbox Code Playgroud) 我正面临Android MediaPlayer类的一个奇怪问题.我正在使用MediaPlayer在VideoView中播放视频.这适用于所有设备,除了搭载Android 4.2.2的Samsung GT-I8200N.好吧,我实际上已经听说过这些视频无法在某些三星4.1.X设备上播放的报道,但是我无法将这些视频放到其中一个设备上.我在Google Android模拟器中没有任何错误.
更详细一点:带有Android 4.2.2的三星GT-I8200N能够以一个片段播放视频,但不能在另一个片段中播放,即使使用相同的代码播放视频.当视频开始时,除了视频应该在的空间外,整个屏幕都会闪烁黑色.
这是代码:
public abstract class AbstractSignVideoFragment extends Fragment {
private static final double MAXMIMUM_VIDEO_HEIGHT_ON_LANDSCAPE = 0.4;
private static final double MAXIMUM_VIDEO_WIDTH_ON_PORTRAIT = 0.8;
private final static String TAG = AbstractSignVideoFragment.class.getSimpleName();
private static final String ANDROID_RESOURCE = "android.resource://";
private static final String SLASH = "/";
private static final String RAW = "raw";
protected VideoView videoView;
protected ProgressBar progressBar;
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
protected boolean isSetupVideoViewSuccessful(final Sign sign, final SOUND sound, final CONTROLS controls) {
initializeMediaController();
final String …Run Code Online (Sandbox Code Playgroud) 我在使用检测的Android单元测试中使用JUnit4 @BeforeClass注释时遇到了问题(我正在使用Espresso GUI测试库).一旦我添加了带@BeforeClass注释的测试,Android Studio 1.5.1就不会运行任何测试,而只是打印"空测试套件".我没有使用测试套件.我搜索了这个网站和网站,但找不到解决方案.我认为在@BeforeClass方法中调用的代码实际上失败(TDD)可能是一个问题,但是当在正常测试用例中工作的代码放入带@BeforeClass注释的方法时,甚至会发生此错误.
谢谢.
更新:检查logcat输出后,正如一位评论者建议的那样,问题似乎是问题是没有启动任何活动:没有找到任何活动.你忘了调用启动活动getActivity()或startActivitySync或类似的?
我该怎么做?我不能使用该ActivityTestRule字段,因为带@BeforeClass注释的方法是静态的.
也许我只是@BeforeClass以错误的方式使用注释.我的印象是你可以使用这个注释在测试类中的所有其他测试之前执行测试.我基本上是在寻找TestNG注释的替代品"dependsOnMethods".也许我最好@FixMethodOrder(MethodSorters.NAME_ASCENDING)在测试类上使用注释并将第一个测试用例重命名为aaa_my_testcase.
有人可以对此发表评论吗?谢谢.
重新提出问题的标题.
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.Espresso.pressBack;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.isEnabled;
import static …Run Code Online (Sandbox Code Playgroud) 是否可以将 Quarkus 中的 QuarkusTestExtension 与 AssertJ 中的 SoftAssertionsExtension 结合使用?
我想运行 Quarkus 测试,在使用 AssertJ 的软断言的测试之后隐式调用 softAssertions.assertAll() 。不过,我总是遇到例外。
语境:
我正在使用io.quarkus:quarkus-junit5:1.13.3.Final和org.assertj:assertj-core:3.21.0。
这是我创建的注释。
@ExtendWith({SoftAssertionsExtension.class, QuarkusTestExtension.class})
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface QuarkusAssertJTest {
}
Run Code Online (Sandbox Code Playgroud)
这是我的测试。受到 AssertJ 文档的启发。
@QuarkusAssertJTest
class MyTestClass {
@Test
void assertThatSoftAssertionsWork(SoftAssertions softly) {
softly.assertThat("George Martin").as("great authors").isEqualTo("JRR Tolkien");
softly.assertThat(42).as("response to Everything").isGreaterThan(100);
softly.assertThat("Gandalf").isEqualTo("Sauron");
}
Run Code Online (Sandbox Code Playgroud)
当我运行此测试时,出现以下异常。
org.junit.jupiter.api.extension.TestInstantiationException: Failed to create test instance
at io.quarkus.test.junit.QuarkusTestExtension.initTestState(QuarkusTestExtension.java:828)
at io.quarkus.test.junit.QuarkusTestExtension.interceptTestClassConstructor(QuarkusTestExtension.java:792)
at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
at org.junit.jupiter.api.extension.InvocationInterceptor.interceptTestClassConstructor(InvocationInterceptor.java:72)
at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37) …Run Code Online (Sandbox Code Playgroud)