### Question:
MatchupGenerator extends BasicTool { static long defineMatchupPattern(String primarySensorName, String secondarySensorName, long referenceSensorPattern, PersistenceManager pm, Stack<EntityTransaction> rollbackStack) { long matchupPattern; final Storage storage = pm.getStorage(); rollbackStack.push(pm.transaction()); final String primaryOrbitName = SensorNames.getOrbitName(primarySensorName); final Sensor primarySensor = storage.getSensor(primaryOrbitName); if (secondarySensorName != null) { final String secondaryOrbitName = SensorNames.getOrbitName(secondarySensorName); final Sensor secondarySensor = storage.getSensor(secondaryOrbitName); matchupPattern = referenceSensorPattern | primarySensor.getPattern() | secondarySensor.getPattern(); } else { matchupPattern = referenceSensorPattern | primarySensor.getPattern(); } pm.commit(); return matchupPattern; } MatchupGenerator(); static void main(String[] args); @Override void initialize();  }### Answer:
@Test public void testDefineMatchupPattern_twoSensors() { final String primarySensorname = "atsr.3"; final String secondarySensorname = "atsr.2"; final Stack<EntityTransaction> transactionStack = new Stack<>(); final Sensor primarySensor = new SensorBuilder().name(primarySensorname).pattern(10).build(); final Sensor secondarySensor = new SensorBuilder().name(secondarySensorname).pattern(100).build(); final EntityTransaction transaction = mock(EntityTransaction.class); final Storage storage = mock(Storage.class); final PersistenceManager persistenceManager = mock(PersistenceManager.class); when(persistenceManager.transaction()).thenReturn(transaction); when(persistenceManager.getStorage()).thenReturn(storage); when(storage.getSensor("orb_atsr.3")).thenReturn(primarySensor); when(storage.getSensor("orb_atsr.2")).thenReturn(secondarySensor); final long pattern = MatchupGenerator.defineMatchupPattern(primarySensorname, secondarySensorname, 1000000L, persistenceManager, transactionStack); assertEquals(1000000L | 10L | 100L, pattern); verify(persistenceManager, times(1)).getStorage(); verify(persistenceManager, times(1)).transaction(); verify(persistenceManager, times(1)).commit(); verifyNoMoreInteractions(persistenceManager); verify(storage, times(1)).getSensor("orb_atsr.3"); verify(storage, times(1)).getSensor("orb_atsr.2"); verifyNoMoreInteractions(storage); assertEquals(1, transactionStack.size()); assertSame(transaction, transactionStack.pop()); }
@Test public void testDefineMatchupPattern_onlyPrimarySensor() { final String primarySensorname = "atsr.3"; final Stack<EntityTransaction> transactionStack = new Stack<>(); final Sensor primarySensor = new SensorBuilder().name(primarySensorname).pattern(10).build(); final EntityTransaction transaction = mock(EntityTransaction.class); final Storage storage = mock(Storage.class); final PersistenceManager persistenceManager = mock(PersistenceManager.class); when(persistenceManager.transaction()).thenReturn(transaction); when(persistenceManager.getStorage()).thenReturn(storage); when(storage.getSensor("orb_atsr.3")).thenReturn(primarySensor); final long pattern = MatchupGenerator.defineMatchupPattern(primarySensorname, null, 1000000L, persistenceManager, transactionStack); assertEquals(1000000L | 10L, pattern); verify(persistenceManager, times(1)).getStorage(); verify(persistenceManager, times(1)).transaction(); verify(persistenceManager, times(1)).commit(); verifyNoMoreInteractions(persistenceManager); verify(storage, times(1)).getSensor("orb_atsr.3"); verifyNoMoreInteractions(storage); assertEquals(1, transactionStack.size()); assertSame(transaction, transactionStack.pop()); }