method2testcases
stringlengths
118
6.63k
### Question: AbstractCommonFunctions extends io.github.wysohn.triggerreactor.core.manager.trigger.share.CommonFunctions implements SelfReference { public void addLore(ItemStack IS, String lore) { ItemMeta IM = IS.getItemMeta(); if (IM == null) IM = Bukkit.getItemFactory().getItemMeta(IS.getType()); if (IM == null) return; List<String> lores = IM.getLore(); if (lores == null) lores = new ArrayList<>(); lores.add(color(lore)); IM.setLore(lores); IS.setItemMeta(IM); } AbstractCommonFunctions(TriggerReactorCore plugin); Plugin plugin(String name); @Deprecated abstract boolean takeItem(Player player, int id, int amount); abstract boolean takeItem(Player player, String id, int amount); @Deprecated abstract boolean takeItem(Player player, int id, int amount, int data); abstract boolean takeItem(Player player, String id, int amount, int data); boolean takeItem(Player player, ItemStack IS, int amount); Location location(String world, double x, double y, double z); Location location(String world, double x, double y, double z, double yaw, double pitch); Block block(String world, int x, int y, int z); boolean locationEqual(Location loc1, Location loc2); abstract PotionEffect makePotionEffect(String EffectType, int duration, int amplifier, boolean ambient, boolean particles, Color color); Player player(String name); OfflinePlayer oplayer(String name); abstract Collection<? extends Player> getPlayers(); String currentArea(Entity entity); String currentAreaAt(Location location); String[] currentAreas(Entity entity); String[] currentAreasAt(Location location); List<Entity> getEntitiesInArea(String areaTriggerName); String color(String str); Color bukkitColor(int red, int green, int blue); @Deprecated abstract ItemStack item(int type, int amount, int data); abstract ItemStack item(String type, int amount, int data); @Deprecated abstract ItemStack item(int type, int amount); abstract ItemStack item(String type, int amount); String getItemTitle(ItemStack IS); void setItemTitle(ItemStack IS, String title); boolean hasLore(ItemStack IS, String lore); String getLore(ItemStack IS, int index); void addLore(ItemStack IS, String lore); void setLore(ItemStack IS, int index, String lore); void removeLore(ItemStack IS, int index); void clearLore(ItemStack IS); int loreSize(ItemStack IS); @Override String formatCurrency(double money, String locale1, String locale2); @Override String formatCurrency(double money); Block getTargetBlock(Player player, int maxDistance); ItemStack headForName(String targetName); abstract ItemStack headForName(String targetName, int amount); abstract ItemStack headForValue(String textureValue); }### Answer: @Test public void testAddLore() { List<String> lores = new ArrayList<>(); lores.add("abab"); lores.add("cdcd"); ItemStack IS = new ItemStack(Material.STONE); Mockito.doAnswer(invocation -> lores).when(mockItemMeta).getLore(); fn.addLore(IS, "efef"); Assert.assertEquals(3, lores.size()); Assert.assertEquals("efef", lores.get(lores.size() - 1)); }
### Question: AbstractCommonFunctions extends io.github.wysohn.triggerreactor.core.manager.trigger.share.CommonFunctions implements SelfReference { public void setLore(ItemStack IS, int index, String lore) { ItemMeta IM = IS.getItemMeta(); if (IM == null) IM = Bukkit.getItemFactory().getItemMeta(IS.getType()); if (IM == null) return; List<String> lores = IM.getLore(); if (lores == null) lores = new ArrayList<>(); while (index >= lores.size()) lores.add(""); lores.set(index, color(lore)); IM.setLore(lores); IS.setItemMeta(IM); } AbstractCommonFunctions(TriggerReactorCore plugin); Plugin plugin(String name); @Deprecated abstract boolean takeItem(Player player, int id, int amount); abstract boolean takeItem(Player player, String id, int amount); @Deprecated abstract boolean takeItem(Player player, int id, int amount, int data); abstract boolean takeItem(Player player, String id, int amount, int data); boolean takeItem(Player player, ItemStack IS, int amount); Location location(String world, double x, double y, double z); Location location(String world, double x, double y, double z, double yaw, double pitch); Block block(String world, int x, int y, int z); boolean locationEqual(Location loc1, Location loc2); abstract PotionEffect makePotionEffect(String EffectType, int duration, int amplifier, boolean ambient, boolean particles, Color color); Player player(String name); OfflinePlayer oplayer(String name); abstract Collection<? extends Player> getPlayers(); String currentArea(Entity entity); String currentAreaAt(Location location); String[] currentAreas(Entity entity); String[] currentAreasAt(Location location); List<Entity> getEntitiesInArea(String areaTriggerName); String color(String str); Color bukkitColor(int red, int green, int blue); @Deprecated abstract ItemStack item(int type, int amount, int data); abstract ItemStack item(String type, int amount, int data); @Deprecated abstract ItemStack item(int type, int amount); abstract ItemStack item(String type, int amount); String getItemTitle(ItemStack IS); void setItemTitle(ItemStack IS, String title); boolean hasLore(ItemStack IS, String lore); String getLore(ItemStack IS, int index); void addLore(ItemStack IS, String lore); void setLore(ItemStack IS, int index, String lore); void removeLore(ItemStack IS, int index); void clearLore(ItemStack IS); int loreSize(ItemStack IS); @Override String formatCurrency(double money, String locale1, String locale2); @Override String formatCurrency(double money); Block getTargetBlock(Player player, int maxDistance); ItemStack headForName(String targetName); abstract ItemStack headForName(String targetName, int amount); abstract ItemStack headForValue(String textureValue); }### Answer: @Test public void testSetLore() { List<String> lores = new ArrayList<>(); lores.add("abab"); lores.add("cdcd"); ItemStack IS = new ItemStack(Material.STONE); Mockito.doAnswer(invocation -> lores).when(mockItemMeta).getLore(); fn.setLore(IS, 0, "pqpq"); Assert.assertEquals("pqpq", lores.get(0)); fn.setLore(IS, 5, "ffee"); Assert.assertEquals(6, lores.size()); Assert.assertEquals("ffee", lores.get(5)); }
### Question: AbstractCommonFunctions extends io.github.wysohn.triggerreactor.core.manager.trigger.share.CommonFunctions implements SelfReference { public void removeLore(ItemStack IS, int index) { ItemMeta IM = IS.getItemMeta(); if (IM == null) IM = Bukkit.getItemFactory().getItemMeta(IS.getType()); if (IM == null) return; List<String> lores = IM.getLore(); if (lores == null) lores = new ArrayList<>(); if (index < 0 || index >= lores.size()) return; lores.remove(index); IM.setLore(lores); IS.setItemMeta(IM); } AbstractCommonFunctions(TriggerReactorCore plugin); Plugin plugin(String name); @Deprecated abstract boolean takeItem(Player player, int id, int amount); abstract boolean takeItem(Player player, String id, int amount); @Deprecated abstract boolean takeItem(Player player, int id, int amount, int data); abstract boolean takeItem(Player player, String id, int amount, int data); boolean takeItem(Player player, ItemStack IS, int amount); Location location(String world, double x, double y, double z); Location location(String world, double x, double y, double z, double yaw, double pitch); Block block(String world, int x, int y, int z); boolean locationEqual(Location loc1, Location loc2); abstract PotionEffect makePotionEffect(String EffectType, int duration, int amplifier, boolean ambient, boolean particles, Color color); Player player(String name); OfflinePlayer oplayer(String name); abstract Collection<? extends Player> getPlayers(); String currentArea(Entity entity); String currentAreaAt(Location location); String[] currentAreas(Entity entity); String[] currentAreasAt(Location location); List<Entity> getEntitiesInArea(String areaTriggerName); String color(String str); Color bukkitColor(int red, int green, int blue); @Deprecated abstract ItemStack item(int type, int amount, int data); abstract ItemStack item(String type, int amount, int data); @Deprecated abstract ItemStack item(int type, int amount); abstract ItemStack item(String type, int amount); String getItemTitle(ItemStack IS); void setItemTitle(ItemStack IS, String title); boolean hasLore(ItemStack IS, String lore); String getLore(ItemStack IS, int index); void addLore(ItemStack IS, String lore); void setLore(ItemStack IS, int index, String lore); void removeLore(ItemStack IS, int index); void clearLore(ItemStack IS); int loreSize(ItemStack IS); @Override String formatCurrency(double money, String locale1, String locale2); @Override String formatCurrency(double money); Block getTargetBlock(Player player, int maxDistance); ItemStack headForName(String targetName); abstract ItemStack headForName(String targetName, int amount); abstract ItemStack headForValue(String textureValue); }### Answer: @Test public void testRemoveLore() { List<String> lores = new ArrayList<>(); lores.add("abab"); lores.add("cdcd"); lores.add("efef"); ItemStack IS = new ItemStack(Material.STONE); Mockito.doAnswer(invocation -> lores).when(mockItemMeta).getLore(); fn.removeLore(IS, 2); Assert.assertEquals(2, lores.size()); Assert.assertFalse(lores.contains("efef")); fn.removeLore(IS, 0); Assert.assertEquals(1, lores.size()); Assert.assertFalse(lores.contains("abab")); Assert.assertEquals("cdcd", lores.get(0)); }
### Question: AbstractCommonFunctions extends io.github.wysohn.triggerreactor.core.manager.trigger.share.CommonFunctions implements SelfReference { public void clearLore(ItemStack IS) { ItemMeta IM = IS.getItemMeta(); if (IM == null) return; IM.setLore(new ArrayList<>()); IS.setItemMeta(IM); } AbstractCommonFunctions(TriggerReactorCore plugin); Plugin plugin(String name); @Deprecated abstract boolean takeItem(Player player, int id, int amount); abstract boolean takeItem(Player player, String id, int amount); @Deprecated abstract boolean takeItem(Player player, int id, int amount, int data); abstract boolean takeItem(Player player, String id, int amount, int data); boolean takeItem(Player player, ItemStack IS, int amount); Location location(String world, double x, double y, double z); Location location(String world, double x, double y, double z, double yaw, double pitch); Block block(String world, int x, int y, int z); boolean locationEqual(Location loc1, Location loc2); abstract PotionEffect makePotionEffect(String EffectType, int duration, int amplifier, boolean ambient, boolean particles, Color color); Player player(String name); OfflinePlayer oplayer(String name); abstract Collection<? extends Player> getPlayers(); String currentArea(Entity entity); String currentAreaAt(Location location); String[] currentAreas(Entity entity); String[] currentAreasAt(Location location); List<Entity> getEntitiesInArea(String areaTriggerName); String color(String str); Color bukkitColor(int red, int green, int blue); @Deprecated abstract ItemStack item(int type, int amount, int data); abstract ItemStack item(String type, int amount, int data); @Deprecated abstract ItemStack item(int type, int amount); abstract ItemStack item(String type, int amount); String getItemTitle(ItemStack IS); void setItemTitle(ItemStack IS, String title); boolean hasLore(ItemStack IS, String lore); String getLore(ItemStack IS, int index); void addLore(ItemStack IS, String lore); void setLore(ItemStack IS, int index, String lore); void removeLore(ItemStack IS, int index); void clearLore(ItemStack IS); int loreSize(ItemStack IS); @Override String formatCurrency(double money, String locale1, String locale2); @Override String formatCurrency(double money); Block getTargetBlock(Player player, int maxDistance); ItemStack headForName(String targetName); abstract ItemStack headForName(String targetName, int amount); abstract ItemStack headForValue(String textureValue); }### Answer: @Test public void testClearLore() { ItemStack IS = new ItemStack(Material.STONE); ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class); fn.clearLore(IS); Mockito.verify(mockItemMeta).setLore(captor.capture()); Assert.assertEquals(0, captor.getValue().size()); }
### Question: AbstractCommonFunctions extends io.github.wysohn.triggerreactor.core.manager.trigger.share.CommonFunctions implements SelfReference { public int loreSize(ItemStack IS) { ItemMeta IM = IS.getItemMeta(); if (IM == null) return 0; List<String> lores = IM.getLore(); if (lores == null) return 0; return lores.size(); } AbstractCommonFunctions(TriggerReactorCore plugin); Plugin plugin(String name); @Deprecated abstract boolean takeItem(Player player, int id, int amount); abstract boolean takeItem(Player player, String id, int amount); @Deprecated abstract boolean takeItem(Player player, int id, int amount, int data); abstract boolean takeItem(Player player, String id, int amount, int data); boolean takeItem(Player player, ItemStack IS, int amount); Location location(String world, double x, double y, double z); Location location(String world, double x, double y, double z, double yaw, double pitch); Block block(String world, int x, int y, int z); boolean locationEqual(Location loc1, Location loc2); abstract PotionEffect makePotionEffect(String EffectType, int duration, int amplifier, boolean ambient, boolean particles, Color color); Player player(String name); OfflinePlayer oplayer(String name); abstract Collection<? extends Player> getPlayers(); String currentArea(Entity entity); String currentAreaAt(Location location); String[] currentAreas(Entity entity); String[] currentAreasAt(Location location); List<Entity> getEntitiesInArea(String areaTriggerName); String color(String str); Color bukkitColor(int red, int green, int blue); @Deprecated abstract ItemStack item(int type, int amount, int data); abstract ItemStack item(String type, int amount, int data); @Deprecated abstract ItemStack item(int type, int amount); abstract ItemStack item(String type, int amount); String getItemTitle(ItemStack IS); void setItemTitle(ItemStack IS, String title); boolean hasLore(ItemStack IS, String lore); String getLore(ItemStack IS, int index); void addLore(ItemStack IS, String lore); void setLore(ItemStack IS, int index, String lore); void removeLore(ItemStack IS, int index); void clearLore(ItemStack IS); int loreSize(ItemStack IS); @Override String formatCurrency(double money, String locale1, String locale2); @Override String formatCurrency(double money); Block getTargetBlock(Player player, int maxDistance); ItemStack headForName(String targetName); abstract ItemStack headForName(String targetName, int amount); abstract ItemStack headForValue(String textureValue); }### Answer: @Test public void testLoreSize() { List<String> lores = new ArrayList<>(); lores.add("abab"); lores.add("cdcd"); lores.add("efef"); ItemStack IS = new ItemStack(Material.STONE); Mockito.doAnswer(invocation -> lores).when(mockItemMeta).getLore(); Assert.assertEquals(3, fn.loreSize(IS)); }
### Question: AbstractCommonFunctions extends io.github.wysohn.triggerreactor.core.manager.trigger.share.CommonFunctions implements SelfReference { @Override public String formatCurrency(double money, String locale1, String locale2) { Locale locale = new Locale(locale1, locale2); NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(locale); return currencyFormatter.format(money); } AbstractCommonFunctions(TriggerReactorCore plugin); Plugin plugin(String name); @Deprecated abstract boolean takeItem(Player player, int id, int amount); abstract boolean takeItem(Player player, String id, int amount); @Deprecated abstract boolean takeItem(Player player, int id, int amount, int data); abstract boolean takeItem(Player player, String id, int amount, int data); boolean takeItem(Player player, ItemStack IS, int amount); Location location(String world, double x, double y, double z); Location location(String world, double x, double y, double z, double yaw, double pitch); Block block(String world, int x, int y, int z); boolean locationEqual(Location loc1, Location loc2); abstract PotionEffect makePotionEffect(String EffectType, int duration, int amplifier, boolean ambient, boolean particles, Color color); Player player(String name); OfflinePlayer oplayer(String name); abstract Collection<? extends Player> getPlayers(); String currentArea(Entity entity); String currentAreaAt(Location location); String[] currentAreas(Entity entity); String[] currentAreasAt(Location location); List<Entity> getEntitiesInArea(String areaTriggerName); String color(String str); Color bukkitColor(int red, int green, int blue); @Deprecated abstract ItemStack item(int type, int amount, int data); abstract ItemStack item(String type, int amount, int data); @Deprecated abstract ItemStack item(int type, int amount); abstract ItemStack item(String type, int amount); String getItemTitle(ItemStack IS); void setItemTitle(ItemStack IS, String title); boolean hasLore(ItemStack IS, String lore); String getLore(ItemStack IS, int index); void addLore(ItemStack IS, String lore); void setLore(ItemStack IS, int index, String lore); void removeLore(ItemStack IS, int index); void clearLore(ItemStack IS); int loreSize(ItemStack IS); @Override String formatCurrency(double money, String locale1, String locale2); @Override String formatCurrency(double money); Block getTargetBlock(Player player, int maxDistance); ItemStack headForName(String targetName); abstract ItemStack headForName(String targetName, int amount); abstract ItemStack headForValue(String textureValue); }### Answer: @Test public void testFormatCurrency() { Assert.assertEquals("$3,234,463.44", fn.formatCurrency(3234463.44)); Assert.assertEquals("$3,234,463.44", fn.formatCurrency(3234463.44, "en", "US")); Assert.assertEquals("\u00a33,234,463.44", fn.formatCurrency(3234463.44, "en", "GB")); }
### Question: AbstractCommonFunctions extends io.github.wysohn.triggerreactor.core.manager.trigger.share.CommonFunctions implements SelfReference { public Block getTargetBlock(Player player, int maxDistance) { return player.getTargetBlock(null, maxDistance); } AbstractCommonFunctions(TriggerReactorCore plugin); Plugin plugin(String name); @Deprecated abstract boolean takeItem(Player player, int id, int amount); abstract boolean takeItem(Player player, String id, int amount); @Deprecated abstract boolean takeItem(Player player, int id, int amount, int data); abstract boolean takeItem(Player player, String id, int amount, int data); boolean takeItem(Player player, ItemStack IS, int amount); Location location(String world, double x, double y, double z); Location location(String world, double x, double y, double z, double yaw, double pitch); Block block(String world, int x, int y, int z); boolean locationEqual(Location loc1, Location loc2); abstract PotionEffect makePotionEffect(String EffectType, int duration, int amplifier, boolean ambient, boolean particles, Color color); Player player(String name); OfflinePlayer oplayer(String name); abstract Collection<? extends Player> getPlayers(); String currentArea(Entity entity); String currentAreaAt(Location location); String[] currentAreas(Entity entity); String[] currentAreasAt(Location location); List<Entity> getEntitiesInArea(String areaTriggerName); String color(String str); Color bukkitColor(int red, int green, int blue); @Deprecated abstract ItemStack item(int type, int amount, int data); abstract ItemStack item(String type, int amount, int data); @Deprecated abstract ItemStack item(int type, int amount); abstract ItemStack item(String type, int amount); String getItemTitle(ItemStack IS); void setItemTitle(ItemStack IS, String title); boolean hasLore(ItemStack IS, String lore); String getLore(ItemStack IS, int index); void addLore(ItemStack IS, String lore); void setLore(ItemStack IS, int index, String lore); void removeLore(ItemStack IS, int index); void clearLore(ItemStack IS); int loreSize(ItemStack IS); @Override String formatCurrency(double money, String locale1, String locale2); @Override String formatCurrency(double money); Block getTargetBlock(Player player, int maxDistance); ItemStack headForName(String targetName); abstract ItemStack headForName(String targetName, int amount); abstract ItemStack headForValue(String textureValue); }### Answer: @Test public void testGetTargetBlock() { fn.getTargetBlock(mockPlayer, 30); Mockito.verify(mockPlayer).getTargetBlock(null, 30); }
### Question: AbstractCommonFunctions extends io.github.wysohn.triggerreactor.core.manager.trigger.share.CommonFunctions implements SelfReference { public ItemStack headForName(String targetName) { return headForName(targetName, 1); } AbstractCommonFunctions(TriggerReactorCore plugin); Plugin plugin(String name); @Deprecated abstract boolean takeItem(Player player, int id, int amount); abstract boolean takeItem(Player player, String id, int amount); @Deprecated abstract boolean takeItem(Player player, int id, int amount, int data); abstract boolean takeItem(Player player, String id, int amount, int data); boolean takeItem(Player player, ItemStack IS, int amount); Location location(String world, double x, double y, double z); Location location(String world, double x, double y, double z, double yaw, double pitch); Block block(String world, int x, int y, int z); boolean locationEqual(Location loc1, Location loc2); abstract PotionEffect makePotionEffect(String EffectType, int duration, int amplifier, boolean ambient, boolean particles, Color color); Player player(String name); OfflinePlayer oplayer(String name); abstract Collection<? extends Player> getPlayers(); String currentArea(Entity entity); String currentAreaAt(Location location); String[] currentAreas(Entity entity); String[] currentAreasAt(Location location); List<Entity> getEntitiesInArea(String areaTriggerName); String color(String str); Color bukkitColor(int red, int green, int blue); @Deprecated abstract ItemStack item(int type, int amount, int data); abstract ItemStack item(String type, int amount, int data); @Deprecated abstract ItemStack item(int type, int amount); abstract ItemStack item(String type, int amount); String getItemTitle(ItemStack IS); void setItemTitle(ItemStack IS, String title); boolean hasLore(ItemStack IS, String lore); String getLore(ItemStack IS, int index); void addLore(ItemStack IS, String lore); void setLore(ItemStack IS, int index, String lore); void removeLore(ItemStack IS, int index); void clearLore(ItemStack IS); int loreSize(ItemStack IS); @Override String formatCurrency(double money, String locale1, String locale2); @Override String formatCurrency(double money); Block getTargetBlock(Player player, int maxDistance); ItemStack headForName(String targetName); abstract ItemStack headForName(String targetName, int amount); abstract ItemStack headForValue(String textureValue); }### Answer: @Test public abstract void testHeadForName();
### Question: AbstractCommonFunctions extends io.github.wysohn.triggerreactor.core.manager.trigger.share.CommonFunctions implements SelfReference { public abstract ItemStack headForValue(String textureValue); AbstractCommonFunctions(TriggerReactorCore plugin); Plugin plugin(String name); @Deprecated abstract boolean takeItem(Player player, int id, int amount); abstract boolean takeItem(Player player, String id, int amount); @Deprecated abstract boolean takeItem(Player player, int id, int amount, int data); abstract boolean takeItem(Player player, String id, int amount, int data); boolean takeItem(Player player, ItemStack IS, int amount); Location location(String world, double x, double y, double z); Location location(String world, double x, double y, double z, double yaw, double pitch); Block block(String world, int x, int y, int z); boolean locationEqual(Location loc1, Location loc2); abstract PotionEffect makePotionEffect(String EffectType, int duration, int amplifier, boolean ambient, boolean particles, Color color); Player player(String name); OfflinePlayer oplayer(String name); abstract Collection<? extends Player> getPlayers(); String currentArea(Entity entity); String currentAreaAt(Location location); String[] currentAreas(Entity entity); String[] currentAreasAt(Location location); List<Entity> getEntitiesInArea(String areaTriggerName); String color(String str); Color bukkitColor(int red, int green, int blue); @Deprecated abstract ItemStack item(int type, int amount, int data); abstract ItemStack item(String type, int amount, int data); @Deprecated abstract ItemStack item(int type, int amount); abstract ItemStack item(String type, int amount); String getItemTitle(ItemStack IS); void setItemTitle(ItemStack IS, String title); boolean hasLore(ItemStack IS, String lore); String getLore(ItemStack IS, int index); void addLore(ItemStack IS, String lore); void setLore(ItemStack IS, int index, String lore); void removeLore(ItemStack IS, int index); void clearLore(ItemStack IS); int loreSize(ItemStack IS); @Override String formatCurrency(double money, String locale1, String locale2); @Override String formatCurrency(double money); Block getTargetBlock(Player player, int maxDistance); ItemStack headForName(String targetName); abstract ItemStack headForName(String targetName, int amount); abstract ItemStack headForValue(String textureValue); }### Answer: @Test public abstract void testHeadForValue();
### Question: AbstractCommonFunctions extends io.github.wysohn.triggerreactor.core.manager.trigger.share.CommonFunctions implements SelfReference { public Location location(String world, double x, double y, double z) { return location(world, x, y, z, 0.0, 0.0); } AbstractCommonFunctions(TriggerReactorCore plugin); Plugin plugin(String name); @Deprecated abstract boolean takeItem(Player player, int id, int amount); abstract boolean takeItem(Player player, String id, int amount); @Deprecated abstract boolean takeItem(Player player, int id, int amount, int data); abstract boolean takeItem(Player player, String id, int amount, int data); boolean takeItem(Player player, ItemStack IS, int amount); Location location(String world, double x, double y, double z); Location location(String world, double x, double y, double z, double yaw, double pitch); Block block(String world, int x, int y, int z); boolean locationEqual(Location loc1, Location loc2); abstract PotionEffect makePotionEffect(String EffectType, int duration, int amplifier, boolean ambient, boolean particles, Color color); Player player(String name); OfflinePlayer oplayer(String name); abstract Collection<? extends Player> getPlayers(); String currentArea(Entity entity); String currentAreaAt(Location location); String[] currentAreas(Entity entity); String[] currentAreasAt(Location location); List<Entity> getEntitiesInArea(String areaTriggerName); String color(String str); Color bukkitColor(int red, int green, int blue); @Deprecated abstract ItemStack item(int type, int amount, int data); abstract ItemStack item(String type, int amount, int data); @Deprecated abstract ItemStack item(int type, int amount); abstract ItemStack item(String type, int amount); String getItemTitle(ItemStack IS); void setItemTitle(ItemStack IS, String title); boolean hasLore(ItemStack IS, String lore); String getLore(ItemStack IS, int index); void addLore(ItemStack IS, String lore); void setLore(ItemStack IS, int index, String lore); void removeLore(ItemStack IS, int index); void clearLore(ItemStack IS); int loreSize(ItemStack IS); @Override String formatCurrency(double money, String locale1, String locale2); @Override String formatCurrency(double money); Block getTargetBlock(Player player, int maxDistance); ItemStack headForName(String targetName); abstract ItemStack headForName(String targetName, int amount); abstract ItemStack headForValue(String textureValue); }### Answer: @Test public void testLocation() { Location loc1 = new Location(mockWorld, 1, 2, 3); Location loc2 = new Location(mockWorld, 4, 5, 6, 0.5F, 0.6F); Mockito.when(mockWorld.getName()).thenReturn("test"); Assert.assertEquals(loc1, fn.location("test", 1, 2, 3)); Mockito.when(mockWorld.getName()).thenReturn("test2"); Assert.assertEquals(loc2, fn.location("test2", 4, 5, 6, 0.5, 0.6)); }
### Question: BukkitMigrationHelper implements IMigrationHelper { @Override public void migrate(IConfigSource current) { traversal(null, oldConfig.getValues(false), current::put); if (oldFile.exists()) oldFile.renameTo(new File(oldFile.getParentFile(), "config.yml.bak")); } BukkitMigrationHelper(FileConfiguration oldConfig, File oldFile); @Override void migrate(IConfigSource current); }### Answer: @Test public void migrate() { IConfigSource mockSource = mock(IConfigSource.class); FileConfiguration mockConfig = YamlConfiguration.loadConfiguration(new StringReader("" + "Mysql:\n" + " Enable: false\n" + " Address: 127.0.0.1:3306\n" + " DbName: TriggerReactor\n" + " UserName: root\n" + " Password: '1234'\n" + " Deep: \n" + " Value: 5555\n" + " Value2: 52.24\n" + "PermissionManager:\n" + " Intercept: true" + "")); File mockFile = mock(File.class); IMigratable mockMigratable = new IMigratable() { @Override public boolean isMigrationNeeded() { return true; } @Override public void migrate(IMigrationHelper migrationHelper) { migrationHelper.migrate(mockSource); } }; BukkitMigrationHelper helper = new BukkitMigrationHelper(mockConfig, mockFile); mockMigratable.migrate(helper); Mockito.verify(mockSource).put(Mockito.eq("Mysql.Enable"), Mockito.eq(false)); Mockito.verify(mockSource).put(Mockito.eq("Mysql.Address"), Mockito.eq("127.0.0.1:3306")); Mockito.verify(mockSource).put(Mockito.eq("Mysql.DbName"), Mockito.eq("TriggerReactor")); Mockito.verify(mockSource).put(Mockito.eq("Mysql.UserName"), Mockito.eq("root")); Mockito.verify(mockSource).put(Mockito.eq("Mysql.Password"), Mockito.eq("1234")); Mockito.verify(mockSource).put(Mockito.eq("Mysql.Deep.Value"), Mockito.eq(5555)); Mockito.verify(mockSource).put(Mockito.eq("Mysql.Deep.Value2"), Mockito.eq(52.24)); Mockito.verify(mockSource).put(Mockito.eq("PermissionManager.Intercept"), Mockito.eq(true)); }
### Question: Timings { public static Timing getTiming(String name) { return getTiming(root, name); } static void reset(); static Timing getTiming(String name); static void print(Timing timing, OutputStream stream); static void printAll(OutputStream stream); static final Timing LIMBO; static boolean on; }### Answer: @Test public void testTiming() { Timings.Timing timingName = Timings.getTiming("my.timing.name"); Timings.Timing timingTiming = Timings.getTiming("my.timing"); Timings.Timing timingMy = Timings.getTiming("my"); Timings.Timing root = Timings.getTiming(null); Assert.assertNotNull(timingName); Assert.assertNotNull(timingTiming); Assert.assertNotNull(timingMy); Assert.assertNotNull(root); Assert.assertEquals(timingName, Timings.getTiming("my.timing.name")); Assert.assertEquals(timingTiming, Timings.getTiming("my.timing")); Assert.assertEquals(timingMy, Timings.getTiming("my")); Assert.assertEquals(root, Timings.getTiming(null)); } @Test public void testExampleTiming() throws Exception { Timings.on = true; Timings.Timing timingExMessage = Timings.getTiming("CommandTrigger.myCmd.Executors.#MESSAGE"); Timings.Timing timingExTP = Timings.getTiming("CommandTrigger.myCmd.Executors.#TP"); Timings.Timing timingPhPlayerName = Timings.getTiming("CommandTrigger.myCmd.Placeholders.$playername"); Timings.Timing timingPhRandom = Timings.getTiming("CommandTrigger.myCmd.Placeholders.$random"); Timings.Timing timingInterpret = Timings.getTiming("CommandTrigger.myCmd.Interpret"); try (Timings.Timing t = timingExMessage.begin(true)) { Thread.sleep(2L); } try (Timings.Timing t = timingExTP.begin()) { Thread.sleep(5L); } try (Timings.Timing t = timingPhPlayerName.begin()) { Thread.sleep(100L); } try (Timings.Timing t = timingPhRandom.begin()) { Thread.sleep(10L); } try (Timings.Timing t = timingInterpret.begin()) { Thread.sleep(1000L); } Timings.Timing parent = Timings.getTiming("CommandTrigger"); Timings.Timing timingExMessage2 = parent.getTiming("myCmd2.Executors.#MESSAGE"); try (Timings.Timing t = timingExMessage2.begin()) { Thread.sleep(1L); } }
### Question: CommonFunctions implements SelfReference { public int random(int end) { return rand.nextInt(end); } int random(int end); float random(float end); double random(double end); long random(long end); int random(int start, int end); float random(float start, float end); double random(double start, double end); long random(long start, long end); String round(double val, int decimal); Object staticGetFieldValue(String className, String fieldName); void staticSetFieldValue(String className, String fieldName, Object value); Object staticMethod(String className, String methodName, Object... args); @SuppressWarnings("unchecked") Object parseEnum(String enumClassName, String valueName); SimpleLocation slocation(String world, int x, int y, int z); Object newInstance(String className, Object... args); boolean matches(String str, String regex); int parseInt(String str); double parseDouble(String str); Object[] array(int size); List<Object> list(); Map<Object, Object> map(); Set<Object> set(); String mergeArguments(String[] args); String mergeArguments(String[] args, int indexFrom); String mergeArguments(String[] args, int indexFrom, int indexTo); byte toByte(Number number); short toShort(Number number); int toInt(Number number); long toLong(Number number); float toFloat(Number number); double toDouble(Number number); double sqrt(int num); String formatCurrency(double money, String locale1, String locale2); String formatCurrency(double money); String typeOf(Object value, boolean withFullPath); }### Answer: @Test public void testRandoms() throws Exception { for (int i = 0; i < trials; i++) { double value = fn.random(1.0); assertTrue(0.0 <= value && value < 1.0); value = fn.random(0.0, 1.0); assertTrue(0.0 <= value && value < 1.0); value = fn.random(1.0F); assertTrue(0.0 <= value && value < 1.0); value = fn.random(0.0F, 1.0F); assertTrue(0.0 <= value && value < 1.0); } for (int i = 0; i < trials; i++) { long value = fn.random(10L); assertTrue(0L <= value && value < 10L); value = fn.random(0L, 10L); assertTrue(0L <= value && value < 10L); int value2 = fn.random(10); assertTrue(0 <= value2 && value2 < 10); value2 = fn.random(0, 10); assertTrue(0 <= value2 && value2 < 10); } }
### Question: CommonFunctions implements SelfReference { public SimpleLocation slocation(String world, int x, int y, int z) { if (world == null) { throw new IllegalArgumentException("world cannot be null"); } return new SimpleLocation(world, x, y, z); } int random(int end); float random(float end); double random(double end); long random(long end); int random(int start, int end); float random(float start, float end); double random(double start, double end); long random(long start, long end); String round(double val, int decimal); Object staticGetFieldValue(String className, String fieldName); void staticSetFieldValue(String className, String fieldName, Object value); Object staticMethod(String className, String methodName, Object... args); @SuppressWarnings("unchecked") Object parseEnum(String enumClassName, String valueName); SimpleLocation slocation(String world, int x, int y, int z); Object newInstance(String className, Object... args); boolean matches(String str, String regex); int parseInt(String str); double parseDouble(String str); Object[] array(int size); List<Object> list(); Map<Object, Object> map(); Set<Object> set(); String mergeArguments(String[] args); String mergeArguments(String[] args, int indexFrom); String mergeArguments(String[] args, int indexFrom, int indexTo); byte toByte(Number number); short toShort(Number number); int toInt(Number number); long toLong(Number number); float toFloat(Number number); double toDouble(Number number); double sqrt(int num); String formatCurrency(double money, String locale1, String locale2); String formatCurrency(double money); String typeOf(Object value, boolean withFullPath); }### Answer: @Test public void testSLocation() throws Exception { assertEquals(fn.slocation("merp", 1, 2, 3), new SimpleLocation("merp", 1, 2, 3)); }
### Question: GsonConfigSource implements IConfigSource { @Override public void reload() { ensureFile(); synchronized (file) { try (Reader fr = this.readerFactory.apply(file)) { synchronized (cache) { cache.clear(); Map<String, Object> loaded = gson.fromJson(fr, new TypeToken<Map<String, Object>>() { }.getType()); if (loaded != null) { cache.putAll(loaded); } } } catch (IOException e) { e.printStackTrace(); } } } GsonConfigSource(File file); GsonConfigSource(File file, Function<File, Reader> readerFactory, Function<File, Writer> writerFactory); @Override void reload(); @Override void disable(); @Override void saveAll(); @Override Optional<T> get(String key, Class<T> asType); @Override Optional<T> get(String key); @Override void put(String key, Object value); @Override Set<String> keys(); @Override boolean isSection(String key); void shutdown(); }### Answer: @Test public void testReload() { Mockito.when(mockFile.exists()).thenReturn(true); manager.reload(); Map<String, Object> cache = Whitebox.getInternalState(manager, "cache"); List<Integer> list = new ArrayList<>(); list.add(1); list.add(2); list.add(3); Assert.assertEquals(list, cache.get("array")); Assert.assertEquals(true, cache.get("boolean")); Assert.assertEquals("#82b92c", cache.get("color")); Assert.assertEquals(null, cache.get("null")); Assert.assertEquals(123, cache.get("number")); Assert.assertEquals(345.67, cache.get("fnumber")); Assert.assertTrue(cache.get("object") instanceof Map); Map<String, Object> obj = (Map<String, Object>) cache.get("object"); Assert.assertEquals("b", obj.get("a")); Assert.assertEquals("d", obj.get("c")); Assert.assertEquals("f", obj.get("e")); Assert.assertEquals("Hello World", cache.get("string")); }
### Question: GsonConfigSource implements IConfigSource { @Override public void saveAll() { ensureFile(); synchronized (file) { cacheToFile(); } } GsonConfigSource(File file); GsonConfigSource(File file, Function<File, Reader> readerFactory, Function<File, Writer> writerFactory); @Override void reload(); @Override void disable(); @Override void saveAll(); @Override Optional<T> get(String key, Class<T> asType); @Override Optional<T> get(String key); @Override void put(String key, Object value); @Override Set<String> keys(); @Override boolean isSection(String key); void shutdown(); }### Answer: @Test public void testSaveAll() { Mockito.when(mockFile.exists()).thenReturn(true); Map<String, Object> cache = Whitebox.getInternalState(manager, "cache"); cache.put("array2", new int[]{4, 5, 6}); cache.put("boolean2", false); cache.put("color2", "#123b9cc"); cache.put("null", null); cache.put("number2", 456); cache.put("fnumber2", 789.12); Map<String, Object> obj = new HashMap<>(); obj.put("i", "j"); obj.put("k", "l"); obj.put("m", "n"); cache.put("object", obj); cache.put("string2", "World Hello"); manager.saveAll(); String out = stringWriter.toString(); GsonBuilder builder = org.powermock.reflect.Whitebox.getInternalState(GsonConfigSource.class, "builder"); Gson gson = builder.create(); Map<String, Object> deser = gson.fromJson(out, new TypeToken<Map<String, Object>>() { }.getType()); List<Integer> list = new ArrayList<>(); list.add(4); list.add(5); list.add(6); Assert.assertEquals(list, deser.get("array2")); Assert.assertEquals(false, deser.get("boolean2")); Assert.assertEquals("#123b9cc", deser.get("color2")); Assert.assertEquals(null, deser.get("null")); Assert.assertEquals(456, deser.get("number2")); Assert.assertEquals(789.12, deser.get("fnumber2")); Assert.assertTrue(deser.get("object") instanceof Map); Map<String, Object> obj2 = (Map<String, Object>) deser.get("object"); Assert.assertEquals("j", obj2.get("i")); Assert.assertEquals("l", obj2.get("k")); Assert.assertEquals("n", obj2.get("m")); Assert.assertEquals("World Hello", deser.get("string2")); }
### Question: GsonConfigSource implements IConfigSource { private <T> T get(Map<String, Object> map, String[] path, Class<T> asType) { for (int i = 0; i < path.length; i++) { String key = path[i]; Object value = map.get(key); if (i == path.length - 1) { return asType.cast(value); } else if (value instanceof Map) { map = (Map<String, Object>) value; } else { return null; } } return null; } GsonConfigSource(File file); GsonConfigSource(File file, Function<File, Reader> readerFactory, Function<File, Writer> writerFactory); @Override void reload(); @Override void disable(); @Override void saveAll(); @Override Optional<T> get(String key, Class<T> asType); @Override Optional<T> get(String key); @Override void put(String key, Object value); @Override Set<String> keys(); @Override boolean isSection(String key); void shutdown(); }### Answer: @Test public void testGet() { Mockito.when(mockFile.exists()).thenReturn(true); manager.reload(); Assert.assertTrue(manager.get("object").orElse(null) instanceof Map); Assert.assertEquals("b", manager.get("object.a").orElse(null)); Assert.assertEquals("d", manager.get("object.c").orElse(null)); Assert.assertEquals("f", manager.get("object.e").orElse(null)); }
### Question: GsonConfigSource implements IConfigSource { private void put(Map<String, Object> map, String[] path, Object value) { for (int i = 0; i < path.length; i++) { String key = path[i]; if (i == path.length - 1) { map.put(key, value); } else { Object previous = map.computeIfAbsent(key, (k) -> new HashMap<>()); if (!(previous instanceof Map)) throw new RuntimeException("Value found at " + key + " is not a section."); map = (Map<String, Object>) previous; } } } GsonConfigSource(File file); GsonConfigSource(File file, Function<File, Reader> readerFactory, Function<File, Writer> writerFactory); @Override void reload(); @Override void disable(); @Override void saveAll(); @Override Optional<T> get(String key, Class<T> asType); @Override Optional<T> get(String key); @Override void put(String key, Object value); @Override Set<String> keys(); @Override boolean isSection(String key); void shutdown(); }### Answer: @Test public void testPut() { Mockito.when(mockFile.exists()).thenReturn(true); manager.put("some.data.value", "abc"); manager.put("some.data.value2", 123); manager.put("some.data.value3", false); Assert.assertEquals("abc", manager.get("some.data.value").orElse(null)); Assert.assertEquals(123, manager.get("some.data.value2").orElse(null)); Assert.assertEquals(false, manager.get("some.data.value3").orElse(null)); manager.put("some.data", 556); Assert.assertEquals(556, manager.get("some.data").orElse(null)); Assert.assertNull(manager.get("some.data.value").orElse(null)); Assert.assertNull(manager.get("some.data.value2").orElse(null)); Assert.assertNull(manager.get("some.data.value3").orElse(null)); }
### Question: AbstractCommonFunctions extends io.github.wysohn.triggerreactor.core.manager.trigger.share.CommonFunctions implements SelfReference { public Block block(String world, int x, int y, int z) { return location(world, x, y, z).getBlock(); } AbstractCommonFunctions(TriggerReactorCore plugin); Plugin plugin(String name); @Deprecated abstract boolean takeItem(Player player, int id, int amount); abstract boolean takeItem(Player player, String id, int amount); @Deprecated abstract boolean takeItem(Player player, int id, int amount, int data); abstract boolean takeItem(Player player, String id, int amount, int data); boolean takeItem(Player player, ItemStack IS, int amount); Location location(String world, double x, double y, double z); Location location(String world, double x, double y, double z, double yaw, double pitch); Block block(String world, int x, int y, int z); boolean locationEqual(Location loc1, Location loc2); abstract PotionEffect makePotionEffect(String EffectType, int duration, int amplifier, boolean ambient, boolean particles, Color color); Player player(String name); OfflinePlayer oplayer(String name); abstract Collection<? extends Player> getPlayers(); String currentArea(Entity entity); String currentAreaAt(Location location); String[] currentAreas(Entity entity); String[] currentAreasAt(Location location); List<Entity> getEntitiesInArea(String areaTriggerName); String color(String str); Color bukkitColor(int red, int green, int blue); @Deprecated abstract ItemStack item(int type, int amount, int data); abstract ItemStack item(String type, int amount, int data); @Deprecated abstract ItemStack item(int type, int amount); abstract ItemStack item(String type, int amount); String getItemTitle(ItemStack IS); void setItemTitle(ItemStack IS, String title); boolean hasLore(ItemStack IS, String lore); String getLore(ItemStack IS, int index); void addLore(ItemStack IS, String lore); void setLore(ItemStack IS, int index, String lore); void removeLore(ItemStack IS, int index); void clearLore(ItemStack IS); int loreSize(ItemStack IS); @Override String formatCurrency(double money, String locale1, String locale2); @Override String formatCurrency(double money); Block getTargetBlock(Player player, int maxDistance); ItemStack headForName(String targetName); abstract ItemStack headForName(String targetName, int amount); abstract ItemStack headForValue(String textureValue); }### Answer: @Test public void testBlock() { Block mockBlock = Mockito.mock(Block.class); Mockito.when(mockWorld.getBlockAt(Mockito.any(Location.class))) .thenReturn(mockBlock); Assert.assertEquals(mockBlock, fn.block("test", 1, 2, 3)); }
### Question: GsonConfigSource implements IConfigSource { @Override public Set<String> keys() { synchronized (cache) { return new HashSet<>(cache.keySet()); } } GsonConfigSource(File file); GsonConfigSource(File file, Function<File, Reader> readerFactory, Function<File, Writer> writerFactory); @Override void reload(); @Override void disable(); @Override void saveAll(); @Override Optional<T> get(String key, Class<T> asType); @Override Optional<T> get(String key); @Override void put(String key, Object value); @Override Set<String> keys(); @Override boolean isSection(String key); void shutdown(); }### Answer: @Test public void testKeys() { Mockito.when(mockFile.exists()).thenReturn(true); manager.reload(); Set<String> expected = new HashSet<>(); expected.add("array"); expected.add("boolean"); expected.add("color"); expected.add("null"); expected.add("number"); expected.add("fnumber"); expected.add("object"); expected.add("string"); Assert.assertEquals(expected, manager.keys()); }
### Question: GsonConfigSource implements IConfigSource { @Override public boolean isSection(String key) { synchronized (cache) { return get(cache, IConfigSource.toPath(key), Object.class) instanceof Map; } } GsonConfigSource(File file); GsonConfigSource(File file, Function<File, Reader> readerFactory, Function<File, Writer> writerFactory); @Override void reload(); @Override void disable(); @Override void saveAll(); @Override Optional<T> get(String key, Class<T> asType); @Override Optional<T> get(String key); @Override void put(String key, Object value); @Override Set<String> keys(); @Override boolean isSection(String key); void shutdown(); }### Answer: @Test public void testIsSection() { Mockito.when(mockFile.exists()).thenReturn(true); manager.reload(); Assert.assertFalse(manager.isSection("array")); Assert.assertFalse(manager.isSection("boolean")); Assert.assertFalse(manager.isSection("color")); Assert.assertFalse(manager.isSection("null")); Assert.assertFalse(manager.isSection("number")); Assert.assertFalse(manager.isSection("fnumber")); Assert.assertTrue(manager.isSection("object")); Assert.assertFalse(manager.isSection("string")); }
### Question: Lexer { public Token getToken() throws IOException, LexerException { skipWhiteSpaces(); skipComment(); if (Character.isDigit(c)) { return readNumber(); } if (c == '"') { return readString(); } if (c == '`') { return readMultilineString(); } if (isOperator(c)) { return readOperator(); } if (isIdCharacter(c)) { return readId(); } if (c == '\n' || c == ';') { return readEndline(); } if (!eos) { throw new LexerException("Found an unrecognizable character", this); } return null; } Lexer(String str, Charset charset); Lexer(String str, String charset); int getRow(); int getCol(); List<Warning> getWarnings(); boolean getShowWarnings(); String[] getScriptLines(); Token getToken(); void setWarnings(boolean w); static void main(String[] ar); }### Answer: @Test public void testGetToken() throws Exception { Charset charset = StandardCharsets.UTF_8; String text = "#MESSAGE (1+(4/2.0)/3*4-(2/(3*-4)) >= 0)\n" + "#MESSAGE \"text\" \"test\"\n"; Lexer lexer = new Lexer(text, charset); testToken(lexer, Type.ID, "#MESSAGE"); testToken(lexer, Type.OPERATOR, "("); testToken(lexer, Type.INTEGER, "1"); testToken(lexer, Type.OPERATOR_A, "+"); testToken(lexer, Type.OPERATOR, "("); testToken(lexer, Type.INTEGER, "4"); testToken(lexer, Type.OPERATOR_A, "/"); testToken(lexer, Type.DECIMAL, "2.0"); testToken(lexer, Type.OPERATOR, ")"); testToken(lexer, Type.OPERATOR_A, "/"); testToken(lexer, Type.INTEGER, "3"); testToken(lexer, Type.OPERATOR_A, "*"); testToken(lexer, Type.INTEGER, "4"); testToken(lexer, Type.OPERATOR_A, "-"); testToken(lexer, Type.OPERATOR, "("); testToken(lexer, Type.INTEGER, "2"); testToken(lexer, Type.OPERATOR_A, "/"); testToken(lexer, Type.OPERATOR, "("); testToken(lexer, Type.INTEGER, "3"); testToken(lexer, Type.OPERATOR_A, "*"); testToken(lexer, Type.OPERATOR_A, "-"); testToken(lexer, Type.INTEGER, "4"); testToken(lexer, Type.OPERATOR, ")"); testToken(lexer, Type.OPERATOR, ")"); testToken(lexer, Type.OPERATOR_L, ">="); testToken(lexer, Type.INTEGER, "0"); testToken(lexer, Type.OPERATOR, ")"); testToken(lexer, Type.ENDL, null); testToken(lexer, Type.ID, "#MESSAGE"); testToken(lexer, Type.STRING, "text"); testToken(lexer, Type.STRING, "test"); testToken(lexer, Type.ENDL, null); testEnd(lexer); } @Test public void testEscapeCharacter2() throws Exception { Charset charset = StandardCharsets.UTF_8; String text = "#MESSAGE \"The cost is \\$100\""; Lexer lexer = new Lexer(text, charset); assertEquals(new Token(Type.ID, "#MESSAGE"), lexer.getToken()); assertEquals(new Token(Type.STRING, "The cost is $100"), lexer.getToken()); assertNull(lexer.getToken()); } @Test public void testImportWithUnderscore() throws Exception{ Charset charset = StandardCharsets.UTF_8; String text; Lexer lexer; text = "IMPORT net.md_5.bungee.api.chat.ComponentBuilder"; lexer = new Lexer(text, charset); assertEquals(new Token(Type.IMPORT, "net.md_5.bungee.api.chat.ComponentBuilder"), lexer.getToken()); }
### Question: AbstractCommonFunctions extends io.github.wysohn.triggerreactor.core.manager.trigger.share.CommonFunctions implements SelfReference { public boolean locationEqual(Location loc1, Location loc2) { return loc1.getWorld() == loc2.getWorld() && loc1.getBlockX() == loc2.getBlockX() && loc1.getBlockY() == loc2.getBlockY() && loc1.getBlockZ() == loc2.getBlockZ(); } AbstractCommonFunctions(TriggerReactorCore plugin); Plugin plugin(String name); @Deprecated abstract boolean takeItem(Player player, int id, int amount); abstract boolean takeItem(Player player, String id, int amount); @Deprecated abstract boolean takeItem(Player player, int id, int amount, int data); abstract boolean takeItem(Player player, String id, int amount, int data); boolean takeItem(Player player, ItemStack IS, int amount); Location location(String world, double x, double y, double z); Location location(String world, double x, double y, double z, double yaw, double pitch); Block block(String world, int x, int y, int z); boolean locationEqual(Location loc1, Location loc2); abstract PotionEffect makePotionEffect(String EffectType, int duration, int amplifier, boolean ambient, boolean particles, Color color); Player player(String name); OfflinePlayer oplayer(String name); abstract Collection<? extends Player> getPlayers(); String currentArea(Entity entity); String currentAreaAt(Location location); String[] currentAreas(Entity entity); String[] currentAreasAt(Location location); List<Entity> getEntitiesInArea(String areaTriggerName); String color(String str); Color bukkitColor(int red, int green, int blue); @Deprecated abstract ItemStack item(int type, int amount, int data); abstract ItemStack item(String type, int amount, int data); @Deprecated abstract ItemStack item(int type, int amount); abstract ItemStack item(String type, int amount); String getItemTitle(ItemStack IS); void setItemTitle(ItemStack IS, String title); boolean hasLore(ItemStack IS, String lore); String getLore(ItemStack IS, int index); void addLore(ItemStack IS, String lore); void setLore(ItemStack IS, int index, String lore); void removeLore(ItemStack IS, int index); void clearLore(ItemStack IS); int loreSize(ItemStack IS); @Override String formatCurrency(double money, String locale1, String locale2); @Override String formatCurrency(double money); Block getTargetBlock(Player player, int maxDistance); ItemStack headForName(String targetName); abstract ItemStack headForName(String targetName, int amount); abstract ItemStack headForValue(String textureValue); }### Answer: @Test public void testLocationEqual() { Location loc1 = new Location(mockWorld, 1, 2, 3); Location loc2 = new Location(mockWorld, 4, 5, 6, 0.5F, 0.6F); Location loc3 = new Location(mockWorld, 1, 2, 3, 0.7F, 0.8F); Location loc4 = new Location(mockWorld, 4, 5, 6, 0.1F, 0.2F); Assert.assertFalse(fn.locationEqual(loc1, loc2)); Assert.assertTrue(fn.locationEqual(loc1, loc3)); Assert.assertFalse(fn.locationEqual(loc2, loc3)); Assert.assertTrue(fn.locationEqual(loc2, loc4)); }
### Question: AbstractCommonFunctions extends io.github.wysohn.triggerreactor.core.manager.trigger.share.CommonFunctions implements SelfReference { public abstract PotionEffect makePotionEffect(String EffectType, int duration, int amplifier, boolean ambient, boolean particles, Color color); AbstractCommonFunctions(TriggerReactorCore plugin); Plugin plugin(String name); @Deprecated abstract boolean takeItem(Player player, int id, int amount); abstract boolean takeItem(Player player, String id, int amount); @Deprecated abstract boolean takeItem(Player player, int id, int amount, int data); abstract boolean takeItem(Player player, String id, int amount, int data); boolean takeItem(Player player, ItemStack IS, int amount); Location location(String world, double x, double y, double z); Location location(String world, double x, double y, double z, double yaw, double pitch); Block block(String world, int x, int y, int z); boolean locationEqual(Location loc1, Location loc2); abstract PotionEffect makePotionEffect(String EffectType, int duration, int amplifier, boolean ambient, boolean particles, Color color); Player player(String name); OfflinePlayer oplayer(String name); abstract Collection<? extends Player> getPlayers(); String currentArea(Entity entity); String currentAreaAt(Location location); String[] currentAreas(Entity entity); String[] currentAreasAt(Location location); List<Entity> getEntitiesInArea(String areaTriggerName); String color(String str); Color bukkitColor(int red, int green, int blue); @Deprecated abstract ItemStack item(int type, int amount, int data); abstract ItemStack item(String type, int amount, int data); @Deprecated abstract ItemStack item(int type, int amount); abstract ItemStack item(String type, int amount); String getItemTitle(ItemStack IS); void setItemTitle(ItemStack IS, String title); boolean hasLore(ItemStack IS, String lore); String getLore(ItemStack IS, int index); void addLore(ItemStack IS, String lore); void setLore(ItemStack IS, int index, String lore); void removeLore(ItemStack IS, int index); void clearLore(ItemStack IS); int loreSize(ItemStack IS); @Override String formatCurrency(double money, String locale1, String locale2); @Override String formatCurrency(double money); Block getTargetBlock(Player player, int maxDistance); ItemStack headForName(String targetName); abstract ItemStack headForName(String targetName, int amount); abstract ItemStack headForValue(String textureValue); }### Answer: @Test public abstract void testMakePotionEffect();
### Question: AbstractCommonFunctions extends io.github.wysohn.triggerreactor.core.manager.trigger.share.CommonFunctions implements SelfReference { public Player player(String name) { return Bukkit.getPlayer(name); } AbstractCommonFunctions(TriggerReactorCore plugin); Plugin plugin(String name); @Deprecated abstract boolean takeItem(Player player, int id, int amount); abstract boolean takeItem(Player player, String id, int amount); @Deprecated abstract boolean takeItem(Player player, int id, int amount, int data); abstract boolean takeItem(Player player, String id, int amount, int data); boolean takeItem(Player player, ItemStack IS, int amount); Location location(String world, double x, double y, double z); Location location(String world, double x, double y, double z, double yaw, double pitch); Block block(String world, int x, int y, int z); boolean locationEqual(Location loc1, Location loc2); abstract PotionEffect makePotionEffect(String EffectType, int duration, int amplifier, boolean ambient, boolean particles, Color color); Player player(String name); OfflinePlayer oplayer(String name); abstract Collection<? extends Player> getPlayers(); String currentArea(Entity entity); String currentAreaAt(Location location); String[] currentAreas(Entity entity); String[] currentAreasAt(Location location); List<Entity> getEntitiesInArea(String areaTriggerName); String color(String str); Color bukkitColor(int red, int green, int blue); @Deprecated abstract ItemStack item(int type, int amount, int data); abstract ItemStack item(String type, int amount, int data); @Deprecated abstract ItemStack item(int type, int amount); abstract ItemStack item(String type, int amount); String getItemTitle(ItemStack IS); void setItemTitle(ItemStack IS, String title); boolean hasLore(ItemStack IS, String lore); String getLore(ItemStack IS, int index); void addLore(ItemStack IS, String lore); void setLore(ItemStack IS, int index, String lore); void removeLore(ItemStack IS, int index); void clearLore(ItemStack IS); int loreSize(ItemStack IS); @Override String formatCurrency(double money, String locale1, String locale2); @Override String formatCurrency(double money); Block getTargetBlock(Player player, int maxDistance); ItemStack headForName(String targetName); abstract ItemStack headForName(String targetName, int amount); abstract ItemStack headForValue(String textureValue); }### Answer: @Test public void testPlayer() { Assert.assertEquals(mockPlayer, fn.player("wysohn")); }
### Question: AbstractCommonFunctions extends io.github.wysohn.triggerreactor.core.manager.trigger.share.CommonFunctions implements SelfReference { public OfflinePlayer oplayer(String name) { return Bukkit.getOfflinePlayer(name); } AbstractCommonFunctions(TriggerReactorCore plugin); Plugin plugin(String name); @Deprecated abstract boolean takeItem(Player player, int id, int amount); abstract boolean takeItem(Player player, String id, int amount); @Deprecated abstract boolean takeItem(Player player, int id, int amount, int data); abstract boolean takeItem(Player player, String id, int amount, int data); boolean takeItem(Player player, ItemStack IS, int amount); Location location(String world, double x, double y, double z); Location location(String world, double x, double y, double z, double yaw, double pitch); Block block(String world, int x, int y, int z); boolean locationEqual(Location loc1, Location loc2); abstract PotionEffect makePotionEffect(String EffectType, int duration, int amplifier, boolean ambient, boolean particles, Color color); Player player(String name); OfflinePlayer oplayer(String name); abstract Collection<? extends Player> getPlayers(); String currentArea(Entity entity); String currentAreaAt(Location location); String[] currentAreas(Entity entity); String[] currentAreasAt(Location location); List<Entity> getEntitiesInArea(String areaTriggerName); String color(String str); Color bukkitColor(int red, int green, int blue); @Deprecated abstract ItemStack item(int type, int amount, int data); abstract ItemStack item(String type, int amount, int data); @Deprecated abstract ItemStack item(int type, int amount); abstract ItemStack item(String type, int amount); String getItemTitle(ItemStack IS); void setItemTitle(ItemStack IS, String title); boolean hasLore(ItemStack IS, String lore); String getLore(ItemStack IS, int index); void addLore(ItemStack IS, String lore); void setLore(ItemStack IS, int index, String lore); void removeLore(ItemStack IS, int index); void clearLore(ItemStack IS); int loreSize(ItemStack IS); @Override String formatCurrency(double money, String locale1, String locale2); @Override String formatCurrency(double money); Block getTargetBlock(Player player, int maxDistance); ItemStack headForName(String targetName); abstract ItemStack headForName(String targetName, int amount); abstract ItemStack headForValue(String textureValue); }### Answer: @Test public void testOPlayer() { Assert.assertEquals(mockPlayer, fn.oplayer("wysohn")); }
### Question: AbstractCommonFunctions extends io.github.wysohn.triggerreactor.core.manager.trigger.share.CommonFunctions implements SelfReference { public abstract Collection<? extends Player> getPlayers(); AbstractCommonFunctions(TriggerReactorCore plugin); Plugin plugin(String name); @Deprecated abstract boolean takeItem(Player player, int id, int amount); abstract boolean takeItem(Player player, String id, int amount); @Deprecated abstract boolean takeItem(Player player, int id, int amount, int data); abstract boolean takeItem(Player player, String id, int amount, int data); boolean takeItem(Player player, ItemStack IS, int amount); Location location(String world, double x, double y, double z); Location location(String world, double x, double y, double z, double yaw, double pitch); Block block(String world, int x, int y, int z); boolean locationEqual(Location loc1, Location loc2); abstract PotionEffect makePotionEffect(String EffectType, int duration, int amplifier, boolean ambient, boolean particles, Color color); Player player(String name); OfflinePlayer oplayer(String name); abstract Collection<? extends Player> getPlayers(); String currentArea(Entity entity); String currentAreaAt(Location location); String[] currentAreas(Entity entity); String[] currentAreasAt(Location location); List<Entity> getEntitiesInArea(String areaTriggerName); String color(String str); Color bukkitColor(int red, int green, int blue); @Deprecated abstract ItemStack item(int type, int amount, int data); abstract ItemStack item(String type, int amount, int data); @Deprecated abstract ItemStack item(int type, int amount); abstract ItemStack item(String type, int amount); String getItemTitle(ItemStack IS); void setItemTitle(ItemStack IS, String title); boolean hasLore(ItemStack IS, String lore); String getLore(ItemStack IS, int index); void addLore(ItemStack IS, String lore); void setLore(ItemStack IS, int index, String lore); void removeLore(ItemStack IS, int index); void clearLore(ItemStack IS); int loreSize(ItemStack IS); @Override String formatCurrency(double money, String locale1, String locale2); @Override String formatCurrency(double money); Block getTargetBlock(Player player, int maxDistance); ItemStack headForName(String targetName); abstract ItemStack headForName(String targetName, int amount); abstract ItemStack headForValue(String textureValue); }### Answer: @Test public abstract void testGetPlayers();
### Question: AbstractCommonFunctions extends io.github.wysohn.triggerreactor.core.manager.trigger.share.CommonFunctions implements SelfReference { public String currentArea(Entity entity) { String[] areas = currentAreasAt(entity.getLocation()); return areas.length > 0 ? areas[0] : null; } AbstractCommonFunctions(TriggerReactorCore plugin); Plugin plugin(String name); @Deprecated abstract boolean takeItem(Player player, int id, int amount); abstract boolean takeItem(Player player, String id, int amount); @Deprecated abstract boolean takeItem(Player player, int id, int amount, int data); abstract boolean takeItem(Player player, String id, int amount, int data); boolean takeItem(Player player, ItemStack IS, int amount); Location location(String world, double x, double y, double z); Location location(String world, double x, double y, double z, double yaw, double pitch); Block block(String world, int x, int y, int z); boolean locationEqual(Location loc1, Location loc2); abstract PotionEffect makePotionEffect(String EffectType, int duration, int amplifier, boolean ambient, boolean particles, Color color); Player player(String name); OfflinePlayer oplayer(String name); abstract Collection<? extends Player> getPlayers(); String currentArea(Entity entity); String currentAreaAt(Location location); String[] currentAreas(Entity entity); String[] currentAreasAt(Location location); List<Entity> getEntitiesInArea(String areaTriggerName); String color(String str); Color bukkitColor(int red, int green, int blue); @Deprecated abstract ItemStack item(int type, int amount, int data); abstract ItemStack item(String type, int amount, int data); @Deprecated abstract ItemStack item(int type, int amount); abstract ItemStack item(String type, int amount); String getItemTitle(ItemStack IS); void setItemTitle(ItemStack IS, String title); boolean hasLore(ItemStack IS, String lore); String getLore(ItemStack IS, int index); void addLore(ItemStack IS, String lore); void setLore(ItemStack IS, int index, String lore); void removeLore(ItemStack IS, int index); void clearLore(ItemStack IS); int loreSize(ItemStack IS); @Override String formatCurrency(double money, String locale1, String locale2); @Override String formatCurrency(double money); Block getTargetBlock(Player player, int maxDistance); ItemStack headForName(String targetName); abstract ItemStack headForName(String targetName, int amount); abstract ItemStack headForValue(String textureValue); }### Answer: @Test public void testCurrentArea() { }
### Question: MemoryManager { public abstract long acquireExecutionMemory(long numBytes, long taskAttemptId, MemoryMode memoryMode); MemoryManager(SparkConf conf, int numCores, long onHeapStorageMemory, long onHeapExecutionMemory); long pageSizeBytes(); MemoryAllocator tungstenMemoryAllocator(); final void setMemoryStore(MemoryStore memoryStore); abstract long maxOnHeapStorageMemory(); abstract long maxOffHeapStorageMemory(); abstract boolean acquireStorageMemory(BlockId blockId, long numBytes, MemoryMode memoryMode); abstract boolean acquireUnrollMemory(BlockId blockId, long numBytes, MemoryMode memoryMode); synchronized void releaseStorageMemory(long numBytes, MemoryMode memoryMode); synchronized void releaseAllStorageMemory(); final void releaseUnrollMemory(long numBytes, MemoryMode memoryMode); final synchronized long storageMemoryUsed(); abstract long acquireExecutionMemory(long numBytes, long taskAttemptId, MemoryMode memoryMode); void releaseExecutionMemory(long numBytes, long taskAttemptId, MemoryMode memoryMode); synchronized long releaseAllExecutionMemoryForTask(long taskAttemptId); final synchronized long executionMemoryUsed(); synchronized long getExecutionMemoryUsageForTask(long taskAttemptId); static long getMaxStorageMemory(SparkConf conf); static long getMaxExecutionMemory(SparkConf conf); public SparkConf conf; }### Answer: @Test public void testAcquireExecutionMemory() { MemoryManager memoryManager = createStaticMemoryManager(1000L); TaskMemoryManager taskMemoryManager = new TaskMemoryManager(memoryManager, 0); TestMemoryConsumer consumer = new TestMemoryConsumer(taskMemoryManager); assert taskMemoryManager.acquireExecutionMemory(100L, consumer) == 100L; assert taskMemoryManager.acquireExecutionMemory(400L, consumer) == 400L; assert taskMemoryManager.acquireExecutionMemory(400L, consumer) == 400L; assert taskMemoryManager.acquireExecutionMemory(200L, consumer) == 200L; assert taskMemoryManager.acquireExecutionMemory(100L, consumer) == 100L; assert taskMemoryManager.acquireExecutionMemory(100L, consumer) == 100L; taskMemoryManager.cleanUpAllAllocatedMemory(); assert taskMemoryManager.acquireExecutionMemory(1000L, consumer) == 1000L; assert taskMemoryManager.acquireExecutionMemory(100L, consumer) == 100L; }
### Question: SparkContext { public SparkContext(SparkConf conf) { this.conf = conf; this.localProperties = new InheritableThreadLocal<Properties>(){ @Override protected Properties childValue(Properties parentValue) { return SerializationUtils.clone(parentValue); } @Override protected Properties initialValue() { return new Properties(); } }; init(); } SparkContext(SparkConf conf); String appName(); int executorMemory(); String applicationId(); String applicationAttemptId(); void stopInNewThread(); List<U> runJob(RDD<T> rdd, PartitionFunction<T, U> partitionFunc, List<Integer> partitions); void runJob(RDD<T> rdd, PartitionFunction<T, U> partitionFunc, List<Integer> partitions, com.sdu.spark.scheduler.action.PartitionResultHandler<U> partitionResultHandler); CallSite getCallSite(); int newShuffleId(); int newRddId(); Broadcast<T> broadcast(T value); Properties getLocalProperties(); void setLocalProperties(Properties props); void setLocalProperty(String key, String value); String getLocalProperty(String key); static final String SPARK_JOB_INTERRUPT_ON_CANCEL; static final String DRIVER_IDENTIFIER; static final String LEGACY_DRIVER_IDENTIFIER; public AtomicBoolean stopped; public SparkConf conf; public SparkEnv env; public LiveListenerBus listenerBus; public SchedulerBackend schedulerBackend; public TaskScheduler taskScheduler; public Map<String, String> executorEnvs; }### Answer: @Test public void testSparkContext() { }
### Question: DiskBlockManager { public BlockId[] getAllBlocks() { File[] blockFiles = getAllFiles(); BlockId[] blockIds = new BlockId[blockFiles.length]; for (int i = 0; i < blockFiles.length; ++i) { blockIds[i] = BlockId.apply(blockFiles[i].getName()); } return blockIds; } DiskBlockManager(SparkConf conf, boolean deleteFilesOnStop); File getFile(BlockId blockId); boolean containsBlock(BlockId blockId); File[] getAllFiles(); BlockId[] getAllBlocks(); Tuple2<BlockId, File> createTempLocalBlock(); Tuple2<TempShuffleBlockId, File> createTempShuffleBlock(); void stop(); public SparkConf conf; public boolean deleteFilesOnStop; public File[] localDirs; public int subDirsPerLocalDir; }### Answer: @Test public void testMultiBlocks() { List<BlockId.ShuffleBlockId> blockIs = Lists.newLinkedList(); for (int i = 0; i < 100; ++i) { blockIs.add(new BlockId.ShuffleBlockId(1, i, 0)); } List<File> shuffleFiles = blockIs.stream().map(diskBlockManager::getFile).collect(Collectors.toList()); shuffleFiles.forEach(file -> writeToFile(file, 5)); assert diskBlockManager.getAllBlocks().length == blockIs.size(); }
### Question: LineChart extends AbstractLineChart { public final void setSparkline(final boolean isSparkline) { this.isSparkline = isSparkline; } LineChart(final ImmutableList<? extends Plot> lines); final void setSparkline(final boolean isSparkline); }### Answer: @Test public void test4() { final Line line = Plots.newLine(Data.newData(0, 50, 100), GREEN); final LineChart chart = GCharts.newLineChart(line); chart.setSparkline(true); chart.setTitle("Foobar"); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); }
### Question: Data { @Override public String toString() { return Arrays.toString(data); } Data(final double... data); @Override String toString(); final double[] getData(); final int getSize(); static Data newData(final double... data); static Data newData(final List<? extends Number> data); static final double MIN_VALUE; static final double MAX_VALUE; static final Data INVALID; }### Answer: @Test public void testData1() { Data data = new Data(-1, 0, 100); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(data.toString()); assertEquals("Junit error", "[-1.0, 0.0, 100.0]", data.toString()); }
### Question: AxisStyle implements Kloneable<AxisStyle> { public static AxisStyle newAxisStyle(final Color textColor, final int fontSize, final AxisTextAlignment alignment) { checkNotNull(textColor, "color must not be null"); checkArgument(fontSize > 0, "fontsize must be > 0"); checkNotNull(alignment, "alignment must not be null"); return new AxisStyle(textColor, fontSize, alignment); } AxisStyle(final Color textColor, final int fontSize, final AxisTextAlignment alignment); private AxisStyle(final AxisStyle axisStyle); AxisStyle klone(); Color getTextColor(); int getFontSize(); AxisTextAlignment getAlignment(); Boolean drawTickMarks(); void setDrawTickMarks(final boolean drawTickMarks); Integer getTickMarkLength(); void setTickMarkLength(final int tickMarkLength); Color getTickMarkColor(); void setTickMarkColor(final Color tickMarkColor); static AxisStyle newAxisStyle(final Color textColor, final int fontSize, final AxisTextAlignment alignment); }### Answer: @Test public void testAxisAlignment() { final LineChart chart = TestUtil.getBasicChart(); chart.setGrid(50, 50, 5, 0); AxisStyle axisStyle = AxisStyle.newAxisStyle(RED, 16, AxisTextAlignment.LEFT); AxisLabels axisLabels = AxisLabelsFactory.newAxisLabels("Foo", 50); axisLabels.setAxisStyle(axisStyle); chart.addXAxisLabels(axisLabels); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); }
### Question: AbstractAxisChart extends AbstractGraphChart implements GridChart { public final void setGrid(final double xAxisStepSize, final double yAxisStepSize, final int lengthOfLineSegment, final int lengthOfBlankSegment) { checkArgument(xAxisStepSize > 0, "xAxisStepSize must be positive: %s", xAxisStepSize); checkArgument(yAxisStepSize > 0, "yAxisStepSize must be positive: %s", yAxisStepSize); checkArgument(lengthOfLineSegment >= 0, "lengthOfLineSegment must be 0 or positive: %s", lengthOfLineSegment); checkArgument(lengthOfBlankSegment >= 0, "lengthOfBlankSegment must be 0 or positive: %s", lengthOfBlankSegment); this.xAxisStepSize = xAxisStepSize; this.yAxisStepSize = yAxisStepSize; gridLineStyle = LineStyle.newLineStyle(1, lengthOfLineSegment, lengthOfBlankSegment); } AbstractAxisChart(); final void addXAxisLabels(final AxisLabels axisLabels); final void addYAxisLabels(final AxisLabels axisLabels); final void addTopAxisLabels(final AxisLabels axisLabels); final void addRightAxisLabels(final AxisLabels axisLabels); final void addMarker(final Marker marker, final double xPos, final double yPos); final void setGrid(final double xAxisStepSize, final double yAxisStepSize, final int lengthOfLineSegment, final int lengthOfBlankSegment); }### Answer: @Test public void testSetGrid0() { try { final LineChart chart = getBasicChart(); chart.setGrid(0, 0, 0, 0); } catch (IllegalArgumentException e) { return; } fail(); } @Test public void testSetGrid1() { final LineChart chart = getBasicChart(); chart.setGrid(10, 10, 1, 0); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); }
### Question: AbstractAxisChart extends AbstractGraphChart implements GridChart { public final void addXAxisLabels(final AxisLabels axisLabels) { checkNotNull(axisLabels, "axisLabel cannnot be null"); xAxisLabels.add((AxisLabelsImpl) axisLabels.klone()); } AbstractAxisChart(); final void addXAxisLabels(final AxisLabels axisLabels); final void addYAxisLabels(final AxisLabels axisLabels); final void addTopAxisLabels(final AxisLabels axisLabels); final void addRightAxisLabels(final AxisLabels axisLabels); final void addMarker(final Marker marker, final double xPos, final double yPos); final void setGrid(final double xAxisStepSize, final double yAxisStepSize, final int lengthOfLineSegment, final int lengthOfBlankSegment); }### Answer: @Test public void testXAxisLabels0() { final LineChart chart = getBasicChart(); chart.addXAxisLabels(AxisLabelsFactory.newAxisLabels("start", "end")); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); } @Test public void testXAxisLabels1() { final LineChart chart = TestUtil.getBasicChart(); final AxisLabels ai = AxisLabelsFactory.newAxisLabels("start", "end"); ai.setAxisStyle(AxisStyle.newAxisStyle(RED, 14, AxisTextAlignment.RIGHT)); chart.addXAxisLabels(ai); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); }
### Question: AbstractAxisChart extends AbstractGraphChart implements GridChart { public final void addYAxisLabels(final AxisLabels axisLabels) { checkNotNull(axisLabels, "axisLabel cannnot be null"); yAxisLabels.add((AxisLabelsImpl) axisLabels.klone()); } AbstractAxisChart(); final void addXAxisLabels(final AxisLabels axisLabels); final void addYAxisLabels(final AxisLabels axisLabels); final void addTopAxisLabels(final AxisLabels axisLabels); final void addRightAxisLabels(final AxisLabels axisLabels); final void addMarker(final Marker marker, final double xPos, final double yPos); final void setGrid(final double xAxisStepSize, final double yAxisStepSize, final int lengthOfLineSegment, final int lengthOfBlankSegment); }### Answer: @Test public void testYAxisLabels() { final LineChart chart = getBasicChart(); chart.addYAxisLabels(AxisLabelsFactory.newAxisLabels("start", "end")); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); }
### Question: AbstractAxisChart extends AbstractGraphChart implements GridChart { public final void addTopAxisLabels(final AxisLabels axisLabels) { checkNotNull(axisLabels, "axisLabel cannnot be null"); topAxisLabels.add((AxisLabelsImpl) axisLabels.klone()); } AbstractAxisChart(); final void addXAxisLabels(final AxisLabels axisLabels); final void addYAxisLabels(final AxisLabels axisLabels); final void addTopAxisLabels(final AxisLabels axisLabels); final void addRightAxisLabels(final AxisLabels axisLabels); final void addMarker(final Marker marker, final double xPos, final double yPos); final void setGrid(final double xAxisStepSize, final double yAxisStepSize, final int lengthOfLineSegment, final int lengthOfBlankSegment); }### Answer: @Test public void testTopAxisLabels() { final LineChart chart = getBasicChart(); chart.addTopAxisLabels(AxisLabelsFactory.newAxisLabels("start", "end")); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); }
### Question: AbstractAxisChart extends AbstractGraphChart implements GridChart { public final void addRightAxisLabels(final AxisLabels axisLabels) { checkNotNull(axisLabels, "axisLabels cannnot be null"); rightAxisLabels.add((AxisLabelsImpl) axisLabels.klone()); } AbstractAxisChart(); final void addXAxisLabels(final AxisLabels axisLabels); final void addYAxisLabels(final AxisLabels axisLabels); final void addTopAxisLabels(final AxisLabels axisLabels); final void addRightAxisLabels(final AxisLabels axisLabels); final void addMarker(final Marker marker, final double xPos, final double yPos); final void setGrid(final double xAxisStepSize, final double yAxisStepSize, final int lengthOfLineSegment, final int lengthOfBlankSegment); }### Answer: @Test public void testRightAxisLabels() { final LineChart chart = getBasicChart(); chart.addRightAxisLabels(AxisLabelsFactory.newAxisLabels("start", "end")); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); }
### Question: AbstractAxisChart extends AbstractGraphChart implements GridChart { public final void addMarker(final Marker marker, final double xPos, final double yPos) { checkNotNull(marker, "marker cannnot be null"); checkArgument(xPos >= 0 && xPos <= 100, "xPos must be >= 0 and <= 100: %s", xPos); checkArgument(yPos >= 0 && yPos <= 100, "yPos must be >= 0 and <= 100: %s", yPos); freeMarkers.add(new FreeMarker(marker, xPos, yPos)); } AbstractAxisChart(); final void addXAxisLabels(final AxisLabels axisLabels); final void addYAxisLabels(final AxisLabels axisLabels); final void addTopAxisLabels(final AxisLabels axisLabels); final void addRightAxisLabels(final AxisLabels axisLabels); final void addMarker(final Marker marker, final double xPos, final double yPos); final void setGrid(final double xAxisStepSize, final double yAxisStepSize, final int lengthOfLineSegment, final int lengthOfBlankSegment); }### Answer: @Test public void addFreeShapeMarkersToBarChart() { final BarChart chart = getBasicBarChart(); chart.addMarker(Markers.newShapeMarker(Shape.ARROW, RED, 12,Priority.LOW), 50, 80); chart.addMarker(Markers.newShapeMarker(Shape.X, BLUE, 12,Priority.HIGH), 50, 80); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); } @Test public void addFreeTextMarkerToLineChart() { final LineChart chart = getBasicChart(); chart.addMarker(Markers.newTextMarker("charts4j", RED, 20), 10, 80); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); }
### Question: UrlUtil { public static String normalize(final String s) { if (s == null) { return ""; } final ImmutableList<String> stringList = Lists.of(s.split("\\?")); if (stringList.size() != 2) { return s; } final String args = stringList.get(1); final List<String> params = Arrays.asList(args.split("&")); Collections.sort(params); final StringBuilder sb = new StringBuilder(stringList.get(0) + "?"); int cnt = 0; for (String p : params) { sb.append(cnt++ > 0 ? "&" : "").append(p); } return sb.toString(); } private UrlUtil(); static String normalize(final String s); }### Answer: @Test public void testNormalize() { final String unnormalizedString = "http: final String expectedString = "http: assertEquals("Junit error", normalize(expectedString), UrlUtil.normalize(unnormalizedString)); }
### Question: LineStyle { public static LineStyle newLineStyle(final int lineThickness, final int lengthOfLineSegment, final int lengthOfBlankSegment) { checkArgument(lineThickness > 0, "line thickness must be > 0: %s", lineThickness); checkArgument(lengthOfLineSegment >= 0, "length of line segment must be >= 0: %s", lengthOfLineSegment); checkArgument(lengthOfBlankSegment >= 0, "length of blank segment must be > 0: %s", lengthOfBlankSegment); return new LineStyle(lineThickness, lengthOfLineSegment, lengthOfBlankSegment); } LineStyle(final int lineThickness, final int lengthOfLineSegment, final int lengthOfBlankSegment); int getLineThickness(); int getLengthOfLineSegment(); int getLengthOfBlankSegment(); static LineStyle newLineStyle(final int lineThickness, final int lengthOfLineSegment, final int lengthOfBlankSegment); static final LineStyle THICK_LINE; static final LineStyle MEDIUM_LINE; static final LineStyle THIN_LINE; static final LineStyle THICK_DOTTED_LINE; static final LineStyle MEDIUM_DOTTED_LINE; static final LineStyle THIN_DOTTED_LINE; }### Answer: @Test public void testNewLineStyle0() { try { final Line line = TestUtil.getBasicLine(); line.setLineStyle(LineStyle.newLineStyle(0, 0, 0)); } catch (IllegalArgumentException e) { return; } fail(); }
### Question: GCharts { public static LineChart newLineChart(final Line... plots) { checkNotNull(plots, "plots cannot be null or contain a null."); checkContentsNotNull(Arrays.asList(plots), "plots cannot be null or contain a null."); return new LineChart(Plots.copyOf(plots)); } private GCharts(); static LineChart newLineChart(final Line... plots); static LineChart newLineChart(final Plot... plots); static LineChart newLineChart(final List<? extends Plot> plots); static RadarChart newRadarChart(final RadarPlot... plots); static RadarChart newRadarChart(final Plot... plots); static RadarChart newRadarChart(final List<? extends Plot> plots); static BarChart newBarChart(final BarChartPlot... plots); static BarChart newBarChart(final Plot... plots); static BarChart newBarChart(final List<? extends Plot> plots); static XYLineChart newXYLineChart(final XYLine... plots); static XYLineChart newXYLineChart(final Plot... plots); static XYLineChart newXYLineChart(final List<? extends Plot> plots); static ScatterPlot newScatterPlot(final ScatterPlotData scatterPlotData); static ScatterPlot newScatterPlot(final Plot scatterPlotData); static PieChart newPieChart(final Slice... slices); static PieChart newPieChart(final List<? extends Slice> slices); static VennDiagram newVennDiagram(final double circle1Size, final double circle2Size, final double circle3Size, final double abIntersect, final double caIntersect, final double bcIntersect, final double abcIntersect); static GoogleOMeter newGoogleOMeter(final double data); static GoogleOMeter newGoogleOMeter(final double data,final String label); @Deprecated //Since 1.1 Going away in future release. static GoogleOMeter newGoogleOMeter(final double data, final String label, final Color... colors); @Deprecated //Since 1.1 Going away in future release. static GoogleOMeter newGoogleOMeter(final double data, final String label, final List<? extends Color> colors); static GoogleOMeter newGoogleOMeter(final double data, final String label, final String legend, final Color... colors); static GoogleOMeter newGoogleOMeter(final double data, final String label, final String legend, final List<? extends Color> colors); static MapChart newMapChart(final GeographicalArea geographicalArea); }### Answer: @Test public void testNewLineChart0() { try { Line[] lines = null; GCharts.newLineChart(lines); } catch (NullPointerException e) { return; } } @Test public void testNewLineChart1() { try { Line[] lines = { TestUtil.getBasicLine(), null }; GCharts.newLineChart(lines); } catch (NullPointerException e) { return; } }
### Question: PieChart extends AbstractGraphChart { public final void setThreeD(final boolean threeD) { this.threeD = threeD; } PieChart(final ImmutableList<? extends Slice> slices); void setOrientation(final double radians); final boolean isThreeD(); final void setThreeD(final boolean threeD); }### Answer: @Test public void basicTest() { final Slice s1 = Slice.newSlice(45, GRAY, "Safari", "X"); final Slice s2 = Slice.newSlice(45, ORANGERED, "Firefox", "Y"); final Slice s3 = Slice.newSlice(10, BLUE, "Internet Explorer", "Z"); PieChart chart = GCharts.newPieChart(s1, s2, s3); chart.setTitle("A Better World 1"); chart.setSize(500, 200); chart.setThreeD(true); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); } @Test public void nocolorTest() { final Slice s1 = Slice.newSlice(45, "Safari"); final Slice s2 = Slice.newSlice(45, "Firefox"); final Slice s3 = Slice.newSlice(10, "Internet Explorer"); PieChart chart = GCharts.newPieChart(s1, s2, s3); chart.setTitle("A Better World 2"); chart.setSize(500, 200); chart.setThreeD(true); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); } @Test public void interpolatedColorTest() { final Slice s1 = Slice.newSlice(45, GRAY, "Safari", "A"); final Slice s2 = Slice.newSlice(45, "Firefox"); final Slice s3 = Slice.newSlice(10, BLUE, "Internet Explorer", "B"); PieChart chart = GCharts.newPieChart(s1, s2, s3); chart.setTitle("A Better World 3"); chart.setSize(500, 200); chart.setThreeD(true); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); } @Test public void fillTest() { final Slice s1 = Slice.newSlice(45, GRAY, "Safari", "X"); final Slice s2 = Slice.newSlice(45, ORANGERED, "Firefox", "Y"); final Slice s3 = Slice.newSlice(10, BLUE, "Internet Explorer", "Z"); PieChart chart = GCharts.newPieChart(s1, s2, s3); chart.setTitle("A Better World 1"); chart.setSize(500, 200); chart.setAreaFill(Fills.newSolidFill(BLACK)); chart.setBackgroundFill(Fills.newSolidFill(LIGHTGREY)); chart.setThreeD(true); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); }
### Question: PieChart extends AbstractGraphChart { public void setOrientation(final double radians) { this.orientation = radians; } PieChart(final ImmutableList<? extends Slice> slices); void setOrientation(final double radians); final boolean isThreeD(); final void setThreeD(final boolean threeD); }### Answer: @Test public void orientationTest() { final Slice s1 = Slice.newSlice(450, "Safari"); final Slice s2 = Slice.newSlice(450, "Firefox"); final Slice s3 = Slice.newSlice(100, "Internet Explorer"); PieChart chart = GCharts.newPieChart(s1, s2, s3); chart.setOrientation(3.14/2); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); }
### Question: AbstractMarkableChart extends AbstractAxisChart { public final void addHorizontalRangeMarker(final double startPoint, final double endPoint, final Color color) { checkRangeArgs(startPoint, endPoint); checkNotNull(color, "Color cannot be null."); horizontalRangeMarkers.add(new HorizontalRangeMarker(color, startPoint, endPoint)); } AbstractMarkableChart(); final void addVerticalRangeMarker(final double startPoint, final double endPoint, final Color color); final void addHorizontalRangeMarker(final double startPoint, final double endPoint, final Color color); }### Answer: @Test public void testAddVerticalRangeMarker0() { try { final LineChart chart = getBasicChart(); chart.addHorizontalRangeMarker(100, 200, RED); } catch (IllegalArgumentException e) { return; } fail(); } @Test public void testAddVerticalRangeMarker1() { final LineChart chart = getBasicChart(); chart.addHorizontalRangeMarker(29, 30, RED); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); }
### Question: AbstractGraphChart extends AbstractGChart implements GraphChart, TitledChart { public final void setTitle(final String title) { checkNotNull(title, "Title cannot be null."); this.chartTitle = new ChartTitle(title); } AbstractGraphChart(); final void setTitle(final String title); final void setTitle(final String title, final Color color, final int fontSize); final void setLegendPosition(final LegendPosition legendPosition); void setLegendMargins(final int legendWidth, final int legendHeight); final void setAreaFill(final Fill fill); }### Answer: @Test public void testSetTitleString0() { try { final LineChart chart = getBasicChart(); chart.setTitle(null); } catch (NullPointerException e) { return; } fail(); } @Test public void testSetTitleString1() { final LineChart chart = getBasicChart(); chart.setTitle("foo"); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); } @Test public void testSetTitleStringColorInt0() { try { final LineChart chart = getBasicChart(); chart.setTitle("foo", RED, 0); } catch (IllegalArgumentException e) { return; } fail(); } @Test public void testSetTitleStringColorInt1() { final LineChart chart = getBasicChart(); chart.setTitle("foo", RED, 20); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); }
### Question: AbstractMarkableChart extends AbstractAxisChart { public final void addVerticalRangeMarker(final double startPoint, final double endPoint, final Color color) { checkRangeArgs(startPoint, endPoint); checkNotNull(color, "Color cannot be null."); verticalRangeMarkers.add(new VerticalRangeMarker(color, startPoint, endPoint)); } AbstractMarkableChart(); final void addVerticalRangeMarker(final double startPoint, final double endPoint, final Color color); final void addHorizontalRangeMarker(final double startPoint, final double endPoint, final Color color); }### Answer: @Test public void testAddHorizontalRangeMarker0() { try { final LineChart chart = getBasicChart(); chart.addVerticalRangeMarker(100, 200, RED); } catch (IllegalArgumentException e) { return; } fail(); } @Test public void testAddHorizontalRangeMarker1() { final LineChart chart = getBasicChart(); chart.addVerticalRangeMarker(29, 30, RED); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); }
### Question: MapChart extends AbstractGChart { public final void addPoliticalBoundaries(final PoliticalBoundary... politicalBoundaries) { pBoundaries.addAll(Lists.of(politicalBoundaries)); } MapChart(final GeographicalArea geographicalArea); final void setColorGradient(final Color defaultColor, final Color... colorGradient); final void addPoliticalBoundary(final PoliticalBoundary politicalBoundary); final void addPoliticalBoundaries(final PoliticalBoundary... politicalBoundaries); final void addPoliticalBoundaries(final List<? extends PoliticalBoundary> politicalBoundaries); @Override final void setSize(final int width, final int height); }### Answer: @Test public void test() { MapChart chart = GCharts.newMapChart(GeographicalArea.AFRICA); chart.addPoliticalBoundaries(new Country(MADAGASCAR, 90)); chart.addPoliticalBoundaries(new Country(MOROCCO, 10)); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); }
### Question: DataUtil { public static Data scaleWithinRange(final double min, final double max, final double[] data) { checkArgument(max - min > 0, "min >= max!"); return Data.newData(privateScale(data, min, max)); } private DataUtil(); static Data scaleWithinRange(final double min, final double max, final double[] data); static Data scaleWithinRange(final double min, final double max, final List<? extends Number> data); static Data scale(final double... data); static Data scale(final List<? extends Number> data); static List<Data> scale(final double data[][]); static List<Data> scaleDataList(final List<? extends List<? extends Number>> data); }### Answer: @Test public void testScaleData0() { Data data = DataUtil.scaleWithinRange(0, 10, new double[] { 1, 2, 3, 4, 5, 6 }); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(data.toString()); assertEquals("Junit error", "[10.0, 20.0, 30.0, 40.0, 50.0, 60.0]", data.toString()); } @Test public void testScaleData3() { Data data = DataUtil.scaleWithinRange(0, 10, Arrays.asList(1, 2, 3, 4, 5, 6)); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(data.toString()); assertEquals("Junit error", "[10.0, 20.0, 30.0, 40.0, 50.0, 60.0]", data.toString()); }
### Question: DataUtil { public static Data scale(final double... data) { checkNotNull(data, "data is null or contents of data is null."); final double min = Collections.min(PrimitiveArrays.asList(data)); final double max = Collections.max(PrimitiveArrays.asList(data)); checkArgument(min < max, "Cannot scale this data. It is ill conditioned."); return Data.newData(privateScale(data, min, max)); } private DataUtil(); static Data scaleWithinRange(final double min, final double max, final double[] data); static Data scaleWithinRange(final double min, final double max, final List<? extends Number> data); static Data scale(final double... data); static Data scale(final List<? extends Number> data); static List<Data> scale(final double data[][]); static List<Data> scaleDataList(final List<? extends List<? extends Number>> data); }### Answer: @Test public void testScaleData1() { Data data = DataUtil.scale(1, 2, 3, 4, 5, 6); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(data.toString()); assertEquals("Junit error", "[0.0, 20.0, 40.0, 60.0, 80.0, 100.0]", data.toString()); } @Test public void testScaleData2() { Data data = DataUtil.scale(-10, 1, 2, 3, 4, 5, 6); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(data.toString()); assertEquals("Junit error", "[0.0, 68.75, 75.0, 81.25, 87.5, 93.75, 100.0]", data.toString()); } @Test public void testScaleData4() { double d0[] = new double[] { 4, 5, 6 }; double d1[] = new double[] { 0, 5, 10 }; double d[][] = new double[][] { d0, d1 }; List<Data> data = DataUtil.scale(d); assertEquals("Junit error", "[[40.0, 50.0, 60.0], [0.0, 50.0, 100.0]]", data.toString()); }
### Question: DataUtil { public static List<Data> scaleDataList(final List<? extends List<? extends Number>> data) { checkContentsNotNull(data, "data is null or contents of data is null."); final double[][] d = new double[data.size()][]; int j = 0; for (List<? extends Number> datum : data) { checkContentsNotNull(datum, "data is null or contents of data is null."); double[] plotData = new double[datum.size()]; int i = 0; for (Number n : datum) { plotData[i++] = n.doubleValue(); } d[j++] = plotData; } return scale(d); } private DataUtil(); static Data scaleWithinRange(final double min, final double max, final double[] data); static Data scaleWithinRange(final double min, final double max, final List<? extends Number> data); static Data scale(final double... data); static Data scale(final List<? extends Number> data); static List<Data> scale(final double data[][]); static List<Data> scaleDataList(final List<? extends List<? extends Number>> data); }### Answer: @Test public void testScaleData5() { double d0[] = new double[] { 4, 5, 6 }; double d1[] = new double[] { 0, 5, 10 }; List<Double> l0 = PrimitiveArrays.asList(d0); List<Double> l1 = PrimitiveArrays.asList(d1); List<List<Double>> d = new LinkedList<List<Double>>(); d.add(l0); d.add(l1); List<Data> data = DataUtil.scaleDataList(d); assertEquals("Junit error", "[[40.0, 50.0, 60.0], [0.0, 50.0, 100.0]]", data.toString()); }
### Question: DataParameter extends AbstractParameter { void addData(final Data data) { datas.add(data); } DataParameter(); @Override String getKey(); @Override String getValue(); }### Answer: @Test public void test0() { final Data data = new Data(1, 2, 3); final DataParameter p = new DataParameter(); p.addData(data); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chd=e:ApBSB7"; assertEquals("Junit error", expectedString, p.toURLParameterString()); }
### Question: PieChartAndGoogleOMeterLegendParameter extends AbstractParameter { void addLegend(final String legend) { this.legends.add(legend); } @Override String getKey(); @Override String getValue(); }### Answer: @Test public void test0() { final PieChartAndGoogleOMeterLegendParameter p = new PieChartAndGoogleOMeterLegendParameter(); p.addLegend("foo"); p.addLegend("bar"); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chl=foo|bar"; assertEquals("Junit error", expectedString, p.toURLParameterString()); }
### Question: AxisTypesParameter extends AbstractParameter { void addAxisTypes(final AxisTypes axisTypes) { axisTypesList.add(axisTypes); } @Override String getKey(); @Override String getValue(); }### Answer: @Test public void test0() { final AxisTypesParameter p = new AxisTypesParameter(); p.addAxisTypes(AxisTypes.BOTTOM_X_AXIS); p.addAxisTypes(AxisTypes.TOP_X_AXIS); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chxt=x,t"; assertEquals("Junit error", expectedString, p.toURLParameterString()); }
### Question: AxisLabelPositionsParameter extends AbstractParameter { void addLabelPosition(final int index, final ImmutableList<? extends Number> positions) { labelPositions.add(new AxisLabelPositions(index, positions)); } @Override String getKey(); @Override String getValue(); }### Answer: @Test public void test0() { final AxisLabelPositionsParameter p = new AxisLabelPositionsParameter(); p.addLabelPosition(1, Lists.of(1, 2, 3)); p.addLabelPosition(2, Lists.of(7, 8, 9)); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chxp=1,1,2,3|2,7,8,9"; assertEquals("Junit error", expectedString, p.toURLParameterString()); } @Test public void test2() { AxisLabelPositionsParameter p = new AxisLabelPositionsParameter(); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); p.addLabelPosition(2, Lists.of(1, 2, 3)); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chxp=2,1,2,3"; assertEquals("Junit error", expectedString, p.toURLParameterString()); }
### Question: ColorsParameter extends AbstractParameter { void addColors(final ImmutableList<? extends ImmutableList<? extends Color>> colors) { for (ImmutableList<? extends Color> listOfColors : colors) { final List<Color> l = Lists.newLinkedList(); l.addAll(listOfColors); this.colors.add(l); } } @Override String getKey(); @Override String getValue(); }### Answer: @Test public void test0() { final ColorsParameter p = new ColorsParameter(); List<ImmutableList<Color>> colors = Lists.newLinkedList(); colors.add(Lists.of(BLUE)); p.addColors(Lists.copyOf(colors)); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chco=0000FF"; assertEquals("Junit error", expectedString, p.toURLParameterString()); } @Test public void test1() { final ColorsParameter p = new ColorsParameter(); List<ImmutableList<Color>> colors = Lists.newLinkedList(); colors.add(Lists.of(BLUE)); colors.add(Lists.of(RED)); p.addColors(Lists.copyOf(colors)); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chco=0000FF,FF0000"; assertEquals("Junit error", expectedString, p.toURLParameterString()); }
### Question: AxisStylesParameter extends AbstractParameter { void addAxisStyle(final int index, final AxisStyle axisStyle) { axisStyles.add(new PrivateAxisStyles(index, axisStyle)); } @Override String getKey(); @Override String getValue(); }### Answer: @Test public void test0() { final AxisStylesParameter p = new AxisStylesParameter(); p.addAxisStyle(1, AxisStyle.newAxisStyle(BLUE, 12, AxisTextAlignment.CENTER)); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chxs=1,0000FF,12,0"; assertEquals("Junit error", expectedString, p.toURLParameterString()); } @Test public void test1() { final AxisStylesParameter p = new AxisStylesParameter(); p.addAxisStyle(1, AxisStyle.newAxisStyle(BLUE, 12, AxisTextAlignment.CENTER)); p.addAxisStyle(2, AxisStyle.newAxisStyle(RED, 12, AxisTextAlignment.CENTER)); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chxs=1,0000FF,12,0|2,FF0000,12,0"; assertEquals("Junit error", expectedString, p.toURLParameterString()); } @Test public void test4() { final AxisStylesParameter p = new AxisStylesParameter(); final AxisStyle axisStyle = AxisStyle.newAxisStyle(BLUE, 12, AxisTextAlignment.CENTER); p.addAxisStyle(1, axisStyle); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chxs=1,0000FF,12,0"; assertEquals("Junit error", expectedString, p.toURLParameterString()); } @Test public void test5() { final AxisStylesParameter p = new AxisStylesParameter(); final AxisStyle axisStyle = AxisStyle.newAxisStyle(BLUE, 12, AxisTextAlignment.CENTER); axisStyle.setDrawTickMarks(true); axisStyle.setTickMarkColor(RED); p.addAxisStyle(1, axisStyle); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chxs=1,0000FF,12,0,lt,FF0000"; assertEquals("Junit error", expectedString, p.toURLParameterString()); } @Test public void test6() { final AxisStylesParameter p = new AxisStylesParameter(); final AxisStyle axisStyle = AxisStyle.newAxisStyle(BLUE, 12, AxisTextAlignment.CENTER); axisStyle.setDrawTickMarks(false); p.addAxisStyle(1, axisStyle); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chxs=1,0000FF,12,0,l"; assertEquals("Junit error", expectedString, p.toURLParameterString()); }
### Question: ChartFillsParameter extends AbstractParameter { void addLinearGradientFill(final FillType fillType, final int angle, final ImmutableList<? extends ColorAndOffset> colorAndOffsets) { fills.add(new LinearGradient(fillType, angle, colorAndOffsets)); } @Override String getKey(); @Override String getValue(); }### Answer: @Test public void test0() { final ChartFillsParameter p = new ChartFillsParameter(); p.addLinearGradientFill(FillType.CHART_AREA, 45, Lists.of(new ColorAndOffset(RED, 50))); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chf=c,lg,45,FF0000,0.5"; assertEquals("Junit error", expectedString, p.toURLParameterString()); }
### Question: ChartFillsParameter extends AbstractParameter { void addLinearStripeFill(final FillType fillType, final int angle, final ImmutableList<? extends ColorAndWidth> colorAndWidths) { fills.add(new LinearStripes(fillType, angle, colorAndWidths)); } @Override String getKey(); @Override String getValue(); }### Answer: @Test public void test1() { final ChartFillsParameter p = new ChartFillsParameter(); p.addLinearStripeFill(FillType.BACKGROUND, 20, Lists.of(new ColorAndWidth(RED, 50))); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chf=bg,ls,20,FF0000,0.5"; assertEquals("Junit error", expectedString, p.toURLParameterString()); }
### Question: ChartFillsParameter extends AbstractParameter { void addSolidFill(final SolidFillType solidFillType, final Color color) { fills.add(new Solid(solidFillType, color)); } @Override String getKey(); @Override String getValue(); }### Answer: @Test public void test2() { final ChartFillsParameter p = new ChartFillsParameter(); p.addSolidFill(SolidFillType.TRANSPARENCY, BLUE); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chf=a,s,0000FF"; assertEquals("Junit error", expectedString, p.toURLParameterString()); }
### Question: AxisRangesParameter extends AbstractParameter { void addAxisRange(final int index, final double startOfRange, final double endOfRange, final double interval) { axisRanges.add(new AxisRange(index, startOfRange, endOfRange, interval)); } @Override String getKey(); @Override String getValue(); }### Answer: @Test public void test0() { final AxisRangesParameter p = new AxisRangesParameter(); p.addAxisRange(1, 10, 30, Double.NaN); p.addAxisRange(2, 12, 15, 1); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chxr=1,10.0,30.0|2,12.0,15.0,1.0"; assertEquals("Junit error", expectedString, p.toURLParameterString()); }
### Question: DataLegendsParameter extends AbstractParameter { void addLegends(final ImmutableList<? extends String> legends) { this.legends.addAll(legends); } @Override String getKey(); @Override String getValue(); }### Answer: @Test public void test0() { final DataLegendsParameter p = new DataLegendsParameter(); p.addLegends(Lists.of("foo", "bar")); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chdl=foo|bar"; assertEquals("Junit error", expectedString, p.toURLParameterString()); }
### Question: ChartMarkersParameter extends AbstractParameter { void addFillAreaMarker(final FillAreaType fillAreaType, final Color color, final int startLineIndex, final int endLineIndex) { markers.add(new FillAreaMarker(fillAreaType, color, startLineIndex, endLineIndex)); } @Override String getKey(); @Override String getValue(); }### Answer: @Test public void test0() { final ChartMarkersParameter p = new ChartMarkersParameter(); p.addFillAreaMarker(FillAreaType.FULL, RED, 1, 3); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chm=B,FF0000,1,3,0"; assertEquals("Junit error", expectedString, p.toURLParameterString()); }
### Question: ChartMarkersParameter extends AbstractParameter { void addLineStyleMarker(final Color color, final int dataSetIndex, final int dataPoint, final int size, final Priority priority) { markers.add(new LineStyleMarker(color, dataSetIndex, dataPoint, size, priority)); } @Override String getKey(); @Override String getValue(); }### Answer: @Test public void test1() { final ChartMarkersParameter p = new ChartMarkersParameter(); p.addLineStyleMarker(BLUE, 1, 3, 12, Priority.HIGH); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chm=D,0000FF,1,3,12,1"; assertEquals("Junit error", expectedString, p.toURLParameterString()); }
### Question: ChartMarkersParameter extends AbstractParameter { void addHorizontalRangeMarker(final Color color, final double startPoint, final double endPoint) { markers.add(new RangeMarker(RangeType.HORIZONTAL, color, startPoint, endPoint)); } @Override String getKey(); @Override String getValue(); }### Answer: @Test public void test2() { final ChartMarkersParameter p = new ChartMarkersParameter(); p.addHorizontalRangeMarker(WHEAT, 0.1, 0.3); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chm=r,F5DEB3,0,0.10,0.30"; assertEquals("Junit error", expectedString, p.toURLParameterString()); }
### Question: ChartMarkersParameter extends AbstractParameter { void addMarker(final Marker marker, final int dataSetIndex, final int startIndex, final int endIndex, final int n) { if (marker instanceof ShapeMarker) { markers.add(new ShapeMarkerParam((ShapeMarker) marker, dataSetIndex, startIndex, endIndex, n)); } else if (marker instanceof TextMarker) { markers.add(new TextMarkerParam((TextMarker) marker, dataSetIndex, startIndex, endIndex, n)); } } @Override String getKey(); @Override String getValue(); }### Answer: @Test public void test3() { final ChartMarkersParameter p = new ChartMarkersParameter(); final Marker sm = Markers.newShapeMarker(Shape.CIRCLE, PERU, 13, Priority.LOW); p.addMarker(sm, 1, 5, 6, 1); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chm=o,CD853F,1,5,13,-1"; assertEquals("Junit error", expectedString, p.toURLParameterString()); } @Test public void test4() { final ChartMarkersParameter p = new ChartMarkersParameter(); p.addMarker(Markers.newTextMarker("foobar", BLACK, 15), 7, 5, 6, 1); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chm=tfoobar,000000,7,5,15,0"; assertEquals("Junit error", expectedString, p.toURLParameterString()); } @Test public void test5() { final ChartMarkersParameter p = new ChartMarkersParameter(); final Marker sm = Markers.newShapeMarker(Shape.CIRCLE, PERU, 13, Priority.LOW); p.addMarker(sm, 1, 5, 6, 1); p.addMarker(Markers.newTextMarker("foobar", BLACK, 15), 7, 5, 6, 1); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chm=o,CD853F,1,5,13,-1|tfoobar,000000,7,5,15,0"; assertEquals("Junit error", expectedString, p.toURLParameterString()); } @Test public void test7() { final ChartMarkersParameter p = new ChartMarkersParameter(); final Marker sm = Markers.newShapeMarker(Shape.CIRCLE, PERU, 13, Priority.LOW); p.addMarker(sm, 1, 5, 10 ,2); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chm=o,CD853F,1,5:9:2,13,-1"; assertEquals("Junit error", expectedString, p.toURLParameterString()); } @Test public void test8() { final ChartMarkersParameter p = new ChartMarkersParameter(); final Marker sm = Markers.newShapeMarker(Shape.CIRCLE, PERU, 13, Priority.LOW); p.addMarker(sm, 1, 5, 6 ,2); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chm=o,CD853F,1,5,13,-1"; assertEquals("Junit error", expectedString, p.toURLParameterString()); }
### Question: ChartMarkersParameter extends AbstractParameter { void addMarkers(final Marker marker, final int dataSetIndex) { addMarker(marker, dataSetIndex, -1, 0, 0); } @Override String getKey(); @Override String getValue(); }### Answer: @Test public void test9() { final ChartMarkersParameter p = new ChartMarkersParameter(); final Marker sm = Markers.newShapeMarker(Shape.CIRCLE, PERU, 13, Priority.LOW); p.addMarkers(sm, 1); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chm=o,CD853F,1,-1,13,-1"; assertEquals("Junit error", expectedString, p.toURLParameterString()); }
### Question: ChartMarkersParameter extends AbstractParameter { void addFreeMarker(final Marker marker, final double xPos, final double yPos) { markers.add(new FreeMarker(marker, xPos, yPos)); } @Override String getKey(); @Override String getValue(); }### Answer: @Test public void addFreeShapeMarker() { final ChartMarkersParameter p = new ChartMarkersParameter(); final Marker sm = Markers.newShapeMarker(Shape.CIRCLE, PERU, 13, Priority.LOW); p.addFreeMarker(sm, 10, 20); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chm=@o,CD853F,0,0.1:0.2,13,-1"; assertEquals("Junit error", expectedString, p.toURLParameterString()); } @Test public void addFreeTextMarker() { final ChartMarkersParameter p = new ChartMarkersParameter(); final Marker sm = Markers.newTextMarker("charts4j", PERU, 13, Priority.HIGH); p.addFreeMarker(sm, 20, 10); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chm=@tcharts4j,CD853F,0,0.2:0.1,13,1"; assertEquals("Junit error", expectedString, p.toURLParameterString()); }
### Question: GeoCodesParameter extends AbstractParameter { void addGeoCode(final String geoCodes) { this.geoCodes.add(geoCodes); } @Override String getKey(); @Override String getValue(); }### Answer: @Test public void test0() { final GeoCodesParameter p = new GeoCodesParameter(); p.addGeoCode(UNITED_STATES + ""); p.addGeoCode(AFGHANISTAN + ""); p.addGeoCode(COLORADO + ""); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chld=USAFCO"; assertEquals("Junit error", expectedString, p.toURLParameterString()); }
### Question: LineChartLineStylesParameter extends AbstractParameter { void addLineStyle(final LineStyle lineStyle) { this.lineStyles.add(new LineStyleWrapper(lineStyle)); } @Override String getKey(); @Override String getValue(); }### Answer: @Test public void test0() { final LineChartLineStylesParameter p = new LineChartLineStylesParameter(); p.addLineStyle(LineStyle.newLineStyle(5, 3, 1)); p.addLineStyle(LineStyle.newLineStyle(1, 4, 2)); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chls=5,3,1|1,4,2"; assertEquals("Junit error", expectedString, p.toURLParameterString()); }
### Question: AbstractGraphChart extends AbstractGChart implements GraphChart, TitledChart { public final void setLegendPosition(final LegendPosition legendPosition) { checkNotNull(legendPosition, "Legend position cannot be null."); this.legendPosition = legendPosition; } AbstractGraphChart(); final void setTitle(final String title); final void setTitle(final String title, final Color color, final int fontSize); final void setLegendPosition(final LegendPosition legendPosition); void setLegendMargins(final int legendWidth, final int legendHeight); final void setAreaFill(final Fill fill); }### Answer: @Test public void testSetLegendPosition0() { final Plot plot = Plots.newPlot(Data.newData(0, 50, 100), RED, "my Legend"); final LineChart chart = GCharts.newLineChart(plot); chart.setLegendPosition(LegendPosition.TOP); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); } @Test public void testSetLegendPosition1() { final Plot plot0 = Plots.newPlot(Data.newData(0, 50, 100), RED, "legend 0"); final Plot plot1 = Plots.newPlot(Data.newData(100, 50, 0), BLUE, "legend 1"); final LineChart chart = GCharts.newLineChart(plot0, plot1); chart.setLegendPosition(LegendPosition.TOP_VERTICAL); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); }
### Question: AxisLabelsParameter extends AbstractParameter { void addAxisLabels(final int index, final ImmutableList<? extends String> labels) { axisLabels.add(new AxisLabels(index, labels)); } @Override String getKey(); @Override String getValue(); }### Answer: @Test public void test0() { final AxisLabelsParameter p = new AxisLabelsParameter(); p.addAxisLabels(1, Lists.of("foo", "bar", "zap")); p.addAxisLabels(2, Lists.of("foo2", "bar2", "zap2")); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chxl=1:|foo|bar|zap|2:|foo2|bar2|zap2"; assertEquals("Junit error", expectedString, p.toURLParameterString()); } @Test public void test2() { final AxisLabelsParameter p = new AxisLabelsParameter(); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); p.addAxisLabels(2, Lists.of("foo", "bar", "zap")); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(p.toURLParameterString()); final String expectedString = "chxl=2:|foo|bar|zap"; assertEquals("Junit error", expectedString, p.toURLParameterString()); }
### Question: BarChart extends AbstractAxisChart { public final void setHorizontal(final boolean horizontal) { this.horizontal = horizontal; } BarChart(final ImmutableList<? extends Plot> barChartPlots); final void setDataStacked(final boolean dataStacked); final void setHorizontal(final boolean horizontal); final void setBarWidth(final int barWidth); final void setSpaceBetweenGroupsOfBars(final int spaceBetweenGroupsOfBars); final void setSpaceWithinGroupsOfBars(final int spaceWithinGroupsOfBars); static final int AUTO_RESIZE; }### Answer: @Test public void testHorizontalBarChart() { BarChartPlot data1 = Plots.newBarChartPlot(Data.newData(35, 50, 30, 40), BLUE, "Q1"); BarChartPlot data2 = Plots.newBarChartPlot(Data.newData(10, 20, 30, 25), RED, "Q2"); BarChart chart = GCharts.newBarChart(data1, data2); chart.setSize(200, 300); chart.setHorizontal(true); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); }
### Question: BarChart extends AbstractAxisChart { public final void setDataStacked(final boolean dataStacked) { this.dataStacked = dataStacked; } BarChart(final ImmutableList<? extends Plot> barChartPlots); final void setDataStacked(final boolean dataStacked); final void setHorizontal(final boolean horizontal); final void setBarWidth(final int barWidth); final void setSpaceBetweenGroupsOfBars(final int spaceBetweenGroupsOfBars); final void setSpaceWithinGroupsOfBars(final int spaceWithinGroupsOfBars); static final int AUTO_RESIZE; }### Answer: @Test public void testStackedDataBarChart() { BarChartPlot data1 = Plots.newBarChartPlot(Data.newData(35, 50, 30, 40), BLUE, "Q1"); BarChartPlot data2 = Plots.newBarChartPlot(Data.newData(10, 20, 30, 25), RED, "Q2"); BarChart chart = GCharts.newBarChart(data1, data2); chart.setSize(200, 300); chart.setDataStacked(true); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); }
### Question: BarChart extends AbstractAxisChart { public final void setSpaceBetweenGroupsOfBars(final int spaceBetweenGroupsOfBars) { checkArgument(spaceWithinGroupsOfBars >= 0, "spaceWithinGroupsOfBars must be >= 0"); this.spaceBetweenGroupsOfBars = spaceBetweenGroupsOfBars; } BarChart(final ImmutableList<? extends Plot> barChartPlots); final void setDataStacked(final boolean dataStacked); final void setHorizontal(final boolean horizontal); final void setBarWidth(final int barWidth); final void setSpaceBetweenGroupsOfBars(final int spaceBetweenGroupsOfBars); final void setSpaceWithinGroupsOfBars(final int spaceWithinGroupsOfBars); static final int AUTO_RESIZE; }### Answer: @Test public void testSetSpaceBetweenGroupsOfBars() { BarChartPlot data1 = Plots.newBarChartPlot(Data.newData(0, 25, 50, 75, 100), BLUE); BarChartPlot data2 = Plots.newBarChartPlot(Data.newData(0, 25, 50, 75, 100), RED); BarChart chart = GCharts.newBarChart(data1, data2); chart.setSize(400, 200); chart.setSpaceBetweenGroupsOfBars(30); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); }
### Question: BarChart extends AbstractAxisChart { public final void setBarWidth(final int barWidth) { checkArgument(barWidth > -1, "barWidth must be > 0"); this.barWidth = barWidth; } BarChart(final ImmutableList<? extends Plot> barChartPlots); final void setDataStacked(final boolean dataStacked); final void setHorizontal(final boolean horizontal); final void setBarWidth(final int barWidth); final void setSpaceBetweenGroupsOfBars(final int spaceBetweenGroupsOfBars); final void setSpaceWithinGroupsOfBars(final int spaceWithinGroupsOfBars); static final int AUTO_RESIZE; }### Answer: @Test public void testSetBarWidth() { BarChartPlot data1 = Plots.newBarChartPlot(Data.newData(0, 25, 50, 75, 100), BLUE); BarChartPlot data2 = Plots.newBarChartPlot(Data.newData(0, 25, 50, 75, 100), RED); BarChart chart = GCharts.newBarChart(data1, data2); chart.setSize(400, 200); chart.setBarWidth(30); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); } @Test public void testAutoResize() { BarChartPlot data1 = Plots.newBarChartPlot(Data.newData(5, 25, 50, 75, 100), BLUE); BarChartPlot data2 = Plots.newBarChartPlot(Data.newData(5, 25, 50, 75, 100), RED); BarChart chart = GCharts.newBarChart(data1, data2); chart.setSize(400, 200); chart.setBarWidth(BarChart.AUTO_RESIZE); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); }
### Question: BarChart extends AbstractAxisChart { public final void setSpaceWithinGroupsOfBars(final int spaceWithinGroupsOfBars) { checkArgument(spaceWithinGroupsOfBars >= 0, "spaceWithinGroupsOfBars must be >= 0"); this.spaceWithinGroupsOfBars = spaceWithinGroupsOfBars; } BarChart(final ImmutableList<? extends Plot> barChartPlots); final void setDataStacked(final boolean dataStacked); final void setHorizontal(final boolean horizontal); final void setBarWidth(final int barWidth); final void setSpaceBetweenGroupsOfBars(final int spaceBetweenGroupsOfBars); final void setSpaceWithinGroupsOfBars(final int spaceWithinGroupsOfBars); static final int AUTO_RESIZE; }### Answer: @Test public void testSetSpaceWithinGroupsOfBars() { BarChartPlot data1 = Plots.newBarChartPlot(Data.newData(0, 25, 50, 75, 100), BLUE); BarChartPlot data2 = Plots.newBarChartPlot(Data.newData(0, 25, 50, 75, 100), RED); BarChart chart = GCharts.newBarChart(data1, data2); chart.setSize(400, 200); chart.setSpaceWithinGroupsOfBars(30); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); }
### Question: AbstractGChart implements GChart { public void setSize(final int width, final int height) { checkArgument(width * height <= MAX_PIXELS, "The largest possible area for all charts except maps is 300,000 pixels."); checkArgument(width > MIN_WIDTH && width <= MAX_WIDTH, "width must be > " + MIN_WIDTH + " and <= " + MAX_WIDTH + ": %s", width); checkArgument(height > MIN_HEIGHT && height <= MAX_HEIGHT, "height must be > " + MIN_WIDTH + " and <= " + MAX_WIDTH + ": %s", height); this.width = width; this.height = height; } AbstractGChart(); void setSize(final int width, final int height); final Map<String, String> getParameters(); final String toURLString(); final String toURLForHTML(); void setBackgroundFill(final Fill fill); void setTransparency(final int opacity); final void setDataEncoding(final DataEncoding dataEncoding); void setMargins(final int leftMargin, final int rightMargin, final int topMargin, final int bottomMargin); void setURLEndpoint(final String urlEndpoint); }### Answer: @Test public void testSetSize0() { try { final LineChart chart = getBasicChart(); chart.setSize(0, 0); } catch (IllegalArgumentException e) { return; } fail(); } @Test public void testSetSize1() { try { final LineChart chart = getBasicChart(); chart.setSize(1001, 1001); } catch (IllegalArgumentException e) { return; } fail(); }
### Question: AbstractGChart implements GChart { public void setBackgroundFill(final Fill fill) { checkNotNull(fill, "The background fill cannot be null"); this.backgroundFill = fill; } AbstractGChart(); void setSize(final int width, final int height); final Map<String, String> getParameters(); final String toURLString(); final String toURLForHTML(); void setBackgroundFill(final Fill fill); void setTransparency(final int opacity); final void setDataEncoding(final DataEncoding dataEncoding); void setMargins(final int leftMargin, final int rightMargin, final int topMargin, final int bottomMargin); void setURLEndpoint(final String urlEndpoint); }### Answer: @Test public void testSetBackgroundFill() { final LineChart chart = getBasicChart(); chart.setBackgroundFill(Fills.newSolidFill(BLUE)); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); }
### Question: AbstractGChart implements GChart { public void setTransparency(final int opacity) { checkArgument(opacity >= MIN_OPACITY && opacity <= MAX_OPACITY, "opacity must be between " + MIN_OPACITY + " and " + MAX_OPACITY + ": %s", opacity); this.opacity = opacity; } AbstractGChart(); void setSize(final int width, final int height); final Map<String, String> getParameters(); final String toURLString(); final String toURLForHTML(); void setBackgroundFill(final Fill fill); void setTransparency(final int opacity); final void setDataEncoding(final DataEncoding dataEncoding); void setMargins(final int leftMargin, final int rightMargin, final int topMargin, final int bottomMargin); void setURLEndpoint(final String urlEndpoint); }### Answer: @Test public void testSetTransparency() { final LineChart chart = getBasicChart(); chart.setTransparency(10); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); }
### Question: AbstractGChart implements GChart { public void setURLEndpoint(final String urlEndpoint) { checkNotNull(urlEndpoint, "The chart URL endpoint cannot be null"); this.chartURLEndpoint = urlEndpoint; } AbstractGChart(); void setSize(final int width, final int height); final Map<String, String> getParameters(); final String toURLString(); final String toURLForHTML(); void setBackgroundFill(final Fill fill); void setTransparency(final int opacity); final void setDataEncoding(final DataEncoding dataEncoding); void setMargins(final int leftMargin, final int rightMargin, final int topMargin, final int bottomMargin); void setURLEndpoint(final String urlEndpoint); }### Answer: @Test public void testSetURLEndpoint() { final LineChart chart = getBasicChart(); chart.setDataEncoding(DataEncoding.SIMPLE); chart.setURLEndpoint("http: Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); }
### Question: AbstractGChart implements GChart { public final Map<String, String> getParameters() { parameterManager.init(chartURLEndpoint); prepareData(); return parameterManager.getParameterMap(); } AbstractGChart(); void setSize(final int width, final int height); final Map<String, String> getParameters(); final String toURLString(); final String toURLForHTML(); void setBackgroundFill(final Fill fill); void setTransparency(final int opacity); final void setDataEncoding(final DataEncoding dataEncoding); void setMargins(final int leftMargin, final int rightMargin, final int topMargin, final int bottomMargin); void setURLEndpoint(final String urlEndpoint); }### Answer: @Test public void testGetParameters() { final LineChart chart = getBasicChart(); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); Map<String, String> parameters = chart.getParameters(); assertEquals("Junit error", "lc", parameters.get("cht")); assertEquals("Junit error", "200x125", parameters.get("chs")); assertEquals("Junit error", "e:AAgA..", parameters.get("chd")); }
### Question: AbstractGraphChart extends AbstractGChart implements GraphChart, TitledChart { public void setLegendMargins(final int legendWidth, final int legendHeight) { this.legendMargins = new LegendMargins(legendWidth, legendHeight); } AbstractGraphChart(); final void setTitle(final String title); final void setTitle(final String title, final Color color, final int fontSize); final void setLegendPosition(final LegendPosition legendPosition); void setLegendMargins(final int legendWidth, final int legendHeight); final void setAreaFill(final Fill fill); }### Answer: @Test public void testSetLegendMargins() { final Plot plot = Plots.newPlot(Data.newData(0, 50, 100), RED, "my Legend"); final LineChart chart = GCharts.newLineChart(plot); chart.setLegendMargins(100, 50); chart.setBackgroundFill(Fills.newSolidFill(BLACK)); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); }
### Question: AbstractGraphChart extends AbstractGChart implements GraphChart, TitledChart { public final void setAreaFill(final Fill fill) { areaFill = fill.klone(); } AbstractGraphChart(); final void setTitle(final String title); final void setTitle(final String title, final Color color, final int fontSize); final void setLegendPosition(final LegendPosition legendPosition); void setLegendMargins(final int legendWidth, final int legendHeight); final void setAreaFill(final Fill fill); }### Answer: @Test public void testSetAreaFill() { final LineChart chart = getBasicChart(); chart.setAreaFill(Fills.newSolidFill(RED)); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString()); String expectedString = "http: assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString())); }
### Question: ClassLoaderUtil { public static String classnameFromFilename(final String filename) { Objects.requireNonNull(filename); return StreamSupport.stream( Paths.get(filename.replaceFirst("\\.class$", "")).spliterator(), false) .map(Path::toString) .collect(Collectors.joining(".")); } private ClassLoaderUtil(); static URL toUrl(final Path file); static String classnameFromFilename(final String filename); static String resourceNameFromClassName(final String className); static CT privileged( final Supplier<CT> classLoaderSupplier); }### Answer: @Test public void classnameFromFilename() { assertEquals( "com.example.Foo", ClassLoaderUtil.classnameFromFilename("com/example/Foo.class")); }
### Question: ClassLoaderUtil { public static String resourceNameFromClassName(final String className) { Objects.requireNonNull(className); return className.replace('.', '/') + ".class"; } private ClassLoaderUtil(); static URL toUrl(final Path file); static String classnameFromFilename(final String filename); static String resourceNameFromClassName(final String className); static CT privileged( final Supplier<CT> classLoaderSupplier); }### Answer: @Test public void resourceNameFromClassName() { assertEquals( "com/example/Foo.class", ClassLoaderUtil.resourceNameFromClassName("com.example.Foo")); }
### Question: LobbyPresenter extends BasePresenter<LobbyView> { String getLocalReport() { String localReport = lobbyReportUseCase.getLocalReport(); Timber.d("localReport: %s", localReport); return localReport; } @Inject LobbyPresenter(LobbyReportUseCase lobbyReportUseCase, SchedulersFacade schedulersFacade); }### Answer: @Test public void getLocalReport_returnsLocalReport() throws Exception { when(lobbyReportUseCase.getLocalReport()).thenReturn(DUMMY_REPORT_DATA); String result = testSubject.getLocalReport(); assertThat(result, is(DUMMY_REPORT_DATA)); }
### Question: LobbyActivity extends AppCompatActivity implements LobbyView { @Override public void displayReportData(CharSequence report) { displayReportTextView.setVisibility(View.VISIBLE); displayReportTextView.setText(report); } @OnClick(R.id.generate_report) void onGenerateReportButtonClicked(); @Override void displayReportData(CharSequence report); @Override void hideReportData(); @Override void displayReportError(); @Override void displayLoadingIndicator(); @Override void hideLoadingIndicator(); }### Answer: @Test public void displayReportData_setsReportTextViewVisibilityToVisible_andSetsText() throws Exception { testSubject.displayReportData(DUMMY_REPORT_DATA); verify(displayReportTextView).setVisibility(View.VISIBLE); verify(displayReportTextView).setText(DUMMY_REPORT_DATA); }
### Question: LobbyActivity extends AppCompatActivity implements LobbyView { @Override public void displayReportError() { Toast.makeText(this, R.string.lobby_report_error_text, Toast.LENGTH_LONG).show(); } @OnClick(R.id.generate_report) void onGenerateReportButtonClicked(); @Override void displayReportData(CharSequence report); @Override void hideReportData(); @Override void displayReportError(); @Override void displayLoadingIndicator(); @Override void hideLoadingIndicator(); }### Answer: @Test public void displayReportError_displaysToastWithCorrectErrorMessage() throws Exception { String expected = RuntimeEnvironment.application.getString(R.string.lobby_report_error_text); testSubject.displayReportError(); assertThat(ShadowToast.getTextOfLatestToast(), is(expected)); }
### Question: LobbyActivity extends AppCompatActivity implements LobbyView { @Override public void hideReportData() { displayReportTextView.setVisibility(View.GONE); } @OnClick(R.id.generate_report) void onGenerateReportButtonClicked(); @Override void displayReportData(CharSequence report); @Override void hideReportData(); @Override void displayReportError(); @Override void displayLoadingIndicator(); @Override void hideLoadingIndicator(); }### Answer: @Test public void hideReportData_setsReportTextViewVisibilityToGone() throws Exception { testSubject.hideReportData(); verify(displayReportTextView).setVisibility(View.GONE); }
### Question: LobbyActivity extends AppCompatActivity implements LobbyView { @Override public void displayLoadingIndicator() { loadingIndicator.setVisibility(View.VISIBLE); } @OnClick(R.id.generate_report) void onGenerateReportButtonClicked(); @Override void displayReportData(CharSequence report); @Override void hideReportData(); @Override void displayReportError(); @Override void displayLoadingIndicator(); @Override void hideLoadingIndicator(); }### Answer: @Test public void displayLoadingIndicator_setsLoadingIndicatorVisibilityToVisible() throws Exception { testSubject.displayLoadingIndicator(); verify(loadingIndicator).setVisibility(View.VISIBLE); }
### Question: LobbyActivity extends AppCompatActivity implements LobbyView { @Override public void hideLoadingIndicator() { loadingIndicator.setVisibility(View.GONE); } @OnClick(R.id.generate_report) void onGenerateReportButtonClicked(); @Override void displayReportData(CharSequence report); @Override void hideReportData(); @Override void displayReportError(); @Override void displayLoadingIndicator(); @Override void hideLoadingIndicator(); }### Answer: @Test public void hideLoadingIndicator_setsLoadingIndicatorVisibilityToGone() throws Exception { testSubject.hideLoadingIndicator(); verify(loadingIndicator).setVisibility(View.GONE); }
### Question: LobbyReportUseCase { Single<String> generateReport() { return repository.getReportAsync(); } @Inject LobbyReportUseCase(LobbyRepository repository); }### Answer: @Test public void generateReport_getsReportAsyncFromRepository() throws Exception { testSubject.generateReport(); verify(lobbyRepository).getReportAsync(); }
### Question: LobbyReportUseCase { String getLocalReport() { return repository.getReport(); } @Inject LobbyReportUseCase(LobbyRepository repository); }### Answer: @Test public void getLocalReport_getsReportFromRepository() throws Exception { testSubject.getLocalReport(); verify(lobbyRepository).getReport(); }
### Question: LobbyPresenter extends BasePresenter<LobbyView> { void generateReport() { addDisposable(lobbyReportUseCase.generateReport() .doOnSubscribe(s -> publishRequestState(RequestState.LOADING)) .subscribeOn(schedulersFacade.io()) .observeOn(schedulersFacade.ui()) .delay(REPORT_DELAY_MILLIS, TimeUnit.MILLISECONDS, schedulersFacade.ui()) .doOnSuccess(s -> publishRequestState(RequestState.COMPLETE)) .doOnError(t -> publishRequestState(RequestState.ERROR)) .subscribe(this::onReportDataAvailable, this::onReportDataError)); } @Inject LobbyPresenter(LobbyReportUseCase lobbyReportUseCase, SchedulersFacade schedulersFacade); }### Answer: @Test public void generateReport_whenReportDataAvailable_displaysReportDataInView() throws Exception { when(lobbyReportUseCase.generateReport()).thenReturn(Single.just(DUMMY_REPORT_DATA)); testSubject.generateReport(); testScheduler.advanceTimeBy(REPORT_DELAY_MILLIS, TimeUnit.MILLISECONDS); testScheduler.triggerActions(); verify(view).hideReportData(); verify(view).displayLoadingIndicator(); verify(view).hideLoadingIndicator(); verify(view).displayReportData(DUMMY_REPORT_DATA); verifyNoMoreInteractions(view); } @Test public void generateReport_whenReportDataError_displaysReportErrorInView() throws Exception { Throwable throwable = mock(Throwable.class); when(lobbyReportUseCase.generateReport()).thenReturn(Single.error(throwable)); testSubject.generateReport(); testScheduler.advanceTimeBy(REPORT_DELAY_MILLIS, TimeUnit.MILLISECONDS); testScheduler.triggerActions(); verify(view).hideReportData(); verify(view).displayLoadingIndicator(); verify(view).hideLoadingIndicator(); verify(view).displayReportError(); verifyNoMoreInteractions(view); }
### Question: LobbyPresenter extends BasePresenter<LobbyView> { void onReportDataAvailable(String report) { Timber.d("report data: %s", report); view.displayReportData(report); } @Inject LobbyPresenter(LobbyReportUseCase lobbyReportUseCase, SchedulersFacade schedulersFacade); }### Answer: @Test public void onReportDataAvailable_displaysReportDataInView() throws Exception { testSubject.onReportDataAvailable(DUMMY_REPORT_DATA); verify(view).displayReportData(DUMMY_REPORT_DATA); }
### Question: LobbyPresenter extends BasePresenter<LobbyView> { void onReportDataError(Throwable throwable) { Timber.e(throwable, "report error"); view.displayReportError(); } @Inject LobbyPresenter(LobbyReportUseCase lobbyReportUseCase, SchedulersFacade schedulersFacade); }### Answer: @Test public void onReportDataError_displaysReportErrorInView() throws Exception { testSubject.onReportDataError(null); verify(view).displayReportError(); }
### Question: LobbyRepositoryImpl implements LobbyRepository { @Override public Single<String> getReportAsync() { return Single.just(FAKE_REPORT_DATA); } @Override Single<String> getReportAsync(); @Override String getReport(); }### Answer: @Test public void getReportAsync_onSuccess_returnsReportData() throws Exception { when(testSubject.getReportAsync()) .thenReturn(Single.just(LobbyRepositoryImpl.FAKE_REPORT_DATA)); TestObserver<String> testObserver = testSubject.getReportAsync().test(); testObserver.assertResult(LobbyRepositoryImpl.FAKE_REPORT_DATA); testObserver.assertComplete(); } @Test public void getReportAsync_onError_returnsError() throws Exception { when(testSubject.getReportAsync()) .thenReturn(Single.error(new RuntimeException())); TestObserver<String> testObserver = testSubject.getReportAsync().test(); testObserver.assertError(RuntimeException.class); }
### Question: LobbyRepositoryImpl implements LobbyRepository { @Override public String getReport() { return FAKE_REPORT_DATA; } @Override Single<String> getReportAsync(); @Override String getReport(); }### Answer: @Test public void getReport_returnsReportData() throws Exception { String result = testSubject.getReport(); assertThat(result, is(LobbyRepositoryImpl.FAKE_REPORT_DATA)); }