### Question:
SpawningNexus extends Nexus { public Marble spawn() { if (getContext().isOccupied()) { throw new IllegalStateException("The nexus is already occupied by a marble"); } Marble marble = new Marble(getContext().poll()); accept(direction, marble); getContext().setOccupied(true); return marble; } SpawningNexus(NexusContext context, Direction direction); Marble spawn(); Direction getDirection(); static final Property<Double> JOKER_PROBABILITY; static final Property<List<String>> INITIAL_SEQUENCE; }### Answer:
@Test public void spawnFailsOnOccupation() { context.setOccupied(true); assertThatThrownBy(() -> nexus.spawn()).isInstanceOf(IllegalStateException.class); }
@Test public void spawnInitialSequence() { assertThat(nexus.spawn().getType()).isEqualTo(MarbleType.BLUE); }
@Test public void peekInitialSequence() { assertThat(context.peek()).isEqualTo(MarbleType.BLUE); assertThat(nexus.spawn().getType()).isEqualTo(MarbleType.BLUE); }
@Test public void spawnJoker() { when(random.nextDouble()).thenReturn(0.4); context.poll(); assertThat(nexus.spawn().getType()).isEqualTo(MarbleType.JOKER); }
@Test public void spawnPink() { when(random.nextInt(anyInt())).thenReturn(0); when(random.nextDouble()).thenReturn(0.6); context.poll(); assertThat(nexus.spawn().getType()).isEqualTo(MarbleType.PINK); }
@Test public void spawnGreen() { when(random.nextDouble()).thenReturn(0.6); when(random.nextInt(anyInt())).thenReturn(1); context.poll(); assertThat(nexus.spawn().getType()).isEqualTo(MarbleType.GREEN); }
@Test public void spawnBlue() { when(random.nextDouble()).thenReturn(0.6); when(random.nextInt(anyInt())).thenReturn(2); context.poll(); assertThat(nexus.spawn().getType()).isEqualTo(MarbleType.BLUE); }
@Test public void spawnYellow() { when(random.nextDouble()).thenReturn(0.6); when(random.nextInt(anyInt())).thenReturn(3); context.poll(); assertThat(nexus.spawn().getType()).isEqualTo(MarbleType.YELLOW); }
@Test public void add() { when(random.nextDouble()).thenReturn(0.0); context.add(MarbleType.JOKER); context.poll(); assertThat(nexus.spawn().getType()).isEqualTo(MarbleType.JOKER); }