### Question:
InputSelection implements Serializable { public int fairSelectNextIndexOutOf2(int availableInputsMask, int lastReadInputIndex) { int selectionMask = (int) inputMask; int combineMask = availableInputsMask & selectionMask; if (combineMask == 3) { return lastReadInputIndex == 0 ? 1 : 0; } else if (combineMask >= 0 && combineMask < 3) { return combineMask - 1; } throw new UnsupportedOperationException("Only two inputs are supported."); } private  InputSelection(long inputMask, boolean isALLMaskOf2); long getInputMask(); boolean isInputSelected(int inputId); boolean areAllInputsSelected(); boolean isALLMaskOf2(); int fairSelectNextIndexOutOf2(int availableInputsMask, int lastReadInputIndex); @Override boolean equals(Object o); @Override String toString(); static final InputSelection ALL; static final InputSelection FIRST; static final InputSelection SECOND; }### Answer:
@Test public void testFairSelectNextIndexOutOf2() { assertEquals(1, InputSelection.ALL.fairSelectNextIndexOutOf2(3, 0)); assertEquals(0, new Builder().select(1).select(2).build().fairSelectNextIndexOutOf2(3, 1)); assertEquals(1, InputSelection.ALL.fairSelectNextIndexOutOf2(2, 0)); assertEquals(1, InputSelection.ALL.fairSelectNextIndexOutOf2(2, 1)); assertEquals(0, InputSelection.ALL.fairSelectNextIndexOutOf2(1, 0)); assertEquals(0, InputSelection.ALL.fairSelectNextIndexOutOf2(1, 1)); assertEquals(-1, InputSelection.ALL.fairSelectNextIndexOutOf2(0, 0)); assertEquals(-1, InputSelection.ALL.fairSelectNextIndexOutOf2(0, 1)); assertEquals(0, InputSelection.FIRST.fairSelectNextIndexOutOf2(1, 0)); assertEquals(0, InputSelection.FIRST.fairSelectNextIndexOutOf2(3, 0)); assertEquals(-1, InputSelection.FIRST.fairSelectNextIndexOutOf2(2, 0)); assertEquals(-1, InputSelection.FIRST.fairSelectNextIndexOutOf2(0, 0)); assertEquals(1, InputSelection.SECOND.fairSelectNextIndexOutOf2(2, 1)); assertEquals(1, InputSelection.SECOND.fairSelectNextIndexOutOf2(3, 1)); assertEquals(-1, InputSelection.SECOND.fairSelectNextIndexOutOf2(1, 1)); assertEquals(-1, InputSelection.SECOND.fairSelectNextIndexOutOf2(0, 1)); }
@Test(expected = UnsupportedOperationException.class) public void testUnsupportedFairSelectNextIndexOutOf2() { InputSelection.ALL.fairSelectNextIndexOutOf2(7, 0); }