@SuppressWarnings("unchecked")
	@Test
	public void testPopRemovesItemFromList() throws LuaScriptException {
		String jid1 = addNewTestJob();
		String jid2 = addJob(UUID.randomUUID().toString());

		List<String> keys = Arrays.asList(TEST_QUEUE);
		List<String> args = Arrays.asList(TEST_WORKER, "1",
				JQlessClient.getCurrentSeconds());

		// First pass
		List<String> json = (List<String>) _luaScript.callScript(
				this.scriptName(), keys, args);

		Map<String, Object> jobs = JsonHelper.parseMapFirstObject(json);

		assertTrue(json.size() == 1);
		if (jobs.get("jid").equals(jid1)) {
			assertEquals(jid1, jobs.get("jid"));
		} else {
			assertEquals(jid2, jobs.get("jid"));

			String jobJson = getJob(jid1);
			Map<String, Object> job1 = JsonHelper.parseMap(jobJson);
			jobJson = getJob(jid2);
			Map<String, Object> job2 = JsonHelper.parseMap(jobJson);

			assertEquals(((List<Map<String, Object>>) (job1.get("history")))
					.get(0).get("put"),
					((List<Map<String, Object>>) (job2.get("history"))).get(0)
							.get("put"));
		}

		// Second pass
		json = (List<String>) _luaScript.callScript(this.scriptName(), keys,
				args);

		jobs = JsonHelper.parseMapFirstObject(json);

		assertTrue(json.size() == 1);
		if (jobs.get("jid").equals(jid2)) {
			assertEquals(jid2, jobs.get("jid"));
		} else {
			assertEquals(jid1, jobs.get("jid"));

			String jobJson = getJob(jid1);
			Map<String, Object> job1 = JsonHelper.parseMap(jobJson);
			jobJson = getJob(jid2);
			Map<String, Object> job2 = JsonHelper.parseMap(jobJson);

			assertEquals(((List<Map<String, Object>>) (job1.get("history")))
					.get(0).get("put"),
					((List<Map<String, Object>>) (job2.get("history"))).get(0)
							.get("put"));
		}

		removeJob(jid1);
		removeJob(jid2);
	}