我正在使用兼容性库中的ViewPager.我已经巧妙地让它显示了几个我可以翻阅的视图.
但是,我很难弄清楚如何使用一组新视图更新ViewPager.
我已经试过各种事情就像调用mAdapter.notifyDataSetChanged(),mViewPager.invalidate()即使每次都创建我想用一个新的数据列表中的一个全新的适配器.
没有任何帮助,文本视图与原始数据保持不变.
更新: 我做了一个小测试项目,我几乎能够更新视图.我将粘贴下面的课程.
然而,似乎没有更新的是第二个视图,"B"仍然存在,按下更新按钮后应显示"Y".
public class ViewPagerBugActivity extends Activity {
private ViewPager myViewPager;
private List<String> data;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
data = new ArrayList<String>();
data.add("A");
data.add("B");
data.add("C");
myViewPager = (ViewPager) findViewById(R.id.my_view_pager);
myViewPager.setAdapter(new MyViewPagerAdapter(this, data));
Button updateButton = (Button) findViewById(R.id.update_button);
updateButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
updateViewPager();
}
});
}
private void updateViewPager() {
data.clear();
data.add("X");
data.add("Y");
data.add("Z");
myViewPager.getAdapter().notifyDataSetChanged();
}
private class MyViewPagerAdapter extends PagerAdapter {
private …Run Code Online (Sandbox Code Playgroud) 我找到了Hibernate Annotations的脚,我遇到了一个问题,我希望有人可以提供帮助.
我有2个实体,Section和ScopeTopic.Section有一个List类成员,所以一对多关系.当我运行我的单元测试时,我得到了这个异常:
使用@OneToMany或@ManyToMany定位未映射的类:com.xxx.domain.Section.scopeTopic [com.xxx.domain.ScopeTopic]
我会假设错误意味着我的ScopeTopic实体未映射到表?我看不到我做错了.以下是实体类:
@Entity
public class Section {
private Long id;
private List<ScopeTopic> scopeTopics;
public Section() {}
@Id
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@OneToMany
@JoinTable(name = "section_scope", joinColumns = {@JoinColumn(name="section_id")},
inverseJoinColumns = {@JoinColumn(name="scope_topic_id")} )
public List<ScopeTopic> getScopeTopic() {
return scopeTopic;
}
public void setScopeTopic(List<ScopeTopic> scopeTopic) {
this.scopeTopic = scopeTopic;
}
}
Run Code Online (Sandbox Code Playgroud)
@Entity
@Table(name = "scope_topic")
public class ScopeTopic {
private Long id;
private String topic;
public …Run Code Online (Sandbox Code Playgroud) 我最近在Hibernate 3.5和Spring 3上做过一些工作,我对Hibernate很新,并且认为HibernateDaoSupportSpring中的类使我的域类很好用,也很容易使用Hibernate.
但是,在搜索一个不相关的问题时,我看到有人提到这HibernateDaoSupport不是使用Spring和Hibernate的最佳方法.任何人都可以阐明:
我正在尝试使用一个ViewPager内部ScrollView,但ViewPager不会出现.如果我删除ScrollView了ViewPager显示正常.
我用以下方法创建了一个简单的测试项目:
main.xml布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.support.v4.view.ViewPager
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/viewpager" />
</ScrollView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
活动类:
public class ScrollViewWithViewPagerActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ViewPager vp = (ViewPager) findViewById(R.id.viewpager);
vp.setAdapter(new MyPagerAdapter(this));
}
}
class MyPagerAdapter extends PagerAdapter {
private Context ctx;
public MyPagerAdapter(Context context) {
ctx = context;
}
@Override
public int getCount() {
return 2;
}
@Override …Run Code Online (Sandbox Code Playgroud) 我有以下简单的控制器来捕获任何意外的异常:
@ControllerAdvice
public class ExceptionController {
@ExceptionHandler(Throwable.class)
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
@ResponseBody
public ResponseEntity handleException(Throwable ex) {
return ResponseEntityFactory.internalServerErrorResponse("Unexpected error has occurred.", ex);
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用Spring MVC Test框架编写集成测试.这是我到目前为止:
@RunWith(MockitoJUnitRunner.class)
public class ExceptionControllerTest {
private MockMvc mockMvc;
@Mock
private StatusController statusController;
@Before
public void setup() {
this.mockMvc = MockMvcBuilders.standaloneSetup(new ExceptionController(), statusController).build();
}
@Test
public void checkUnexpectedExceptionsAreCaughtAndStatusCode500IsReturnedInResponse() throws Exception {
when(statusController.checkHealth()).thenThrow(new RuntimeException("Unexpected Exception"));
mockMvc.perform(get("/api/status"))
.andDo(print())
.andExpect(status().isInternalServerError())
.andExpect(jsonPath("$.error").value("Unexpected Exception"));
}
}
Run Code Online (Sandbox Code Playgroud)
我在Spring MVC基础结构中注册了ExceptionController和一个模拟StatusController.在测试方法中,我设置了从StatusController抛出异常的期望.
抛出异常,但ExceptionController没有处理它.
我希望能够测试ExceptionController获取异常并返回适当的响应.
有关为什么这不起作用以及我应该如何进行此类测试的任何想法?
谢谢.
我正在尝试使用Maven将我的测试类打包到一个带有依赖项的可执行jar中,但我很难做到这一点.
到目前为止这是我的pom.xml:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.c0deattack</groupId>
<artifactId>executable-tests</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>executable-tests</name>
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.21.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>cucumber-tests</finalName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>cucumber.cli.Main</mainClass>
</transformer>
</transformers>
<artifactSet>
<includes>
<include>info.cukes:*</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.c0deattack</groupId>
<artifactId>executable-tests</artifactId>
<version>1.0</version>
<type>test-jar</type>
</dependency>
</dependencies>
</plugin> …Run Code Online (Sandbox Code Playgroud) 我有一个拥有JAVA_HOME环境变量的Jenkins Slave(一台Windows PC).我在Slave上更新了Java版本,所以我也更新了环境变量.
当我通过Jenkins web界面查看此Slave的系统属性时,该JAVA_HOME属性被报告为旧属性.
echo %PATH%在Windows PC上运行会显示正确的值.println System.getenv("PATH")在Slave的Jenkins Node脚本控制台上运行会显示旧的JAVA_HOME值.
我试图删除并再次添加Slave并重新启动Jenkins服务器.旧的价值仍未更新.
有什么想法吗?
当涉及隐式参数时,我在尝试理解如何在Scala中编写测试时遇到了一些困难.
我有以下(简短版本)我的代码和测试:
实施(Scala 2.10,Spray和Akka):
import spray.httpx.SprayJsonSupport._
import com.acme.ResultJsonFormat._
case class PerRequestIndexingActor(ctx: RequestContext) extends Actor with ActorLogging {
def receive = LoggingReceive {
case AddToIndexRequestCompleted(result) =>
ctx.complete(result)
context.stop(self)
}
}
object ResultJsonFormat extends DefaultJsonProtocol {
implicit val resultFormat = jsonFormat2(Result)
}
case class Result(code: Int, message: String)
Run Code Online (Sandbox Code Playgroud)
测试(使用ScalaTest和Mockito):
"Per Request Indexing Actor" should {
"send the HTTP Response when AddToIndexRequestCompleted message is received" in {
val request = mock[RequestContext]
val result = mock[Result]
val perRequestIndexingActor = TestActorRef(Props(new PerRequestIndexingActor(request)))
perRequestIndexingActor ! AddToIndexRequestCompleted(result) …Run Code Online (Sandbox Code Playgroud) 我正在设置Jenkins以取代我们当前的TeamCity CI构建.
我创建了一个自由风格的软件项目,以便我可以执行shell脚本.Shell脚本运行mvn命令.
但构建失败抱怨无法找到'mvn'命令.
我认为这是因为Jenkins在不同的shell中运行构建,它在路径上没有Maven.
我的问题是; 如何添加路径以便在我的Shell脚本中找到"mvn"?我环顾四周,但无法找到合适的地方.
谢谢你的时间.
我想弄清楚如何为我要编写的服务编写我的测试用例.
该服务将使用HTTPBuilder从某个URL请求响应.HTTPBuilder请求只需要检查响应是否成功.服务实现将是如此简单:
boolean isOk() {
httpBuilder.request(GET) {
response.success = { return true }
response.failure = { return false }
}
}
Run Code Online (Sandbox Code Playgroud)
所以,我希望能够模拟HTTPBuilder,以便我可以在我的测试中将响应设置为成功/失败,这样我就可以断言我的服务isOk方法在响应成功时返回True,而当响应是失败.
任何人都可以帮助我如何模拟HTTPBuilder请求并在GroovyTestCase中设置响应?
android ×2
hibernate ×2
hudson ×2
jenkins ×2
spring ×2
unit-testing ×2
dependencies ×1
groovy ×1
httpbuilder ×1
java ×1
java-home ×1
jpa ×1
maven ×1
mockito ×1
scala ×1
scalatest ×1
scrollview ×1
spray ×1
spring-mvc ×1
testing ×1