ItemStack testSpawner = new ItemStack(Material.MOB_SPAWNER, 1);
BlockStateMeta bsm = (BlockStateMeta) testSpawner.getItemMeta();
CreatureSpawner cs = (CreatureSpawner) bsm.getBlockState();
cs.setSpawnedType(EntityType.BAT);
bsm.setBlockState(cs);
testSpawner.setItemMeta(bsm);