@Test public void roomReadyAndPlayerDontMove() throws JSONException { UserProfile profile = new UserProfile("aaaa", "bbbb"); GameProfile gameProfile = profile.getGameProfile(); final int defaultTestX = 500; gameProfile.setX(defaultTestX); final int defaultTestY = 500; gameProfile.setY(defaultTestY); gameProfile.setScore(1); Room room = mock(Room.class); doReturn(profile).when(gameServer).getPlayerBySession(anyString()); doReturn(room).when(gameServer).getPlayerRoomBySession(anyString()); when(room.isFinished()).thenReturn(false); JSONObject object = new JSONObject(); object.put("direction", -1); moveActionStrategy.processGameAction(object, httpSession); assertEquals(gameProfile.getX(), defaultTestX, 0); object.put("direction", 100); moveActionStrategy.processGameAction(object, httpSession); moveActionStrategy.processGameAction(object, httpSession); assertNotEquals(gameProfile.getX(), 1.0d, 0d); assertNotEquals(gameProfile.getY(), 1.0d, 0d); }
@Test public void shouldShallowCopyFieldValuesIntoMock() throws Exception { // given from.defaultField = "foo"; from.instancePublicField = new SomeOtherObject(); from.privateField = 1; from.privateTransientField = 2; from.protectedField = 3; assertNotEquals(from.defaultField, to.defaultField); assertNotEquals(from.instancePublicField, to.instancePublicField); assertNotEquals(from.privateField, to.privateField); assertNotEquals(from.privateTransientField, to.privateTransientField); assertNotEquals(from.protectedField, to.protectedField); // when tool.copyToMock(from, to); // then assertEquals(from.defaultField, to.defaultField); assertEquals(from.instancePublicField, to.instancePublicField); assertEquals(from.privateField, to.privateField); assertEquals(from.privateTransientField, to.privateTransientField); assertEquals(from.protectedField, to.protectedField); }
@Test public void a_show_inventory_object_is_not_equal_to_a_non_object() { UseWithSpecificItem object = createAction(); Object notAUseWithSpecificItem = new Object(); assertNotEquals(object, notAUseWithSpecificItem); }
@Test public void shouldCopyValuesOfInheritedFields() throws Exception { // given ((InheritMe) from).privateInherited = "foo"; ((InheritMe) from).protectedInherited = "bar"; assertNotEquals(((InheritMe) from).privateInherited, ((InheritMe) to).privateInherited); assertNotEquals(((InheritMe) from).privateInherited, ((InheritMe) to).privateInherited); // when tool.copyToMock(from, to); // then assertEquals(((InheritMe) from).privateInherited, ((InheritMe) to).privateInherited); assertEquals(((InheritMe) from).privateInherited, ((InheritMe) to).privateInherited); }
@Test public void testUpdate_adjustsName() { givenAWorkerAndATaskRequiring(1000); givenTheWorkerIsWorkingOnTheTask(); whenOneHourOfGameTimeElapses(); assertNotEquals( "Name should have been updated", INITIAL_TASK_NAME, world.name.get(taskEntity.id)); }
@Test public void shouldShallowCopyTransientPrivateFields() throws Exception { // given from.privateTransientField = 1000; assertNotEquals(1000, to.privateTransientField); // when tool.copyToMock(from, to); // then assertEquals(1000, to.privateTransientField); }
@Test public void shouldShallowCopyBasicFinalField() throws Exception { // given assertEquals(100, from.finalField); assertNotEquals(100, to.finalField); // when tool.copyToMock(from, to); // then assertEquals(100, to.finalField); }
@Test public void execute_shouldCreateAndStartAThreadWithTheProvidedRunnableAndReturnAFuture() throws Exception { CountDownLatch latch = new CountDownLatch(1); Future<?> result = asyncExecutor.execute(latch::countDown); latch.await(5, TimeUnit.SECONDS); // give the new thread time to start to running verify(factory).newThread(any()); // The provided runnable will be wrapped, not passed directly assertEquals(0, latch.getCount()); // but the runnable will be executed assertNotNull(result); assertNotNull(createdThread); assertNotEquals(Thread.State.NEW, createdThread.getState()); }
@SuppressWarnings("unchecked") @Test(timeout = 30000) public void testConnectAndDispatchMessages_Balanced() throws Exception { assertNull(connector1.getNodeName()); assertNull(connector2.getNodeName()); final AtomicInteger counter1 = new AtomicInteger(0); final AtomicInteger counter2 = new AtomicInteger(0); connector1.subscribe(String.class.getName(), new CountingCommandHandler(counter1)); connector1.connect(20); assertTrue( "Expected connector 1 to connect within 10 seconds", connector1.awaitJoined(10, TimeUnit.SECONDS)); connector2.subscribe(String.class.getName(), new CountingCommandHandler(counter2)); connector2.connect(80); assertTrue("Connector 2 failed to connect", connector2.awaitJoined()); // wait for both connectors to have the same view waitForConnectorSync(); List<FutureCallback> callbacks = new ArrayList<>(); for (int t = 0; t < 100; t++) { FutureCallback<Object, Object> callback = new FutureCallback<>(); String message = "message" + t; if ((t & 1) == 0) { connector1.send(message, new GenericCommandMessage<>(message), callback); } else { connector2.send(message, new GenericCommandMessage<>(message), callback); } callbacks.add(callback); } for (FutureCallback callback : callbacks) { assertEquals("The Reply!", callback.get()); } assertEquals(100, counter1.get() + counter2.get()); System.out.println("Node 1 got " + counter1.get()); System.out.println("Node 2 got " + counter2.get()); verify(mockCommandBus1, atMost(40)) .dispatch(any(CommandMessage.class), isA(CommandCallback.class)); verify(mockCommandBus2, atLeast(60)) .dispatch(any(CommandMessage.class), isA(CommandCallback.class)); assertEquals(connector1.getMembers(), connector2.getMembers()); assertNotNull(connector1.getNodeName()); assertNotNull(connector2.getNodeName()); assertNotEquals(connector1.getNodeName(), connector2.getNodeName()); }