added tests for ability extension functionality
This commit is contained in:
parent
a05988f5b4
commit
159de38b29
@ -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();
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user