added tests for ability extension functionality

This commit is contained in:
romangraef 2018-11-10 22:07:41 +01:00
parent a05988f5b4
commit 159de38b29
No known key found for this signature in database
GPG Key ID: 5FF81499D091C626
3 changed files with 103 additions and 0 deletions

View File

@ -0,0 +1,26 @@
package org.telegram.abilitybots.api.bot;
import org.telegram.abilitybots.api.objects.Ability;
import org.telegram.abilitybots.api.util.AbilityExtension;
import static org.telegram.abilitybots.api.objects.Locality.ALL;
import static org.telegram.abilitybots.api.objects.Privacy.PUBLIC;
public class AbilityBotExtension implements AbilityExtension {
private String name;
public AbilityBotExtension(String name) {
this.name = name;
}
public Ability abc() {
return Ability.builder()
.name(this.name + "0abc")
.info("Test ability")
.locality(ALL)
.privacy(PUBLIC)
.action(messageContext -> {
})
.build();
}
}

View File

@ -0,0 +1,36 @@
package org.telegram.abilitybots.api.bot;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.telegram.abilitybots.api.objects.Ability;
import static junit.framework.TestCase.assertTrue;
public class ExtensionTest {
private ExtensionUsingBot bot;
@Before
public void setUp() {
bot = new ExtensionUsingBot();
}
@After
public void teardown() {
bot = null;
}
@Test
public void methodReturningAbilities() {
assertTrue("Failed to find Ability in directly declared in root extension/bot", hasAbilityNamed("direct"));
assertTrue("Failed to find Ability in directly declared in extension returned by method returning the AbilityExtension class", hasAbilityNamed("returningSuperClass0abc"));
assertTrue("Failed to find Ability in directly declared in extension returned by method returning the AbilityExtension subclass", hasAbilityNamed("returningSubClass0abc"));
}
private boolean hasAbilityNamed(String name) {
return bot.abilities().values().stream().map(Ability::name).anyMatch(name::equals);
}
}

View File

@ -0,0 +1,41 @@
package org.telegram.abilitybots.api.bot;
import org.telegram.abilitybots.api.objects.Ability;
import org.telegram.abilitybots.api.util.AbilityExtension;
import static org.telegram.abilitybots.api.db.MapDBContext.offlineInstance;
import static org.telegram.abilitybots.api.objects.Locality.ALL;
import static org.telegram.abilitybots.api.objects.Privacy.PUBLIC;
public class ExtensionUsingBot extends AbilityBot {
public ExtensionUsingBot() {
super("", "", offlineInstance("testing"));
}
@Override
public int creatorId() {
return 0;
}
public AbilityBotExtension methodReturningExtensionSubClass() {
return new AbilityBotExtension("returningSubClass");
}
public AbilityExtension methodReturningExtensionSuperClass() {
return new AbilityBotExtension("returningSuperClass");
}
public Ability methodReturningAbility() {
return Ability.builder()
.name("direct")
.info("Test ability")
.locality(ALL)
.privacy(PUBLIC)
.action(messageContext -> {
})
.build();
}
}