小编dSt*_*lle的帖子

使用libgdx,如何将文本和图像添加到ScrollPane?

这是一段代码片段.

itemList = new List(skin, "ariel.32.white");
String[] tmpInv = new String[b+1];
tmpInv[0] = "<Empty>";
a++;
for (Entry<String, String> entry : inventoryItems.entrySet()) {
    tmpInv[a] = entry.getKey(); 
    a++;
    //String key = entry.getKey();
    //Object value = entry.getValue();
    // ...
}
Arrays.sort(tmpInv);

itemList.setItems(tmpInv);

inventoryPane  = new ScrollPane(itemList, skin);
Run Code Online (Sandbox Code Playgroud)

这是我得到的,它工作正常.我想在每个项目前面添加描述性图标,但我似乎无法让它工作.我还需要一些方法来获取添加后所选内容的名称.目前我用

itemlist.getSelectedIndex();
Run Code Online (Sandbox Code Playgroud)

结果

inline image scrollpane libgdx scene2d

8
推荐指数
1
解决办法
3985
查看次数

在无头LibGDX单元测试中创建纹理

我正在使用LibGDX无头后端来运行jUnit测试.这适用于某些测试,但如果我尝试创建一个new Texture('myTexture.png');,我会得到一个NullPointerException.确切的错误是:

java.lang.NullPointerException
    at com.badlogic.gdx.graphics.GLTexture.createGLHandle(GLTexture.java:207)
Run Code Online (Sandbox Code Playgroud)

为了简单起见,我创建了一个除了加载纹理之外什么都不做的方法:

public class TextureLoader {
    public Texture load(){
        return new Texture("badlogic.jpg");
    }
}
Run Code Online (Sandbox Code Playgroud)

然后,我的测试类看起来像这样:

public class TextureTest {

    @Before
    public void before(){
        final HeadlessApplicationConfiguration config = new HeadlessApplicationConfiguration();
        new HeadlessApplication(new ApplicationListener() {
            // Override necessary methods
            ...
        }, config);
    }

    @Test
    public void shouldCreateTexture() {
        TextureLoader loader = new TextureLoader();
        assertNotNull( loader.load() );
    }
}
Run Code Online (Sandbox Code Playgroud)

这个方法在我的实际应用程序中正常工作,而不是在单元测试中.

如何使用HeadlessApplication该类加载纹理?

opengl junit headless libgdx

8
推荐指数
1
解决办法
1539
查看次数

在ruby中是否有针对ISO 8601的综合库/模块?

是否已经实现了红宝石中ISO 8601标准的所有日期,时间,持续时间和间隔使用?我的意思是类似于一个类,你可以在其中设置和获取详细信息,如年,月,日,day_of_the_week,周,小时,分钟,is_duration?,has_recurrence?等等也可以设置并输出到字符串?

ruby recurrence datetime duration iso8601

6
推荐指数
1
解决办法
1196
查看次数

错误:现场作业需要类型为“org.springframework.batch.core.Job”的 bean,但无法找到

我是 Spring Batch 的初学者,我用它开发了一个简单的项目。我收到错误。

Description:
Field job in com.example.demo.DemoApplication required a bean of type 
'org.springframework.batch.core.Job' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.batch.core.Job' in your 
configuration.
Run Code Online (Sandbox Code Playgroud)

这是我的代码,我只有一个类:

Description:
Field job in com.example.demo.DemoApplication required a bean of type 
'org.springframework.batch.core.Job' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.batch.core.Job' in your 
configuration.
Run Code Online (Sandbox Code Playgroud)

感谢您帮助我找到此错误的主要原因

spring-batch spring-boot

6
推荐指数
1
解决办法
2万
查看次数

使用 H2 数据库进行单元测试

我开始使用 H2 数据库编写一些单元测试。

因此,我想从我的@Entity 创建一个表。

但是,我总是收到以下错误消息:

12:40:13.635 [main] WARN org.springframework.context.support.GenericApplicationContext - 上下文初始化期间遇到异常 - 取消刷新尝试:org.springframework.beans.factory.BeanCreationException:创建名称为“dataSource”的 bean 时出错.wrk.fmd.config.JpaConfigTest:通过工厂方法实例化Bean失败;

未找到表“ROLLETEST”;SQL语句:

插入 RolleTest(created_at, bezeichnung) VALUES (now(), 'ADMIN') [42102-197] java.lang.IllegalStateException:无法加载 ApplicationContext

这是我的课程:

Jpa配置测试

@Configuration
@EnableJpaRepositories
@PropertySource("application.propertiesTest")
@EnableTransactionManagement
public class JpaConfigTest {

    @Autowired
    private Environment env;
     
    @Bean
    public DataSource dataSource() {
        DataSource dataSource = new DriverManagerDataSource("jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1", "sa", null);
        new ResourceDatabasePopulator(new ClassPathResource("/import-test.sql")).execute(dataSource);
 
        return dataSource;
    }
}
Run Code Online (Sandbox Code Playgroud)

内存数据库测试:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(
  classes = { JpaConfigTest.class }, 
  loader = AnnotationConfigContextLoader.class)
@Transactional
@WebMvcTest
public class InMemoryDbTest {
     
    @Resource
    private StudentRepository studentRepository; …
Run Code Online (Sandbox Code Playgroud)

java junit spring h2 junit4

5
推荐指数
1
解决办法
2万
查看次数

Kotlin 如何在参数中模拟函数

我试图用测试来覆盖演示者。演示者用例作为数据源。用例的 Execute 方法具有以下结构:fun execute(params: TInput? = null, onNext: (TOutput) -> Unit, onError: (Throwable) -> Unit).

我的问题是如何从 onNext 和 onError 模拟发射?

这是我的 PresenterTest:

class AssignmentsPresenterTest : UnitTest() {

    @Mock lateinit var dataRepository: IDataRepository
    @Mock lateinit var viewState: AssignmentsView

    lateinit var execute: ExecuteUseCase
    lateinit var presenter: AssignmentsPresenter


    @Before fun setUp() {
        execute = ExecuteUseCase(dataRepository)
        presenter = AssignmentsPresenter()
        presenter.attachView(viewState)
    }

    @Test fun `should return list of assignments`() {
        given {
            execute.execute(anyVararg(), { }, { })
        }.willReturn(anyVararg())
    }
}
Run Code Online (Sandbox Code Playgroud)

演示者代码:

@InjectViewState
class …
Run Code Online (Sandbox Code Playgroud)

junit android mockito kotlin

0
推荐指数
1
解决办法
5077
查看次数