method2testcases
stringlengths
118
6.63k
### Question: LocationCollectionClient implements SharedPreferences.OnSharedPreferenceChangeListener { @NonNull static LocationCollectionClient getInstance() { synchronized (lock) { if (locationCollectionClient != null) { return locationCollectionClient; } else { throw new IllegalStateException("LocationCollectionClient is not installed."); } } } @VisibleForTesting LocationCollectionClient(@NonNull LocationEngineController collectionController, @NonNull HandlerThread handlerThread, @NonNull SessionIdentifier sessionIdentifier, @NonNull SharedPreferences sharedPreferences, @NonNull MapboxTelemetry telemetry); static LocationCollectionClient install(@NonNull Context context, long defaultInterval); @Override void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key); static final int DEFAULT_SESSION_ROTATION_INTERVAL_HOURS; }### Answer: @Test(expected = IllegalStateException.class) public void callGetInstanceBeforeInstall() { LocationCollectionClient.getInstance(); }
### Question: LocationCollectionClient implements SharedPreferences.OnSharedPreferenceChangeListener { static boolean uninstall() { boolean uninstalled = false; synchronized (lock) { if (locationCollectionClient != null) { locationCollectionClient.locationEngineController.onDestroy(); locationCollectionClient.settingsChangeHandlerThread.quit(); locationCollectionClient.sharedPreferences.unregisterOnSharedPreferenceChangeListener(locationCollectionClient); locationCollectionClient = null; uninstalled = true; } } return uninstalled; } @VisibleForTesting LocationCollectionClient(@NonNull LocationEngineController collectionController, @NonNull HandlerThread handlerThread, @NonNull SessionIdentifier sessionIdentifier, @NonNull SharedPreferences sharedPreferences, @NonNull MapboxTelemetry telemetry); static LocationCollectionClient install(@NonNull Context context, long defaultInterval); @Override void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key); static final int DEFAULT_SESSION_ROTATION_INTERVAL_HOURS; }### Answer: @Test public void callUninstallBeforeInstall() { assertThat(LocationCollectionClient.uninstall()).isFalse(); }
### Question: LocationUpdatesBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { try { if (intent == null) { Log.w(TAG, "intent == null"); return; } final String action = intent.getAction(); if (!ACTION_LOCATION_UPDATED.equals(action)) { return; } LocationEngineResult result = LocationEngineResult.extractResult(intent); if (result == null) { Log.w(TAG, "LocationEngineResult == null"); return; } LocationCollectionClient collectionClient = LocationCollectionClient.getInstance(); MapboxTelemetry telemetry = collectionClient.getTelemetry(); String sessionId = collectionClient.getSessionId(); List<Location> locations = result.getLocations(); for (Location location : locations) { if (isThereAnyNaN(location) || isThereAnyInfinite(location)) { continue; } telemetry.push(LocationMapper.create(location, sessionId)); } } catch (Throwable throwable) { Log.e(TAG, throwable.toString()); } } @Override void onReceive(Context context, Intent intent); }### Answer: @Test public void testNullIntentOnReceive() { Context mockedContext = mock(Context.class, RETURNS_DEEP_STUBS); broadcastReceiver.onReceive(mockedContext, null); verify(mockedContext, never()).getApplicationContext(); } @Test public void testOnReceiveActionReturnNull() { Context mockedContext = mock(Context.class, RETURNS_DEEP_STUBS); Intent mockedIntent = mock(Intent.class); when(mockedIntent.getAction()).thenReturn(null); broadcastReceiver.onReceive(mockedContext, mockedIntent); verify(mockedIntent, never()).getStringExtra(anyString()); }
### Question: AlarmReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { try { if (SCHEDULER_FLUSHER_INTENT.equals(intent.getAction())) { callback.onPeriodRaised(); } } catch (Throwable throwable) { Log.e(TAG, throwable.toString()); } } AlarmReceiver(@NonNull SchedulerCallback callback); @Override void onReceive(Context context, Intent intent); }### Answer: @Test public void checksOnPeriodRaisedCall() throws Exception { Context mockedContext = mock(Context.class); Intent mockedIntent = mock(Intent.class); when(mockedIntent.getAction()).thenReturn("com.mapbox.scheduler_flusher"); SchedulerCallback mockedSchedulerCallback = mock(SchedulerCallback.class); AlarmReceiver theAlarmReceiver = new AlarmReceiver(mockedSchedulerCallback); theAlarmReceiver.onReceive(mockedContext, mockedIntent); verify(mockedSchedulerCallback, times(1)).onPeriodRaised(); }
### Question: AlarmReceiver extends BroadcastReceiver { Intent supplyIntent() { return new Intent(SCHEDULER_FLUSHER_INTENT); } AlarmReceiver(@NonNull SchedulerCallback callback); @Override void onReceive(Context context, Intent intent); }### Answer: @Test public void checksSupplyIntent() throws Exception { SchedulerCallback mockedSchedulerCallback = mock(SchedulerCallback.class); AlarmReceiver theAlarmReceiver = new AlarmReceiver(mockedSchedulerCallback); Intent actualAlarmIntent = theAlarmReceiver.supplyIntent(); Intent expectedAlarmIntent = new Intent("com.mapbox.scheduler_flusher"); assertEquals(expectedAlarmIntent.getAction(), actualAlarmIntent.getAction()); }
### Question: MapboxTelemetry implements FullQueueCallback, ServiceTaskCallback { public boolean push(Event event) { if (sendEventIfWhitelisted(event)) { return true; } return pushToQueue(event); } MapboxTelemetry(Context context, String accessToken, String userAgent); MapboxTelemetry(Context context, String accessToken, String userAgent, EventsQueue queue, TelemetryClient telemetryClient, Callback httpCallback, SchedulerFlusher schedulerFlusher, Clock clock, TelemetryEnabler telemetryEnabler, ExecutorService executorService); @Override // Callback is dispatched on background thread void onFullQueue(List<Event> fullQueue); @Override void onTaskRemoved(); boolean push(Event event); boolean enable(); boolean disable(); boolean updateSessionIdRotationInterval(SessionInterval interval); void updateDebugLoggingEnabled(boolean isDebugLoggingEnabled); void updateUserAgent(String userAgent); boolean updateAccessToken(String accessToken); boolean addTelemetryListener(TelemetryListener listener); boolean removeTelemetryListener(TelemetryListener listener); boolean addAttachmentListener(AttachmentListener listener); boolean removeAttachmentListener(AttachmentListener listener); @SuppressWarnings("WeakerAccess") @Deprecated synchronized boolean setBaseUrl(String eventsHost); boolean isCnRegion(); synchronized void setCnRegion(boolean setCnRegion); }### Answer: @Test public void checksPushIfTelemetryEnabled() throws Exception { Context mockedContext = mock(Context.class, RETURNS_DEEP_STUBS); EventsQueue mockedEventsQueue = mock(EventsQueue.class); MapboxTelemetry theMapboxTelemetry = obtainMapboxTelemetryWith(mockedContext, mockedEventsQueue, TelemetryEnabler.State.ENABLED); Event mockedEvent = mock(Event.class); when(mockedEvent.obtainType()).thenReturn(Event.Type.LOCATION); theMapboxTelemetry.push(mockedEvent); verify(mockedEventsQueue, times(1)).push(eq(mockedEvent)); } @Test public void checksPushIfTelemetryDisabled() throws Exception { Context mockedContext = mock(Context.class, RETURNS_DEEP_STUBS); EventsQueue mockedEventsQueue = mock(EventsQueue.class); MapboxTelemetry theMapboxTelemetry = obtainMapboxTelemetryWith(mockedContext, mockedEventsQueue, TelemetryEnabler.State.DISABLED); Event mockedEvent = mock(Event.class); when(mockedEvent.obtainType()).thenReturn(Event.Type.LOCATION); theMapboxTelemetry.push(mockedEvent); verify(mockedEventsQueue, never()).push(eq(mockedEvent)); }
### Question: MapboxTelemetry implements FullQueueCallback, ServiceTaskCallback { public boolean enable() { if (TelemetryEnabler.isEventsEnabled(applicationContext)) { startTelemetry(); return true; } return false; } MapboxTelemetry(Context context, String accessToken, String userAgent); MapboxTelemetry(Context context, String accessToken, String userAgent, EventsQueue queue, TelemetryClient telemetryClient, Callback httpCallback, SchedulerFlusher schedulerFlusher, Clock clock, TelemetryEnabler telemetryEnabler, ExecutorService executorService); @Override // Callback is dispatched on background thread void onFullQueue(List<Event> fullQueue); @Override void onTaskRemoved(); boolean push(Event event); boolean enable(); boolean disable(); boolean updateSessionIdRotationInterval(SessionInterval interval); void updateDebugLoggingEnabled(boolean isDebugLoggingEnabled); void updateUserAgent(String userAgent); boolean updateAccessToken(String accessToken); boolean addTelemetryListener(TelemetryListener listener); boolean removeTelemetryListener(TelemetryListener listener); boolean addAttachmentListener(AttachmentListener listener); boolean removeAttachmentListener(AttachmentListener listener); @SuppressWarnings("WeakerAccess") @Deprecated synchronized boolean setBaseUrl(String eventsHost); boolean isCnRegion(); synchronized void setCnRegion(boolean setCnRegion); }### Answer: @Test public void checksFlusherRegisteringWhenEnabled() throws Exception { Context mockedContext = mock(Context.class, RETURNS_DEEP_STUBS); SchedulerFlusher mockedSchedulerFlusher = mock(SchedulerFlusher.class); MapboxTelemetry theMapboxTelemetry = obtainMapboxTelemetryWith(mockedContext, mockedSchedulerFlusher); theMapboxTelemetry.enable(); verify(mockedSchedulerFlusher, times(1)).register(); } @Test public void checksFlusherSchedulingWhenEnabled() throws Exception { Context mockedContext = mock(Context.class, RETURNS_DEEP_STUBS); SchedulerFlusher mockedSchedulerFlusher = mock(SchedulerFlusher.class); MapboxTelemetry theMapboxTelemetry = obtainMapboxTelemetryWith(mockedContext, mockedSchedulerFlusher); theMapboxTelemetry.enable(); verify(mockedSchedulerFlusher, times(1)).schedule(anyLong()); }
### Question: MapboxTelemetry implements FullQueueCallback, ServiceTaskCallback { public boolean disable() { if (TelemetryEnabler.isEventsEnabled(applicationContext)) { stopTelemetry(); return true; } return false; } MapboxTelemetry(Context context, String accessToken, String userAgent); MapboxTelemetry(Context context, String accessToken, String userAgent, EventsQueue queue, TelemetryClient telemetryClient, Callback httpCallback, SchedulerFlusher schedulerFlusher, Clock clock, TelemetryEnabler telemetryEnabler, ExecutorService executorService); @Override // Callback is dispatched on background thread void onFullQueue(List<Event> fullQueue); @Override void onTaskRemoved(); boolean push(Event event); boolean enable(); boolean disable(); boolean updateSessionIdRotationInterval(SessionInterval interval); void updateDebugLoggingEnabled(boolean isDebugLoggingEnabled); void updateUserAgent(String userAgent); boolean updateAccessToken(String accessToken); boolean addTelemetryListener(TelemetryListener listener); boolean removeTelemetryListener(TelemetryListener listener); boolean addAttachmentListener(AttachmentListener listener); boolean removeAttachmentListener(AttachmentListener listener); @SuppressWarnings("WeakerAccess") @Deprecated synchronized boolean setBaseUrl(String eventsHost); boolean isCnRegion(); synchronized void setCnRegion(boolean setCnRegion); }### Answer: @Test public void checksFlushEnqueuedEventsWhenDisabled() throws Exception { Context mockedContext = mock(Context.class, RETURNS_DEEP_STUBS); EventsQueue mockedEventsQueue = mock(EventsQueue.class); MapboxTelemetry theMapboxTelemetry = obtainMapboxTelemetryWith(mockedContext, mockedEventsQueue); theMapboxTelemetry.disable(); verify(mockedEventsQueue, times(1)).flush(); } @Test public void checksFlusherUnregisteringWhenDisabled() throws Exception { Context mockedContext = mock(Context.class, RETURNS_DEEP_STUBS); SchedulerFlusher mockedSchedulerFlusher = mock(SchedulerFlusher.class); MapboxTelemetry theMapboxTelemetry = obtainMapboxTelemetryWith(mockedContext, mockedSchedulerFlusher); theMapboxTelemetry.disable(); verify(mockedSchedulerFlusher, times(1)).unregister(); }
### Question: MapboxTelemetry implements FullQueueCallback, ServiceTaskCallback { public boolean updateAccessToken(String accessToken) { if (isAccessTokenValid(accessToken) && updateTelemetryClient(accessToken)) { sAccessToken.set(accessToken); return true; } return false; } MapboxTelemetry(Context context, String accessToken, String userAgent); MapboxTelemetry(Context context, String accessToken, String userAgent, EventsQueue queue, TelemetryClient telemetryClient, Callback httpCallback, SchedulerFlusher schedulerFlusher, Clock clock, TelemetryEnabler telemetryEnabler, ExecutorService executorService); @Override // Callback is dispatched on background thread void onFullQueue(List<Event> fullQueue); @Override void onTaskRemoved(); boolean push(Event event); boolean enable(); boolean disable(); boolean updateSessionIdRotationInterval(SessionInterval interval); void updateDebugLoggingEnabled(boolean isDebugLoggingEnabled); void updateUserAgent(String userAgent); boolean updateAccessToken(String accessToken); boolean addTelemetryListener(TelemetryListener listener); boolean removeTelemetryListener(TelemetryListener listener); boolean addAttachmentListener(AttachmentListener listener); boolean removeAttachmentListener(AttachmentListener listener); @SuppressWarnings("WeakerAccess") @Deprecated synchronized boolean setBaseUrl(String eventsHost); boolean isCnRegion(); synchronized void setCnRegion(boolean setCnRegion); }### Answer: @Test public void checksAccessTokenUpdated() throws Exception { TelemetryClient mockedTelemetryClient = mock(TelemetryClient.class); MapboxTelemetry theMapboxTelemetry = obtainMapboxTelemetryWith(mockedTelemetryClient); String anotherValidAccessToken = "anotherValidAccessToken"; boolean updatedAccessToken = theMapboxTelemetry.updateAccessToken(anotherValidAccessToken); verify(mockedTelemetryClient, times(1)).updateAccessToken(eq(anotherValidAccessToken)); assertTrue(updatedAccessToken); } @Test public void checksAccessTokenNotUpdatedWhenAccessTokenNull() throws Exception { TelemetryClient mockedTelemetryClient = mock(TelemetryClient.class); MapboxTelemetry theMapboxTelemetry = obtainMapboxTelemetryWith(mockedTelemetryClient); String nullAccessToken = null; boolean updatedAccessToken = theMapboxTelemetry.updateAccessToken(nullAccessToken); assertFalse(updatedAccessToken); } @Test public void checksAccessTokenNotUpdatedWhenAccessTokenEmpty() throws Exception { TelemetryClient mockedTelemetryClient = mock(TelemetryClient.class); MapboxTelemetry theMapboxTelemetry = obtainMapboxTelemetryWith(mockedTelemetryClient); String emptyAccessToken = ""; boolean updatedAccessToken = theMapboxTelemetry.updateAccessToken(emptyAccessToken); assertFalse(updatedAccessToken); } @Test public void checksAccessTokenNotUpdatedWhenTelemetryClientNull() throws Exception { TelemetryClient nullTelemetryClient = null; MapboxTelemetry theMapboxTelemetry = obtainMapboxTelemetryWith(nullTelemetryClient); String anotherValidAccessToken = "anotherValidAccessToken"; boolean updatedAccessToken = theMapboxTelemetry.updateAccessToken(anotherValidAccessToken); assertFalse(updatedAccessToken); }
### Question: MapboxTelemetry implements FullQueueCallback, ServiceTaskCallback { public boolean addTelemetryListener(TelemetryListener listener) { return telemetryListeners.add(listener); } MapboxTelemetry(Context context, String accessToken, String userAgent); MapboxTelemetry(Context context, String accessToken, String userAgent, EventsQueue queue, TelemetryClient telemetryClient, Callback httpCallback, SchedulerFlusher schedulerFlusher, Clock clock, TelemetryEnabler telemetryEnabler, ExecutorService executorService); @Override // Callback is dispatched on background thread void onFullQueue(List<Event> fullQueue); @Override void onTaskRemoved(); boolean push(Event event); boolean enable(); boolean disable(); boolean updateSessionIdRotationInterval(SessionInterval interval); void updateDebugLoggingEnabled(boolean isDebugLoggingEnabled); void updateUserAgent(String userAgent); boolean updateAccessToken(String accessToken); boolean addTelemetryListener(TelemetryListener listener); boolean removeTelemetryListener(TelemetryListener listener); boolean addAttachmentListener(AttachmentListener listener); boolean removeAttachmentListener(AttachmentListener listener); @SuppressWarnings("WeakerAccess") @Deprecated synchronized boolean setBaseUrl(String eventsHost); boolean isCnRegion(); synchronized void setCnRegion(boolean setCnRegion); }### Answer: @Test public void checkAddTelemetryListener() throws Exception { MapboxTelemetry theMapboxTelemetry = obtainMapboxTelemetry(); TelemetryListener telemetryListener = mock(TelemetryListener.class); assertTrue(theMapboxTelemetry.addTelemetryListener(telemetryListener)); }
### Question: MapboxTelemetry implements FullQueueCallback, ServiceTaskCallback { public boolean addAttachmentListener(AttachmentListener listener) { return attachmentListeners.add(listener); } MapboxTelemetry(Context context, String accessToken, String userAgent); MapboxTelemetry(Context context, String accessToken, String userAgent, EventsQueue queue, TelemetryClient telemetryClient, Callback httpCallback, SchedulerFlusher schedulerFlusher, Clock clock, TelemetryEnabler telemetryEnabler, ExecutorService executorService); @Override // Callback is dispatched on background thread void onFullQueue(List<Event> fullQueue); @Override void onTaskRemoved(); boolean push(Event event); boolean enable(); boolean disable(); boolean updateSessionIdRotationInterval(SessionInterval interval); void updateDebugLoggingEnabled(boolean isDebugLoggingEnabled); void updateUserAgent(String userAgent); boolean updateAccessToken(String accessToken); boolean addTelemetryListener(TelemetryListener listener); boolean removeTelemetryListener(TelemetryListener listener); boolean addAttachmentListener(AttachmentListener listener); boolean removeAttachmentListener(AttachmentListener listener); @SuppressWarnings("WeakerAccess") @Deprecated synchronized boolean setBaseUrl(String eventsHost); boolean isCnRegion(); synchronized void setCnRegion(boolean setCnRegion); }### Answer: @Test public void checkAddAttachmentListener() throws Exception { MapboxTelemetry theMapboxTelemetry = obtainMapboxTelemetry(); AttachmentListener attachmentListener = mock(AttachmentListener.class); assertTrue(theMapboxTelemetry.addAttachmentListener(attachmentListener)); }
### Question: LocationEngineProvider { @NonNull @Deprecated public static LocationEngine getBestLocationEngine(@NonNull Context context, boolean background) { return getBestLocationEngine(context); } private LocationEngineProvider(); @NonNull @Deprecated static LocationEngine getBestLocationEngine(@NonNull Context context, boolean background); @NonNull static LocationEngine getBestLocationEngine(@NonNull Context context); }### Answer: @Test(expected = NullPointerException.class) public void passNullContext() { LocationEngineProvider.getBestLocationEngine(null, false); }
### Question: AtlasJavaModelFactory { public static JavaClass createJavaClass() { JavaClass javaClass = new JavaClass(); javaClass.setJavaEnumFields(new JavaEnumFields()); javaClass.setJavaFields(new JavaFields()); return javaClass; } static JavaClass createJavaClass(); static JavaField createJavaField(); static FieldGroup cloneFieldGroup(FieldGroup group); static Field cloneJavaField(Field field, boolean withActions); static void copyField(Field from, Field to, boolean withActions); static final String URI_FORMAT; }### Answer: @Test public void testCreateJavaClass() { JavaClass javaClass = AtlasJavaModelFactory.createJavaClass(); assertNotNull(javaClass); assertNotNull(javaClass.getJavaFields()); assertNotNull(javaClass.getJavaFields().getJavaField()); assertEquals(new Integer(0), new Integer(javaClass.getJavaFields().getJavaField().size())); assertNotNull(javaClass.getJavaEnumFields()); assertNotNull(javaClass.getJavaEnumFields().getJavaEnumField()); assertEquals(new Integer(0), new Integer(javaClass.getJavaEnumFields().getJavaEnumField().size())); }
### Question: CharacterConverter implements AtlasConverter<Character> { @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.BYTE, concerns = { AtlasConversionConcern.RANGE }) public Byte toByte(Character value) throws AtlasConversionException { if (value == null) { return null; } if (value.charValue() > Byte.MAX_VALUE) { throw new AtlasConversionException( String.format("Character value %s is greater than BYTE.MAX_VALUE", value)); } return (byte) value.charValue(); } @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.BOOLEAN, concerns = { AtlasConversionConcern.CONVENTION }) Boolean toBoolean(Character value, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.BYTE, concerns = { AtlasConversionConcern.RANGE }) Byte toByte(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.CHAR) Character toCharacter(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.DOUBLE) Double toDouble(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.FLOAT) Float toFloat(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.INTEGER) Integer toInteger(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.LONG) Long toLong(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.NUMBER) Number toNumber(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.SHORT, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Short toShort(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.STRING) String toString(Character value, String sourceFormat, String targetFormat); }### Answer: @Test public void convertToByteNull() throws Exception { assertNull(converter.toByte(null)); } @Test public void convertToByte() throws Exception { byte value = 99; assertEquals(value, converter.toByte('c').byteValue()); } @Test(expected = AtlasConversionException.class) public void convertToByteOutOfRange() throws Exception { byte value = 99; assertEquals(value, converter.toByte('\uD840').byteValue()); }
### Question: CharacterConverter implements AtlasConverter<Character> { @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.CHAR) public Character toCharacter(Character value) { if (value == null) { return null; } return new Character(value); } @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.BOOLEAN, concerns = { AtlasConversionConcern.CONVENTION }) Boolean toBoolean(Character value, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.BYTE, concerns = { AtlasConversionConcern.RANGE }) Byte toByte(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.CHAR) Character toCharacter(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.DOUBLE) Double toDouble(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.FLOAT) Float toFloat(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.INTEGER) Integer toInteger(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.LONG) Long toLong(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.NUMBER) Number toNumber(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.SHORT, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Short toShort(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.STRING) String toString(Character value, String sourceFormat, String targetFormat); }### Answer: @Test public void convertToCharacter() { Character c = (char) 0; Character c2 = converter.toCharacter(c); assertNotNull(c2); assertNotSame(c, c2); assertEquals(c, c2); } @Test public void convertToCharacterNull() { Character c = null; Character c2 = converter.toCharacter(c); assertNull(c2); }
### Question: CharacterConverter implements AtlasConverter<Character> { @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.DOUBLE) public Double toDouble(Character value) { if (value == null) { return null; } return Double.valueOf(value); } @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.BOOLEAN, concerns = { AtlasConversionConcern.CONVENTION }) Boolean toBoolean(Character value, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.BYTE, concerns = { AtlasConversionConcern.RANGE }) Byte toByte(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.CHAR) Character toCharacter(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.DOUBLE) Double toDouble(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.FLOAT) Float toFloat(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.INTEGER) Integer toInteger(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.LONG) Long toLong(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.NUMBER) Number toNumber(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.SHORT, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Short toShort(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.STRING) String toString(Character value, String sourceFormat, String targetFormat); }### Answer: @Test public void convertToDouble() { Character c = Character.forDigit(0, 10); Double d = converter.toDouble(c); assertNotNull(d); assertEquals(48.0, d, 0.0); c = '\uFFFF'; d = converter.toDouble(c); assertNotNull(d); assertEquals(65535.0, d, 0.0); } @Test public void convertToDoubleNull() { Character c = null; Double d = converter.toDouble(c); assertNull(d); }
### Question: CharacterConverter implements AtlasConverter<Character> { @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.FLOAT) public Float toFloat(Character value) { if (value == null) { return null; } return Float.valueOf(value); } @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.BOOLEAN, concerns = { AtlasConversionConcern.CONVENTION }) Boolean toBoolean(Character value, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.BYTE, concerns = { AtlasConversionConcern.RANGE }) Byte toByte(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.CHAR) Character toCharacter(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.DOUBLE) Double toDouble(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.FLOAT) Float toFloat(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.INTEGER) Integer toInteger(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.LONG) Long toLong(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.NUMBER) Number toNumber(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.SHORT, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Short toShort(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.STRING) String toString(Character value, String sourceFormat, String targetFormat); }### Answer: @Test public void convertToFloat() { Character c = Character.forDigit(0, 10); Float f = converter.toFloat(c); assertNotNull(f); assertEquals(48.00, f, 0.00); c = '\uFFFF'; f = converter.toFloat(c); assertNotNull(f); assertEquals(65535.0, f, 0.00); } @Test public void convertToFloatNull() { Character c = null; Float f = converter.toFloat(c); assertNull(f); }
### Question: CharacterConverter implements AtlasConverter<Character> { @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.INTEGER) public Integer toInteger(Character value) { if (value == null) { return null; } return Integer.valueOf(value); } @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.BOOLEAN, concerns = { AtlasConversionConcern.CONVENTION }) Boolean toBoolean(Character value, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.BYTE, concerns = { AtlasConversionConcern.RANGE }) Byte toByte(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.CHAR) Character toCharacter(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.DOUBLE) Double toDouble(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.FLOAT) Float toFloat(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.INTEGER) Integer toInteger(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.LONG) Long toLong(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.NUMBER) Number toNumber(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.SHORT, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Short toShort(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.STRING) String toString(Character value, String sourceFormat, String targetFormat); }### Answer: @Test public void convertToInteger() { Character c = Character.forDigit(0, 10); Integer i = converter.toInteger(c); assertNotNull(i); assertEquals(48, i, 0.00); c = '\uFFFF'; i = converter.toInteger(c); assertNotNull(i); assertEquals(65535, i, 0.00); } @Test public void convertToIntegerNull() { Character c = null; Integer i = converter.toInteger(c); assertNull(i); }
### Question: CharacterConverter implements AtlasConverter<Character> { @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.LONG) public Long toLong(Character value) { if (value == null) { return null; } return Long.valueOf(value); } @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.BOOLEAN, concerns = { AtlasConversionConcern.CONVENTION }) Boolean toBoolean(Character value, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.BYTE, concerns = { AtlasConversionConcern.RANGE }) Byte toByte(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.CHAR) Character toCharacter(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.DOUBLE) Double toDouble(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.FLOAT) Float toFloat(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.INTEGER) Integer toInteger(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.LONG) Long toLong(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.NUMBER) Number toNumber(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.SHORT, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Short toShort(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.STRING) String toString(Character value, String sourceFormat, String targetFormat); }### Answer: @Test public void convertToLong() { Character c = Character.forDigit(0, 10); Long l = converter.toLong(c); assertNotNull(l); assertEquals(48, l, 0.00); c = '\uFFFF'; l = converter.toLong(c); assertNotNull(l); assertEquals(65535, l, 0.00); } @Test public void convertToLongNull() { Long l = converter.toLong(null); assertNull(l); }
### Question: CharacterConverter implements AtlasConverter<Character> { @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.SHORT, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) public Short toShort(Character value) throws AtlasConversionException { if (value == null) { return null; } if (value > Short.MAX_VALUE) { throw new AtlasConversionException(); } return (short) value.charValue(); } @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.BOOLEAN, concerns = { AtlasConversionConcern.CONVENTION }) Boolean toBoolean(Character value, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.BYTE, concerns = { AtlasConversionConcern.RANGE }) Byte toByte(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.CHAR) Character toCharacter(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.DOUBLE) Double toDouble(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.FLOAT) Float toFloat(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.INTEGER) Integer toInteger(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.LONG) Long toLong(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.NUMBER) Number toNumber(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.SHORT, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Short toShort(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.STRING) String toString(Character value, String sourceFormat, String targetFormat); }### Answer: @Test public void convertToShort() throws Exception { Character c = Character.forDigit(0, 10); Short s = converter.toShort(c); assertNotNull(s); assertEquals(48.0, s, 0.00); } @Test public void convertToShortNull() throws Exception { Character c = null; Short s = converter.toShort(c); assertNull(s); } @Test(expected = AtlasConversionException.class) public void convertToShortException() throws Exception { Character c = Character.MAX_VALUE; converter.toShort(c); }
### Question: CharacterConverter implements AtlasConverter<Character> { @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.STRING) public String toString(Character value, String sourceFormat, String targetFormat) { if (value == null) { return null; } return String.valueOf(value); } @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.BOOLEAN, concerns = { AtlasConversionConcern.CONVENTION }) Boolean toBoolean(Character value, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.BYTE, concerns = { AtlasConversionConcern.RANGE }) Byte toByte(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.CHAR) Character toCharacter(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.DOUBLE) Double toDouble(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.FLOAT) Float toFloat(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.INTEGER) Integer toInteger(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.LONG) Long toLong(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.NUMBER) Number toNumber(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.SHORT, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Short toShort(Character value); @AtlasConversionInfo(sourceType = FieldType.CHAR, targetType = FieldType.STRING) String toString(Character value, String sourceFormat, String targetFormat); }### Answer: @Test public void convertToString() { Character c = Character.forDigit(0, 10); String s = converter.toString(c, null, null); assertNotNull(s); assertEquals("0", s); } @Test public void convertToStringNull() { Character c = null; String s = converter.toString(c, null, null); assertNull(s); }
### Question: ByteConverter implements AtlasConverter<Byte> { @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.BOOLEAN, concerns = {AtlasConversionConcern.CONVENTION}) public Boolean toBoolean(Byte value) { if (value == null) { return null; } return value.byteValue() != 0; } @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.BOOLEAN, concerns = {AtlasConversionConcern.CONVENTION}) Boolean toBoolean(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.BYTE) Byte toByte(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.CHAR) Character toCharacter(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE_TIME) Date toDate(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DOUBLE) Double toDouble(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.FLOAT) Float toFloat(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.INTEGER) Integer toInteger(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE) LocalDate toLocalDate(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.TIME) LocalTime toLocalTime(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.LONG) Long toLong(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.NUMBER) Number toNumber(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.SHORT) Short toShort(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.STRING, concerns = {AtlasConversionConcern.CONVENTION}) String toString(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Byte value); }### Answer: @Test() public void convertToBoolean() { assertTrue(byteConverter.toBoolean(new Byte((byte)1))); assertFalse(byteConverter.toBoolean(new Byte((byte)0))); assertTrue(byteConverter.toBoolean(Byte.MAX_VALUE)); } @Test public void convertToBooleanNull() { assertNull(byteConverter.toBoolean(null)); }
### Question: ByteConverter implements AtlasConverter<Byte> { @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.BYTE) public Byte toByte(Byte value) { return value != null ? new Byte(value) : null; } @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.BOOLEAN, concerns = {AtlasConversionConcern.CONVENTION}) Boolean toBoolean(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.BYTE) Byte toByte(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.CHAR) Character toCharacter(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE_TIME) Date toDate(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DOUBLE) Double toDouble(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.FLOAT) Float toFloat(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.INTEGER) Integer toInteger(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE) LocalDate toLocalDate(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.TIME) LocalTime toLocalTime(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.LONG) Long toLong(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.NUMBER) Number toNumber(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.SHORT) Short toShort(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.STRING, concerns = {AtlasConversionConcern.CONVENTION}) String toString(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Byte value); }### Answer: @Test public void convertToByte() { byteConverter.toByte(Byte.MAX_VALUE); } @Test public void convertToByteNull() { assertNull(byteConverter.toByte(null)); }
### Question: MavenClasspathHelper { public String generateClasspathFromPom(String pom) throws Exception { if (pom == null || pom.isEmpty()) { return null; } if (LOG.isDebugEnabled()) { LOG.debug("Generating classpath from pom:\n" + pom); } Path workingDirectory = createWorkingDirectory(); Path pomFile = Paths.get(workingDirectory.toString(), "pom.xml"); Files.write(pomFile, pom.getBytes()); List<String> cmd = new LinkedList<String>(); cmd.add("mvn"); cmd.add("org.apache.maven.plugins:maven-dependency-plugin:3.0.0:build-classpath"); cmd.add("-DincludeScope=runtime"); String result = executeMavenProcess(workingDirectory.toString(), cmd); if (result != null) { result = parseClasspathFromMavenOutput(result); } else { LOG.error("MavenProcess returned unexpected result: " + result); throw new InspectionException("Unable to generate classpath from pom file"); } try { deleteWorkingDirectory(workingDirectory); } catch (IOException ioe) { LOG.warn("Cleanup of working directory failed to complete: " + ioe.getMessage(), ioe); } return result; } String generateClasspathFromPom(String pom); Integer cleanupTempFolders(); long getProcessCheckInterval(); void setProcessCheckInterval(long processCheckInterval); long getProcessMaxExecutionTime(); void setProcessMaxExecutionTime(long processMaxExecutionTime); String getBaseFolder(); void setBaseFolder(String baseFolder); static final String WORKING_FOLDER_PREFIX; }### Answer: @Test public void testMavenClasspath() throws Exception { Path testPom = Paths.get("src/test/resources/pom-classpath-test.xml"); String pomData = new String(Files.readAllBytes(testPom)); String classpath = mavenClasspathHelper.generateClasspathFromPom(pomData); assertNotNull(classpath); assertTrue(classpath.contains("jackson-annotations")); assertTrue(classpath.contains("jackson-databind")); assertTrue(classpath.contains("jackson-core")); }
### Question: ByteConverter implements AtlasConverter<Byte> { @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.CHAR) public Character toCharacter(Byte value) { return value != null ? (char) value.byteValue() : null; } @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.BOOLEAN, concerns = {AtlasConversionConcern.CONVENTION}) Boolean toBoolean(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.BYTE) Byte toByte(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.CHAR) Character toCharacter(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE_TIME) Date toDate(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DOUBLE) Double toDouble(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.FLOAT) Float toFloat(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.INTEGER) Integer toInteger(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE) LocalDate toLocalDate(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.TIME) LocalTime toLocalTime(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.LONG) Long toLong(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.NUMBER) Number toNumber(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.SHORT) Short toShort(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.STRING, concerns = {AtlasConversionConcern.CONVENTION}) String toString(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Byte value); }### Answer: @Test public void convertToCharacter() { byte value = 0; assertEquals('\u0000', byteConverter.toCharacter(new Byte(value)).charValue()); value = 99; assertEquals('c', byteConverter.toCharacter(new Byte(value)).charValue()); } @Test public void convertToCharacterNull() { assertNull(byteConverter.toCharacter(null)); }
### Question: ByteConverter implements AtlasConverter<Byte> { @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DOUBLE) public Double toDouble(Byte value) { return value != null ? (double) value : null; } @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.BOOLEAN, concerns = {AtlasConversionConcern.CONVENTION}) Boolean toBoolean(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.BYTE) Byte toByte(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.CHAR) Character toCharacter(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE_TIME) Date toDate(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DOUBLE) Double toDouble(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.FLOAT) Float toFloat(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.INTEGER) Integer toInteger(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE) LocalDate toLocalDate(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.TIME) LocalTime toLocalTime(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.LONG) Long toLong(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.NUMBER) Number toNumber(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.SHORT) Short toShort(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.STRING, concerns = {AtlasConversionConcern.CONVENTION}) String toString(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Byte value); }### Answer: @Test public void convertToDouble() { assertEquals(100, byteConverter.toDouble(DEFAULT_VALUE).doubleValue(), 0); } @Test public void convertToDoubleNull() { assertNull(byteConverter.toDouble(null)); }
### Question: ByteConverter implements AtlasConverter<Byte> { @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.FLOAT) public Float toFloat(Byte value) { return value != null ? (float) value : null; } @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.BOOLEAN, concerns = {AtlasConversionConcern.CONVENTION}) Boolean toBoolean(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.BYTE) Byte toByte(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.CHAR) Character toCharacter(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE_TIME) Date toDate(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DOUBLE) Double toDouble(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.FLOAT) Float toFloat(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.INTEGER) Integer toInteger(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE) LocalDate toLocalDate(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.TIME) LocalTime toLocalTime(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.LONG) Long toLong(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.NUMBER) Number toNumber(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.SHORT) Short toShort(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.STRING, concerns = {AtlasConversionConcern.CONVENTION}) String toString(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Byte value); }### Answer: @Test public void convertToFloat() { assertEquals(100, byteConverter.toFloat(DEFAULT_VALUE).floatValue(), 0); } @Test public void convertToFloatNull() { assertNull(byteConverter.toFloat(null)); }
### Question: ByteConverter implements AtlasConverter<Byte> { @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.INTEGER) public Integer toInteger(Byte value) { return value != null ? (int) value : null; } @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.BOOLEAN, concerns = {AtlasConversionConcern.CONVENTION}) Boolean toBoolean(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.BYTE) Byte toByte(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.CHAR) Character toCharacter(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE_TIME) Date toDate(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DOUBLE) Double toDouble(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.FLOAT) Float toFloat(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.INTEGER) Integer toInteger(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE) LocalDate toLocalDate(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.TIME) LocalTime toLocalTime(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.LONG) Long toLong(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.NUMBER) Number toNumber(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.SHORT) Short toShort(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.STRING, concerns = {AtlasConversionConcern.CONVENTION}) String toString(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Byte value); }### Answer: @Test public void convertToInteger() { assertEquals(100, byteConverter.toInteger(DEFAULT_VALUE).intValue()); } @Test public void convertToIntegerNull() { assertNull(byteConverter.toInteger(null)); }
### Question: ByteConverter implements AtlasConverter<Byte> { @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.LONG) public Long toLong(Byte value) { return value != null ? (long) value : null; } @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.BOOLEAN, concerns = {AtlasConversionConcern.CONVENTION}) Boolean toBoolean(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.BYTE) Byte toByte(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.CHAR) Character toCharacter(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE_TIME) Date toDate(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DOUBLE) Double toDouble(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.FLOAT) Float toFloat(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.INTEGER) Integer toInteger(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE) LocalDate toLocalDate(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.TIME) LocalTime toLocalTime(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.LONG) Long toLong(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.NUMBER) Number toNumber(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.SHORT) Short toShort(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.STRING, concerns = {AtlasConversionConcern.CONVENTION}) String toString(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Byte value); }### Answer: @Test public void convertToLong() { assertEquals(100, byteConverter.toLong(DEFAULT_VALUE).longValue()); } @Test public void convertToLongNull() { assertNull(byteConverter.toLong(null)); }
### Question: ByteConverter implements AtlasConverter<Byte> { @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.SHORT) public Short toShort(Byte value) { return value != null ? (short) value : null; } @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.BOOLEAN, concerns = {AtlasConversionConcern.CONVENTION}) Boolean toBoolean(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.BYTE) Byte toByte(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.CHAR) Character toCharacter(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE_TIME) Date toDate(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DOUBLE) Double toDouble(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.FLOAT) Float toFloat(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.INTEGER) Integer toInteger(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE) LocalDate toLocalDate(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.TIME) LocalTime toLocalTime(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.LONG) Long toLong(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.NUMBER) Number toNumber(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.SHORT) Short toShort(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.STRING, concerns = {AtlasConversionConcern.CONVENTION}) String toString(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Byte value); }### Answer: @Test public void convertToShort() { assertEquals(100, byteConverter.toShort(DEFAULT_VALUE).shortValue()); } @Test public void convertToIShortNull() { assertNull(byteConverter.toShort(null)); }
### Question: ByteConverter implements AtlasConverter<Byte> { @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.STRING, concerns = {AtlasConversionConcern.CONVENTION}) public String toString(Byte value) { return value != null ? String.valueOf(value) : null; } @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.BOOLEAN, concerns = {AtlasConversionConcern.CONVENTION}) Boolean toBoolean(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.BYTE) Byte toByte(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.CHAR) Character toCharacter(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE_TIME) Date toDate(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DOUBLE) Double toDouble(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.FLOAT) Float toFloat(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.INTEGER) Integer toInteger(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE) LocalDate toLocalDate(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.TIME) LocalTime toLocalTime(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.LONG) Long toLong(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.NUMBER) Number toNumber(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.SHORT) Short toShort(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.STRING, concerns = {AtlasConversionConcern.CONVENTION}) String toString(Byte value); @AtlasConversionInfo(sourceType = FieldType.BYTE, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Byte value); }### Answer: @Test public void convertToString() throws Exception { assertEquals(byteConverter.toString(Byte.parseByte("1")), "1"); } @Test public void convertToStringNull() { assertNull(byteConverter.toString(null)); }
### Question: IntegerConverter implements AtlasConverter<Integer> { @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.BOOLEAN, concerns = { AtlasConversionConcern.CONVENTION }) public Boolean toBoolean(Integer value) { if (value == null) { return null; } return value == 0 ? Boolean.FALSE : Boolean.TRUE; } @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.BOOLEAN, concerns = { AtlasConversionConcern.CONVENTION }) Boolean toBoolean(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE_TIME) Date toDate(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DOUBLE) Double toDouble(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.FLOAT, concerns = AtlasConversionConcern.RANGE) Float toFloat(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.INTEGER) Integer toInteger(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE) LocalDate toLocalDate(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.TIME) LocalTime toLocalTime(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.LONG) Long toLong(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.STRING) String toString(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.NUMBER) Number toNumber(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Integer value); }### Answer: @Test public void convertToBoolean() { int xTrue = 1; int xFalse = 0; Boolean out = converter.toBoolean(xTrue); assertNotNull(out); assertTrue(out); out = converter.toBoolean(xFalse); assertNotNull(out); assertFalse(out); } @Test public void convertToBooleanNull() { Boolean out = converter.toBoolean(null); assertNull(out); } @Test public void convertToBooleanHigh() { Boolean out = converter.toBoolean(10); assertTrue(out); }
### Question: IntegerConverter implements AtlasConverter<Integer> { @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) public Byte toByte(Integer value) throws AtlasConversionException { if (value == null) { return null; } if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) { return value.byteValue(); } throw new AtlasConversionException(new AtlasUnsupportedException( String.format("Integer %s is greater than Byte.MAX_VALUE or less than Byte.MIN_VALUE", value))); } @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.BOOLEAN, concerns = { AtlasConversionConcern.CONVENTION }) Boolean toBoolean(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE_TIME) Date toDate(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DOUBLE) Double toDouble(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.FLOAT, concerns = AtlasConversionConcern.RANGE) Float toFloat(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.INTEGER) Integer toInteger(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE) LocalDate toLocalDate(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.TIME) LocalTime toLocalTime(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.LONG) Long toLong(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.STRING) String toString(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.NUMBER) Number toNumber(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Integer value); }### Answer: @Test public void convertToByte() throws Exception { Byte value = (byte) 100; assertEquals(value, converter.toByte(100)); } @Test(expected = AtlasConversionException.class) public void convertToByteOutOfRange() throws Exception { converter.toByte(Integer.MAX_VALUE); } @Test public void convertToByteNull() throws Exception { Byte byt = converter.toByte(null); assertNull(byt); }
### Question: JavaFieldWriterUtil { public Object getChildObject(Object parentObject, SegmentContext segment) throws AtlasException { String fieldName = segment.getName(); if (LOG.isDebugEnabled()) { LOG.debug( "Retrieving child '" + fieldName + "'.\n\tparentObject: " + parentObject); } if (parentObject == null) { if (LOG.isDebugEnabled()) { LOG.debug("Cannot find child '" + fieldName + "', parent is null."); } return null; } Method getterMethod = resolveGetterMethod(parentObject.getClass(), fieldName); if (getterMethod == null) { if (LOG.isDebugEnabled()) { LOG.debug(String.format( "Unable to detect getter method for: %s on parent: %s", fieldName, parentObject)); } return null; } getterMethod.setAccessible(true); Object childObject; try { childObject = getterMethod.invoke(parentObject); } catch (Exception e) { throw new AtlasException(e); } if (LOG.isDebugEnabled()) { if (childObject == null) { LOG.debug("Could not find child object for path: " + fieldName); } else { LOG.debug("Found child object for path '" + fieldName + "': " + childObject); } } return childObject; } JavaFieldWriterUtil(AtlasConversionService conversionService); JavaFieldWriterUtil(ClassLoader classLoader, AtlasConversionService conversionService); Object instantiateObject(Class<?> clz); Class<?> loadClass(String name); Class<?> getDefaultCollectionImplClass(CollectionType type); Object getChildObject(Object parentObject, SegmentContext segment); Object createComplexChildObject(Object parentObject, SegmentContext segmentContext, Class<?> clazz); Object createComplexChildObject(Object parentObject, SegmentContext segmentContext); void setChildObject(Object parentObject, Object childObject, SegmentContext segmentContext); Class<?> resolveChildClass(Object parentObject, SegmentContext segment); Object getCollectionItem(Object collectionObject, SegmentContext segmentContext); Object adjustCollectionSize(Object collectionObject, SegmentContext segmentContext); @SuppressWarnings({ "rawtypes", "unchecked" }) Object createComplexCollectionItem(Object collectionObject, Class<?> itemType, SegmentContext segmentContext); Object createComplexCollectionItem(Object parentObject, Object collectionObject, SegmentContext segmentContext); Class<?> resolveCollectionItemClass(Object parentObject, SegmentContext segmentContext); @SuppressWarnings({ "rawtypes", "unchecked" }) void setCollectionItem(Object collectionObject, Object item, SegmentContext segmentContext); Map<Class<?>, Class<?>> getDefaultCollectionImplClasses(); }### Answer: @Test public void testGetChildObjectNotExist() throws Exception { assertNull(writerUtil.getChildObject(targetTestClassInstance, new SegmentContext("nothing"))); }
### Question: IntegerConverter implements AtlasConverter<Integer> { @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) public Character toCharacter(Integer value) throws AtlasConversionException { if (value == null) { return null; } if (value < Character.MIN_VALUE || value > Character.MAX_VALUE) { throw new AtlasConversionException(String .format("Integer %s is greater than Character.MAX_VALUE or less than Character.MIN_VALUE", value)); } return Character.valueOf((char) value.intValue()); } @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.BOOLEAN, concerns = { AtlasConversionConcern.CONVENTION }) Boolean toBoolean(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE_TIME) Date toDate(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DOUBLE) Double toDouble(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.FLOAT, concerns = AtlasConversionConcern.RANGE) Float toFloat(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.INTEGER) Integer toInteger(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE) LocalDate toLocalDate(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.TIME) LocalTime toLocalTime(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.LONG) Long toLong(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.STRING) String toString(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.NUMBER) Number toNumber(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Integer value); }### Answer: @Test public void convertToCharacterNull() throws Exception { Character character = converter.toCharacter(null); assertNull(character); } @Test public void convertToCharacter() throws Exception { Integer integer = new Integer(4); Character character = converter.toCharacter(integer); assertNotNull(character); int revert = character.charValue(); assertEquals(integer, new Integer(revert)); } @Test(expected = AtlasConversionException.class) public void convertToCharacterGreaterThanMAX() throws Exception { Integer integer = 1500000; converter.toCharacter(integer); } @Test(expected = AtlasConversionException.class) public void convertToCharacterLessThanMIN() throws Exception { Integer integer = -1500000; converter.toCharacter(integer); }
### Question: IntegerConverter implements AtlasConverter<Integer> { @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DOUBLE) public Double toDouble(Integer value) { return value != null ? value.doubleValue() : null; } @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.BOOLEAN, concerns = { AtlasConversionConcern.CONVENTION }) Boolean toBoolean(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE_TIME) Date toDate(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DOUBLE) Double toDouble(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.FLOAT, concerns = AtlasConversionConcern.RANGE) Float toFloat(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.INTEGER) Integer toInteger(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE) LocalDate toLocalDate(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.TIME) LocalTime toLocalTime(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.LONG) Long toLong(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.STRING) String toString(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.NUMBER) Number toNumber(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Integer value); }### Answer: @Test public void convertToDouble() { Integer integer = 0; Double d = converter.toDouble(integer); assertNotNull(d); assertEquals(d, 0.0, 0.0); integer = 1; d = converter.toDouble(integer); assertNotNull(d); assertEquals(1.0, d, 0.0); } @Test public void convertToDoubleNull() { assertNull(converter.toDouble(null)); }
### Question: IntegerConverter implements AtlasConverter<Integer> { @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.FLOAT, concerns = AtlasConversionConcern.RANGE) public Float toFloat(Integer value) { return value != null ? value.floatValue() : null; } @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.BOOLEAN, concerns = { AtlasConversionConcern.CONVENTION }) Boolean toBoolean(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE_TIME) Date toDate(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DOUBLE) Double toDouble(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.FLOAT, concerns = AtlasConversionConcern.RANGE) Float toFloat(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.INTEGER) Integer toInteger(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE) LocalDate toLocalDate(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.TIME) LocalTime toLocalTime(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.LONG) Long toLong(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.STRING) String toString(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.NUMBER) Number toNumber(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Integer value); }### Answer: @Test public void convertToFloat() { Integer integer = 0; Float f = converter.toFloat(integer); assertNotNull(f); assertEquals(f, 0.0, 0.0); integer = 1; f = converter.toFloat(integer); assertNotNull(f); assertEquals(1.0, f, 0.0); } @Test public void convertToFloatNull() { assertNull(converter.toFloat(null)); }
### Question: IntegerConverter implements AtlasConverter<Integer> { @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) public Short toShort(Integer value) throws AtlasConversionException { if (value == null) { return null; } if (value > Short.MAX_VALUE || value < Short.MIN_VALUE) { throw new AtlasConversionException( String.format("Integer %s is greater than Short.MAX_VALUE or less than Short.MIN_VALUE", value)); } return value.shortValue(); } @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.BOOLEAN, concerns = { AtlasConversionConcern.CONVENTION }) Boolean toBoolean(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE_TIME) Date toDate(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DOUBLE) Double toDouble(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.FLOAT, concerns = AtlasConversionConcern.RANGE) Float toFloat(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.INTEGER) Integer toInteger(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE) LocalDate toLocalDate(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.TIME) LocalTime toLocalTime(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.LONG) Long toLong(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.STRING) String toString(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.NUMBER) Number toNumber(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Integer value); }### Answer: @Test public void convertToShort() throws Exception { int i = Short.MAX_VALUE; int negI = Short.MIN_VALUE; Short out = converter.toShort(i); assertNotNull(out); assertEquals(i, out.intValue()); out = converter.toShort(negI); assertNotNull(out); assertEquals(negI, out.intValue()); } @Test public void convertToShortNull() throws Exception { Short out = converter.toShort(null); assertNull(out); } @Test(expected = AtlasConversionException.class) public void convertToShortConvertExceptionGreaterThanMax() throws Exception { converter.toShort(Integer.MAX_VALUE); } @Test(expected = AtlasConversionException.class) public void convertToShortConvertExceptionLessThanMin() throws Exception { converter.toShort(Integer.MIN_VALUE); }
### Question: JavaFieldWriterUtil { public Class<?> getDefaultCollectionImplClass(CollectionType type) { if (type == CollectionType.LIST) { return this.defaultCollectionImplClasses.get(List.class); } else if (type == CollectionType.MAP) { return this.defaultCollectionImplClasses.get(Map.class); } return null; } JavaFieldWriterUtil(AtlasConversionService conversionService); JavaFieldWriterUtil(ClassLoader classLoader, AtlasConversionService conversionService); Object instantiateObject(Class<?> clz); Class<?> loadClass(String name); Class<?> getDefaultCollectionImplClass(CollectionType type); Object getChildObject(Object parentObject, SegmentContext segment); Object createComplexChildObject(Object parentObject, SegmentContext segmentContext, Class<?> clazz); Object createComplexChildObject(Object parentObject, SegmentContext segmentContext); void setChildObject(Object parentObject, Object childObject, SegmentContext segmentContext); Class<?> resolveChildClass(Object parentObject, SegmentContext segment); Object getCollectionItem(Object collectionObject, SegmentContext segmentContext); Object adjustCollectionSize(Object collectionObject, SegmentContext segmentContext); @SuppressWarnings({ "rawtypes", "unchecked" }) Object createComplexCollectionItem(Object collectionObject, Class<?> itemType, SegmentContext segmentContext); Object createComplexCollectionItem(Object parentObject, Object collectionObject, SegmentContext segmentContext); Class<?> resolveCollectionItemClass(Object parentObject, SegmentContext segmentContext); @SuppressWarnings({ "rawtypes", "unchecked" }) void setCollectionItem(Object collectionObject, Object item, SegmentContext segmentContext); Map<Class<?>, Class<?>> getDefaultCollectionImplClasses(); }### Answer: @Test public void testGetDefaultCollectionImplClass() throws Exception { assertNull(writerUtil.getDefaultCollectionImplClass(CollectionType.NONE)); assertNull(writerUtil.getDefaultCollectionImplClass(CollectionType.ARRAY)); assertEquals(LinkedList.class, writerUtil.getDefaultCollectionImplClass(CollectionType.LIST)); assertEquals(HashMap.class, writerUtil.getDefaultCollectionImplClass(CollectionType.MAP)); }
### Question: IntegerConverter implements AtlasConverter<Integer> { @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.LONG) public Long toLong(Integer value) { return value != null ? value.longValue() : null; } @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.BOOLEAN, concerns = { AtlasConversionConcern.CONVENTION }) Boolean toBoolean(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE_TIME) Date toDate(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DOUBLE) Double toDouble(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.FLOAT, concerns = AtlasConversionConcern.RANGE) Float toFloat(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.INTEGER) Integer toInteger(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE) LocalDate toLocalDate(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.TIME) LocalTime toLocalTime(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.LONG) Long toLong(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.STRING) String toString(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.NUMBER) Number toNumber(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Integer value); }### Answer: @Test public void convertToLong() { int i = Integer.MAX_VALUE; int negI = Integer.MIN_VALUE; Long out = converter.toLong(i); assertNotNull(out); assertEquals(i, out.intValue()); out = converter.toLong(negI); assertNotNull(out); assertEquals(negI, out.intValue()); } @Test public void convertToLongNull() { Long out = converter.toLong(null); assertNull(out); }
### Question: IntegerConverter implements AtlasConverter<Integer> { @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.STRING) public String toString(Integer value) { return value != null ? String.valueOf(value) : null; } @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.BOOLEAN, concerns = { AtlasConversionConcern.CONVENTION }) Boolean toBoolean(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE_TIME) Date toDate(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DOUBLE) Double toDouble(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.FLOAT, concerns = AtlasConversionConcern.RANGE) Float toFloat(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.INTEGER) Integer toInteger(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE) LocalDate toLocalDate(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.TIME) LocalTime toLocalTime(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.LONG) Long toLong(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.STRING) String toString(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.NUMBER) Number toNumber(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Integer value); }### Answer: @Test public void convertToString() { int i = Integer.MAX_VALUE; int negI = Integer.MIN_VALUE; String out = converter.toString(i); assertNotNull(out); assertEquals(Integer.toString(i), out); out = converter.toString(negI); assertNotNull(out); assertEquals(Integer.toString(negI), out); } @Test public void convertToStringNull() { String out = converter.toString(null); assertNull(out); }
### Question: IntegerConverter implements AtlasConverter<Integer> { @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.INTEGER) public Integer toInteger(Integer value) { return value != null ? Integer.valueOf(value) : null; } @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.BOOLEAN, concerns = { AtlasConversionConcern.CONVENTION }) Boolean toBoolean(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE_TIME) Date toDate(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DOUBLE) Double toDouble(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.FLOAT, concerns = AtlasConversionConcern.RANGE) Float toFloat(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.INTEGER) Integer toInteger(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE) LocalDate toLocalDate(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.TIME) LocalTime toLocalTime(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.LONG) Long toLong(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.STRING) String toString(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.NUMBER) Number toNumber(Integer value); @AtlasConversionInfo(sourceType = FieldType.INTEGER, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Integer value); }### Answer: @Test public void convertToInteger() { Integer foo = Integer.MAX_VALUE; Integer out = converter.toInteger(foo); foo++; assertNotNull(out); assertNotSame(out, foo); assertNotEquals(out, foo); } @Test public void convertToIntegerNull() { Integer out = converter.toInteger(null); assertNull(out); }
### Question: SqlTimestampConverter implements AtlasConverter<Timestamp> { @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME) public Date toDate(Timestamp timestamp) { return timestamp != null ? Date.from(timestamp.toInstant()) : null; } @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME_TZ) Calendar toCalendar(Timestamp timestamp); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME) Date toDate(Timestamp timestamp); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME_TZ) GregorianCalendar toGregorianCalendar(Timestamp timestamp); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE) LocalDate toLocalDate(Timestamp timestamp); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Timestamp timestamp); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.TIME) LocalTime toLocalTime(Timestamp timestamp); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE) java.sql.Date toSqlDate(Timestamp timestamp); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.TIME) java.sql.Time toSqlTime(Timestamp timestamp); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Timestamp timestamp); }### Answer: @Test public void convertFromTimestamp() { Date date = converter.toDate(new Timestamp(System.nanoTime())); assertNotNull(date); }
### Question: StringUtil { public static String getFieldNameFromGetter(String getter) { if (StringUtil.isEmpty(getter)) { return getter; } String subGetter; if (getter.startsWith("get")) { if (getter.length() <= "get".length()) { return getter; } subGetter = getter.substring("get".length()); } else if (getter.startsWith("is")) { if (getter.length() <= "is".length()) { return getter; } subGetter = getter.substring("is".length()); } else { return getter; } return String.valueOf(subGetter.charAt(0)).toLowerCase() + subGetter.substring(1); } static boolean isEmpty(String s); static String capitalizeFirstLetter(String sentence); static String getFieldNameFromGetter(String getter); static String getFieldNameFromSetter(String setter); static String formatTimeHMS(long milliseconds); }### Answer: @Test public void testRemoveGetterAndLowercaseFirstLetter() { assertNull(StringUtil.getFieldNameFromGetter(null)); assertEquals("", StringUtil.getFieldNameFromGetter("")); assertEquals("g", StringUtil.getFieldNameFromGetter("g")); assertEquals("ge", StringUtil.getFieldNameFromGetter("ge")); assertEquals("get", StringUtil.getFieldNameFromGetter("get")); assertEquals("i", StringUtil.getFieldNameFromGetter("i")); assertEquals("is", StringUtil.getFieldNameFromGetter("is")); assertEquals("abc", StringUtil.getFieldNameFromGetter("getAbc")); assertEquals("abc", StringUtil.getFieldNameFromGetter("isAbc")); }
### Question: JavaFieldReader implements AtlasFieldReader { @Override public Field read(AtlasInternalSession session) throws AtlasException { try { Field field = session.head().getSourceField(); if (sourceDocument == null) { AtlasUtil.addAudit(session, field.getDocId(), String.format( "Unable to read sourceField (path=%s), document (docId=%s) is null", field.getPath(), field.getDocId()), field.getPath(), AuditStatus.ERROR, null); } AtlasPath path = new AtlasPath(field.getPath()); List<Field> fields = getFieldsForPath(session, sourceDocument, field, path, 0); if (LOG.isDebugEnabled()) { LOG.debug("Processed input field sPath=" + field.getPath() + " sV=" + field.getValue() + " sT=" + field.getFieldType() + " docId: " + field.getDocId()); } if (path.hasCollection() && !path.isIndexedCollection()) { FieldGroup fieldGroup = AtlasModelFactory.createFieldGroupFrom(field, true); fieldGroup.getField().addAll(fields); session.head().setSourceField(fieldGroup); return fieldGroup; } else if (fields.size() == 1) { field.setValue(fields.get(0).getValue()); return field; } else { return field; } } catch (Exception e) { throw new AtlasException(e); } } @Override Field read(AtlasInternalSession session); void setDocument(Object sourceDocument); void setConversionService(AtlasConversionService conversionService); }### Answer: @Test public void testRead() throws Exception { TargetTestClass source = new TargetTestClass(); source.setAddress(new TargetAddress()); source.getAddress().setAddressLine1("123 any street"); reader.setDocument(source); read("/address/addressLine1", FieldType.STRING); assertEquals("123 any street", field.getValue()); assertEquals(0, audits.size()); }
### Question: DoubleConverter implements AtlasConverter<Double> { @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.DOUBLE) public Double toDouble(Double value) { return value != null ? Double.valueOf(value) : null; } @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.BIG_INTEGER, concerns = AtlasConversionConcern.FRACTIONAL_PART) BigInteger toBigInteger(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.BOOLEAN, concerns = { AtlasConversionConcern.CONVENTION }) Boolean toBoolean(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.BYTE, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) Byte toByte(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.CHAR, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) Character toCharacter(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.DATE, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) Date toDate(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.DOUBLE) Double toDouble(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.FLOAT, concerns = AtlasConversionConcern.RANGE) Float toFloat(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.INTEGER, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) Integer toInteger(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.DATE, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) LocalDate toLocalDate(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.TIME, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) LocalTime toLocalTime(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.DATE_TIME, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) LocalDateTime toLocalDateTime(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.LONG, concerns = AtlasConversionConcern.RANGE) Long toLong(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.NUMBER) Number toNumber(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.STRING) String toString(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.DATE_TIME_TZ, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) ZonedDateTime toZonedDateTime(Double value); }### Answer: @Test public void convertToDouble() { Double df = 0.0; Double d = converter.toDouble(df); assertNotNull(d); assertNotSame(df, d); assertEquals(0.0, d, 0.0); } @Test public void convertToDoubleNull() { Double df = null; Double d = converter.toDouble(df); assertNull(d); }
### Question: AtlasJsonModelFactory { public static JsonDocument createJsonDocument() { JsonDocument jsonDocument = new JsonDocument(); jsonDocument.setFields(new Fields()); return jsonDocument; } static JsonDocument createJsonDocument(); static JsonField createJsonField(); static String toString(JsonField f); static JsonField cloneField(JsonField field, boolean withActions); static FieldGroup cloneFieldGroup(FieldGroup group); static void copyField(Field from, Field to, boolean withActions); static final String URI_FORMAT; }### Answer: @Test public void testCreateJsonDocument() { JsonDocument jsonDoc = AtlasJsonModelFactory.createJsonDocument(); assertNotNull(jsonDoc); assertNotNull(jsonDoc.getFields()); assertNotNull(jsonDoc.getFields().getField()); assertEquals(new Integer(0), new Integer(jsonDoc.getFields().getField().size())); }
### Question: DoubleConverter implements AtlasConverter<Double> { @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.STRING) public String toString(Double value) { return value != null ? String.valueOf(value) : null; } @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.BIG_INTEGER, concerns = AtlasConversionConcern.FRACTIONAL_PART) BigInteger toBigInteger(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.BOOLEAN, concerns = { AtlasConversionConcern.CONVENTION }) Boolean toBoolean(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.BYTE, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) Byte toByte(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.CHAR, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) Character toCharacter(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.DATE, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) Date toDate(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.DOUBLE) Double toDouble(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.FLOAT, concerns = AtlasConversionConcern.RANGE) Float toFloat(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.INTEGER, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) Integer toInteger(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.DATE, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) LocalDate toLocalDate(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.TIME, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) LocalTime toLocalTime(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.DATE_TIME, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) LocalDateTime toLocalDateTime(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.LONG, concerns = AtlasConversionConcern.RANGE) Long toLong(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.NUMBER) Number toNumber(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.STRING) String toString(Double value); @AtlasConversionInfo(sourceType = FieldType.DOUBLE, targetType = FieldType.DATE_TIME_TZ, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) ZonedDateTime toZonedDateTime(Double value); }### Answer: @Test public void convertToString() { Double df = 0.0; String s = converter.toString(df); assertNotNull(s); assertTrue("0.0".equals(s)); } @Test public void convertToStringNull() { Double df = null; String s = converter.toString(df); assertNull(s); }
### Question: BooleanConverter implements AtlasConverter<Boolean> { @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.BOOLEAN) public Boolean toBoolean(Boolean value, String sourceFormat, String targetFormat) { return value != null ? Boolean.valueOf(value) : null; } @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.BOOLEAN) Boolean toBoolean(Boolean value, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.BYTE) Byte toByte(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.CHAR) Character toCharacter(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.DOUBLE) Double toDouble(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.FLOAT) Float toFloat(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.INTEGER) Integer toInteger(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.LONG) Long toLong(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.NUMBER) Number toNumber(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.SHORT) Short toShort(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.STRING, concerns = { AtlasConversionConcern.CONVENTION }) String toString(Boolean value, String sourceFormat, String targetFormat); }### Answer: @Test public void convertToBoolean() { Boolean t = Boolean.TRUE; Boolean f = Boolean.FALSE; Boolean t2 = converter.toBoolean(t, null, null); Boolean f2 = converter.toBoolean(f, null, null); assertNotNull(t2); assertEquals(t2, t); assertTrue(t2); assertNotNull(f2); assertEquals(f2, f); assertFalse(f2); } @Test public void convertToBooleanNull() { Boolean t = null; Boolean t2 = converter.toBoolean(t, null, null); assertNull(t2); }
### Question: BooleanConverter implements AtlasConverter<Boolean> { @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.BYTE) public Byte toByte(Boolean value) { return value != null ? (byte) (value ? 1 : 0) : null; } @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.BOOLEAN) Boolean toBoolean(Boolean value, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.BYTE) Byte toByte(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.CHAR) Character toCharacter(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.DOUBLE) Double toDouble(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.FLOAT) Float toFloat(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.INTEGER) Integer toInteger(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.LONG) Long toLong(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.NUMBER) Number toNumber(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.SHORT) Short toShort(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.STRING, concerns = { AtlasConversionConcern.CONVENTION }) String toString(Boolean value, String sourceFormat, String targetFormat); }### Answer: @Test public void convertToByte() { Byte trueValue = (byte) 1; assertEquals(trueValue, converter.toByte(Boolean.TRUE)); Byte falseValue = (byte) 0; assertEquals(falseValue, converter.toByte(Boolean.FALSE)); } @Test public void convertToByteNull() { assertNull(converter.toByte(null)); }
### Question: JsonService { protected boolean validJsonData(String jsonData) { if (jsonData == null || jsonData.isEmpty()) { return false; } return jsonData.startsWith("{") || jsonData.startsWith("["); } @GET @Path("/simple") @Produces(MediaType.TEXT_PLAIN) @Operation(summary ="Simple", description = "Simple hello service") @ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = String.class)), description = "Return a response")) String simpleHelloWorld(@Parameter(description = "From") @QueryParam("from") String from); @GET @Path("/inspect") @Produces(MediaType.APPLICATION_JSON) @Operation(summary ="Inspect JSON via URI", description = "*NOT IMPLEMENTED* Inspect a JSON schema or instance located at specified URI and return a Document object") @RequestBody(description = "Inspection type, one of `instance` or `Schema`", content = @Content(schema = @Schema(implementation = InspectionType.class))) @ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = JsonDocument.class)), description = "Return a Document object represented by JsonDocument")) Response getClass( @Parameter(description ="URI for JSON schema or instance") @QueryParam("uri") String uri, @QueryParam("type") String type); @POST @Path("/inspect") @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) @Operation(summary ="Inspect JSON", description = "Inspect a JSON schema or instance and return a Document object") @RequestBody(description = "JsonInspectionRequest object", content = @Content(schema = @Schema(implementation = JsonInspectionRequest.class))) @ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = JsonInspectionResponse.class)), description = "Return a Document object represented by JsonDocument")) Response inspectClass(InputStream requestIn); }### Answer: @Test public void testValidJsonData() { assertTrue(jsonService.validJsonData("{ \"foo\":\"bar\" }")); assertTrue(jsonService.validJsonData("[ { \"foo\":\"bar\" }, { \"meow\":\"blah\" } ]")); assertFalse(jsonService.validJsonData(" [ { \"foo\":\"bar\" }, { \"meow\":\"blah\" } ]")); assertFalse(jsonService.validJsonData(" \"foo\":\"bar\" }, { \"meow\":\"blah\" } ]")); assertTrue(jsonService.validJsonData(jsonService.cleanJsonData(" { \"foo\":\"bar\" }"))); assertTrue(jsonService.validJsonData(jsonService.cleanJsonData("{ \"foo\":\"bar\" } "))); assertTrue(jsonService .validJsonData(jsonService.cleanJsonData(" [ { \"foo\":\"bar\" }, { \"meow\":\"blah\" } ]"))); assertTrue(jsonService.validJsonData(jsonService.cleanJsonData("\b\t\n\f\r { \"foo\":\"bar\" }"))); }
### Question: BooleanConverter implements AtlasConverter<Boolean> { @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.CHAR) public Character toCharacter(Boolean value) { return value != null ? (char) (value ? 1 : 0) : null; } @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.BOOLEAN) Boolean toBoolean(Boolean value, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.BYTE) Byte toByte(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.CHAR) Character toCharacter(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.DOUBLE) Double toDouble(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.FLOAT) Float toFloat(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.INTEGER) Integer toInteger(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.LONG) Long toLong(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.NUMBER) Number toNumber(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.SHORT) Short toShort(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.STRING, concerns = { AtlasConversionConcern.CONVENTION }) String toString(Boolean value, String sourceFormat, String targetFormat); }### Answer: @Test public void convertToCharacter() { Boolean t = Boolean.TRUE; Boolean f = Boolean.FALSE; Character c = converter.toCharacter(t); assertNotNull(c); assertEquals(1, c.charValue()); c = converter.toCharacter(f); assertNotNull(c); assertEquals(0, c.charValue()); } @Test public void convertToCharacterNull() { Boolean t = null; Character c = converter.toCharacter(t); assertNull(c); }
### Question: BooleanConverter implements AtlasConverter<Boolean> { @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.DOUBLE) public Double toDouble(Boolean value) { return value != null ? value ? 1.0d : 0.0d : null; } @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.BOOLEAN) Boolean toBoolean(Boolean value, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.BYTE) Byte toByte(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.CHAR) Character toCharacter(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.DOUBLE) Double toDouble(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.FLOAT) Float toFloat(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.INTEGER) Integer toInteger(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.LONG) Long toLong(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.NUMBER) Number toNumber(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.SHORT) Short toShort(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.STRING, concerns = { AtlasConversionConcern.CONVENTION }) String toString(Boolean value, String sourceFormat, String targetFormat); }### Answer: @Test public void convertToDouble() { Boolean t = Boolean.TRUE; Boolean f = Boolean.FALSE; Double d = converter.toDouble(t); assertNotNull(d); assertEquals(1, d, 0.0d); d = converter.toDouble(f); assertNotNull(d); assertEquals(0, d, 0.0d); } @Test public void convertToDoubleNull() { Boolean t = null; Double d = converter.toDouble(t); assertNull(d); }
### Question: BooleanConverter implements AtlasConverter<Boolean> { @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.FLOAT) public Float toFloat(Boolean value) { return value != null ? (value ? 1.0f : 0.0f) : null; } @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.BOOLEAN) Boolean toBoolean(Boolean value, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.BYTE) Byte toByte(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.CHAR) Character toCharacter(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.DOUBLE) Double toDouble(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.FLOAT) Float toFloat(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.INTEGER) Integer toInteger(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.LONG) Long toLong(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.NUMBER) Number toNumber(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.SHORT) Short toShort(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.STRING, concerns = { AtlasConversionConcern.CONVENTION }) String toString(Boolean value, String sourceFormat, String targetFormat); }### Answer: @Test public void convertToFloat() { Boolean t = Boolean.TRUE; Boolean f = Boolean.FALSE; Float aFloat = converter.toFloat(t); assertNotNull(aFloat); assertEquals(1, aFloat, 0.0f); aFloat = converter.toFloat(f); assertNotNull(aFloat); assertEquals(0, aFloat, 0.0f); } @Test public void convertToFloatNull() { Boolean t = null; Float f = converter.toFloat(t); assertNull(f); }
### Question: BooleanConverter implements AtlasConverter<Boolean> { @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.INTEGER) public Integer toInteger(Boolean value) { return value != null ? (value ? 1 : 0) : null; } @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.BOOLEAN) Boolean toBoolean(Boolean value, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.BYTE) Byte toByte(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.CHAR) Character toCharacter(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.DOUBLE) Double toDouble(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.FLOAT) Float toFloat(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.INTEGER) Integer toInteger(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.LONG) Long toLong(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.NUMBER) Number toNumber(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.SHORT) Short toShort(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.STRING, concerns = { AtlasConversionConcern.CONVENTION }) String toString(Boolean value, String sourceFormat, String targetFormat); }### Answer: @Test public void convertToInteger() { Boolean t = Boolean.TRUE; Boolean f = Boolean.FALSE; Integer i = converter.toInteger(t); assertNotNull(i); assertEquals(1, i.intValue()); i = converter.toInteger(f); assertNotNull(i); assertEquals(0, i.intValue()); } @Test public void convertToIntegerNull() { Boolean t = null; Integer i = converter.toInteger(t); assertNull(i); }
### Question: BooleanConverter implements AtlasConverter<Boolean> { @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.LONG) public Long toLong(Boolean value) { return value != null ? (value ? 1L : 0L) : null; } @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.BOOLEAN) Boolean toBoolean(Boolean value, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.BYTE) Byte toByte(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.CHAR) Character toCharacter(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.DOUBLE) Double toDouble(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.FLOAT) Float toFloat(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.INTEGER) Integer toInteger(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.LONG) Long toLong(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.NUMBER) Number toNumber(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.SHORT) Short toShort(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.STRING, concerns = { AtlasConversionConcern.CONVENTION }) String toString(Boolean value, String sourceFormat, String targetFormat); }### Answer: @Test public void convertToLong() { Boolean t = Boolean.TRUE; Boolean f = Boolean.FALSE; Long l = converter.toLong(t); assertNotNull(l); assertEquals(1, l.longValue()); l = converter.toLong(f); assertNotNull(l); assertEquals(0, l.longValue()); } @Test public void convertToLongNull() { Boolean t = null; Long l = converter.toLong(t); assertNull(l); }
### Question: JsonModule extends BaseAtlasModule { @Override public Boolean isSupportedField(Field field) { if (super.isSupportedField(field)) { return true; } return field instanceof JsonField; } @Override void processPreValidation(AtlasInternalSession atlasSession); @Override void processPreSourceExecution(AtlasInternalSession session); @Override void processPreTargetExecution(AtlasInternalSession session); @Override void readSourceValue(AtlasInternalSession session); @Override void populateTargetField(AtlasInternalSession session); void writeTargetValue(AtlasInternalSession session); @Override void processPostSourceExecution(AtlasInternalSession session); @Override void processPostTargetExecution(AtlasInternalSession session); @Override Boolean isSupportedField(Field field); @Override Field cloneField(Field field); }### Answer: @Test public void testIsSupportedField() { assertTrue(module.isSupportedField(new JsonField())); assertFalse(module.isSupportedField(new PropertyField())); assertFalse(module.isSupportedField(new ConstantField())); assertTrue(module.isSupportedField(new SimpleField())); }
### Question: JavaService { @GET @Path("/class") @Produces(MediaType.APPLICATION_JSON) @Operation(summary = "Inspect Class", description ="Inspect a Java Class with specified fully qualified class name and return a Document object") @ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = JavaClass.class)), description = "Return a Document object represented by JavaClass")) public Response getClass(@Parameter(description = "The fully qualified class name to inspect") @QueryParam("className") String className) { ClassInspectionService classInspectionService = new ClassInspectionService(); classInspectionService.setConversionService(DefaultAtlasConversionService.getInstance()); JavaClass c = classInspectionService.inspectClass(className, CollectionType.NONE, null); classInspectionService = null; return Response.ok().entity(toJson(c)).build(); } @GET @Path("/simple") @Produces(MediaType.TEXT_PLAIN) @Operation(summary = "Simple", description ="Simple hello service") @ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = String.class)), description = "Return a response")) String simpleHelloWorld(@Parameter(description = "From") @QueryParam("from") String from); @GET @Path("/class") @Produces(MediaType.APPLICATION_JSON) @Operation(summary = "Inspect Class", description ="Inspect a Java Class with specified fully qualified class name and return a Document object") @ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = JavaClass.class)), description = "Return a Document object represented by JavaClass")) Response getClass(@Parameter(description = "The fully qualified class name to inspect") @QueryParam("className") String className); @POST @Path("/mavenclasspath") @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) @Operation(summary = "Generate Maven Classpath", description ="Retrieve a maven classpath string") @RequestBody(description = "MavenClasspathRequest object", content = @Content(schema = @Schema(implementation = MavenClasspathRequest.class))) @ApiResponses(@ApiResponse( responseCode = "200", content = @Content(schema = @Schema(implementation = MavenClasspathResponse.class)), description = "Return a MavenClasspathResponse object which contains classpath string")) Response generateClasspath(InputStream requestIn); @POST @Path("/class") @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) @Operation(summary = "Inspect Class", description ="Inspect a Java Class with specified fully qualified class name and return a Document object") @RequestBody(description = "MavenClasspathRequest object", content = @Content(schema = @Schema(implementation = MavenClasspathRequest.class))) @ApiResponses(@ApiResponse( responseCode = "200", content = @Content(schema = @Schema(implementation = JavaClass.class)), description = "Return a Document object represented by JavaClass")) Response inspectClass(InputStream requestIn); }### Answer: @Test public void testGetClass() throws Exception { Response res = javaService.getClass(JavaService.class.getName()); Object entity = res.getEntity(); assertEquals(byte[].class, entity.getClass()); JavaClass javaClass = Json.mapper().readValue((byte[]) entity, JavaClass.class); assertEquals(JavaService.class.getName(), javaClass.getClassName()); }
### Question: BooleanConverter implements AtlasConverter<Boolean> { @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.SHORT) public Short toShort(Boolean value) { return value != null ? (short) (value ? 1 : 0) : null; } @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.BOOLEAN) Boolean toBoolean(Boolean value, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.BYTE) Byte toByte(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.CHAR) Character toCharacter(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.DOUBLE) Double toDouble(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.FLOAT) Float toFloat(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.INTEGER) Integer toInteger(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.LONG) Long toLong(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.NUMBER) Number toNumber(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.SHORT) Short toShort(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.STRING, concerns = { AtlasConversionConcern.CONVENTION }) String toString(Boolean value, String sourceFormat, String targetFormat); }### Answer: @Test public void convertToShort() { Boolean t = Boolean.TRUE; Boolean f = Boolean.FALSE; Short s = converter.toShort(t); assertNotNull(s); assertEquals(1, s.shortValue()); s = converter.toShort(f); assertNotNull(s); assertEquals(0, s.shortValue()); } @Test public void convertToShortNull() { Boolean t = null; Short s = converter.toShort(t); assertNull(s); }
### Question: BooleanConverter implements AtlasConverter<Boolean> { @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.STRING, concerns = { AtlasConversionConcern.CONVENTION }) public String toString(Boolean value, String sourceFormat, String targetFormat) { if (value == null) { return null; } String format = targetFormat != null && !"".equals(targetFormat) ? targetFormat : STRING_VALUES; String[] values = format.split("\\|"); String trueValue = ""; String falseValue = ""; if (values.length == 2) { trueValue = values[0]; falseValue = values[1]; } else if (values.length == 1) { trueValue = values[0]; } return String.valueOf((value ? trueValue : falseValue)); } @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.BOOLEAN) Boolean toBoolean(Boolean value, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.BYTE) Byte toByte(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.CHAR) Character toCharacter(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.DOUBLE) Double toDouble(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.FLOAT) Float toFloat(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.INTEGER) Integer toInteger(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.LONG) Long toLong(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.NUMBER) Number toNumber(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.SHORT) Short toShort(Boolean value); @AtlasConversionInfo(sourceType = FieldType.BOOLEAN, targetType = FieldType.STRING, concerns = { AtlasConversionConcern.CONVENTION }) String toString(Boolean value, String sourceFormat, String targetFormat); }### Answer: @Test public void convertToString() { Boolean t = Boolean.TRUE; Boolean f = Boolean.FALSE; String s = converter.toString(t, null, null); assertNotNull(s); assertTrue("true".equals(s)); s = converter.toString(f, null, null); assertNotNull(s); assertTrue("false".equals(s)); } @Test public void convertToStringNull() { Boolean t = null; String s = converter.toString(t, null, null); assertNull(s); }
### Question: JsonFieldWriter implements AtlasFieldWriter { @Override public void write(AtlasInternalSession session) throws AtlasException { Field targetField = session.head().getTargetField(); if (targetField == null) { throw new AtlasException(new IllegalArgumentException("Argument 'jsonField' cannot be null")); } if (LOG.isDebugEnabled()) { LOG.debug("Field: " + AtlasModelFactory.toString(targetField)); LOG.debug("Field type=" + targetField.getFieldType() + " path=" + targetField.getPath() + " v=" + targetField.getValue()); } AtlasPath path = new AtlasPath(targetField.getPath()); SegmentContext lastSegment = path.getLastSegment(); if (this.rootNode == null) { if (path.hasCollectionRoot()) { this.rootNode = objectMapper.createArrayNode(); } else { this.rootNode = objectMapper.createObjectNode(); } } ContainerNode<?> parentNode = this.rootNode; SegmentContext parentSegment = null; for (SegmentContext segment : path.getSegments(true)) { if (!segment.equals(lastSegment)) { if (LOG.isDebugEnabled()) { LOG.debug("Now processing parent segment: " + segment); } JsonNode childNode; if (segment.isRoot()) { if (parentNode instanceof ArrayNode) { childNode = parentNode; } else { parentSegment = segment; continue; } } else { childNode = getChildNode(parentNode, parentSegment, segment); } if (childNode == null) { childNode = createParentNode(parentNode, parentSegment, segment); } else if (childNode instanceof ArrayNode) { Integer index = segment.getCollectionIndex(); if (index == null) { return; } ArrayNode arrayChild = (ArrayNode) childNode; if (arrayChild.size() < (index + 1)) { if (LOG.isDebugEnabled()) { LOG.debug("Object Array is too small, resizing to accomodate index: " + index + ", current array: " + arrayChild); } while (arrayChild.size() < (index + 1)) { arrayChild.addObject(); } if (LOG.isDebugEnabled()) { LOG.debug("Object Array after resizing: " + arrayChild); } } childNode = arrayChild.get(index); } if (childNode == null) { return; } parentNode = (ObjectNode) childNode; parentSegment = segment; } else { if (targetField.getFieldType() == FieldType.COMPLEX) { createParentNode(parentNode, parentSegment, segment); return; } if (LOG.isDebugEnabled()) { LOG.debug("Now processing field value segment: " + segment); } writeValue(parentNode, parentSegment, segment, targetField); } } } JsonFieldWriter(); JsonFieldWriter(ObjectMapper objectMapper); ContainerNode<?> getRootNode(); ObjectMapper getObjectMapper(); @Override void write(AtlasInternalSession session); }### Answer: @Test(expected = AtlasException.class) public void testWriteNullField() throws Exception { write(null); } @Test public void testJsonFieldBooleanString() throws Exception { Path path = Paths.get("target" + File.separator + "test-write-field-byte-string.json"); String fieldPath = "/primitiveValue"; Object testObject = "abcd"; FieldType inputFieldType = FieldType.STRING; FieldType outputFieldType = FieldType.BOOLEAN; write(path, fieldPath, testObject, inputFieldType); AtlasInternalSession session = read(path, outputFieldType, fieldPath); assertEquals(false, session.head().getSourceField().getValue()); }
### Question: JsonFieldWriter implements AtlasFieldWriter { public ContainerNode<?> getRootNode() { return rootNode; } JsonFieldWriter(); JsonFieldWriter(ObjectMapper objectMapper); ContainerNode<?> getRootNode(); ObjectMapper getObjectMapper(); @Override void write(AtlasInternalSession session); }### Answer: @Test public void testSimpleRepeated() throws Exception { writeString("/orders[0]/orderid", "orderid1"); writeString("/orders[1]/orderid", "orderid2"); Assert.assertThat(writer.getRootNode().toString(), Is.is("{\"orders\":[{\"orderid\":\"orderid1\"},{\"orderid\":\"orderid2\"}]}")); } @Test public void testWriteComplexObjectUnrooted() throws Exception { writeComplexTestData("", ""); Assert.assertThat(writer.getRootNode().toString(), Is.is( "{\"address\":{\"addressLine1\":\"123 Main St\",\"addressLine2\":\"Suite 42b\",\"city\":\"Anytown\",\"state\":\"NY\",\"zipCode\":\"90210\"},\"contact\":{\"firstName\":\"Ozzie\",\"lastName\":\"Smith\",\"phoneNumber\":\"5551212\",\"zipCode\":\"81111\"},\"orderId\":9}")); } @Test public void testWriteComplexObjectRooted() throws Exception { writeComplexTestData("/order", ""); final String instance = new String( Files.readAllBytes(Paths.get("src/test/resources/complex-rooted-result.json"))); Assert.assertNotNull(instance); Assert.assertThat(prettyPrintJson(writer.getRootNode().toString()), Is.is(prettyPrintJson(instance))); } @Test public void testWriteComplexObjectRepeated() throws Exception { for (int i = 0; i < 5; i++) { String prefix = "/SourceOrderList/orders[" + i + "]"; String valueSuffix = " (" + (i + 1) + ")"; writeComplexTestData(prefix, valueSuffix); } writeInteger("/SourceOrderList/orderBatchNumber", 4123562); writeInteger("/SourceOrderList/numberOfOrders", 5); final String instance = new String( Files.readAllBytes(Paths.get("src/test/resources/complex-repeated-result.json"))); Assert.assertNotNull(instance); Assert.assertThat(prettyPrintJson(writer.getRootNode().toString()), Is.is(prettyPrintJson(instance))); }
### Question: StringConverter implements AtlasConverter<String> { @AtlasConversionInfo(sourceType = FieldType.STRING, targetType = FieldType.STRING) public String toString(String value, String sourceFormat, String targetFormat) { if (value == null) { return null; } return new String(value); } @AtlasConversionInfo(sourceType = FieldType.STRING, targetType = FieldType.DECIMAL, concerns = AtlasConversionConcern.FORMAT) BigDecimal toBigDecimal(String value); @AtlasConversionInfo(sourceType = FieldType.STRING, targetType = FieldType.BIG_INTEGER, concerns = AtlasConversionConcern.FORMAT) BigInteger toBigInteger(String value); @AtlasConversionInfo(sourceType = FieldType.STRING, targetType = FieldType.BOOLEAN, concerns = AtlasConversionConcern.CONVENTION) Boolean toBoolean(String value, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.STRING, targetType = FieldType.BYTE, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.FORMAT, AtlasConversionConcern.FRACTIONAL_PART}) Byte toByte(String value); @AtlasConversionInfo(sourceType = FieldType.STRING, targetType = FieldType.CHAR, concerns = AtlasConversionConcern.RANGE) Character toCharacter(String value); @AtlasConversionInfo(sourceType = FieldType.STRING, targetType = FieldType.DATE_TIME) Date toDate(String date, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.STRING, targetType = FieldType.DOUBLE, concerns = { AtlasConversionConcern.FORMAT, AtlasConversionConcern.RANGE }) Double toDouble(String value); @AtlasConversionInfo(sourceType = FieldType.STRING, targetType = FieldType.FLOAT, concerns = { AtlasConversionConcern.FORMAT, AtlasConversionConcern.RANGE }) Float toFloat(String value); @AtlasConversionInfo(sourceType = FieldType.STRING, targetType = FieldType.INTEGER, concerns = { AtlasConversionConcern.FORMAT, AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART }) Integer toInteger(String value); @AtlasConversionInfo(sourceType = FieldType.STRING, targetType = FieldType.DATE) LocalDate toLocalDate(String value); @AtlasConversionInfo(sourceType = FieldType.STRING, targetType = FieldType.TIME) LocalTime toLocalTime(String value); @AtlasConversionInfo(sourceType = FieldType.STRING, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(String value); @AtlasConversionInfo(sourceType = FieldType.STRING, targetType = FieldType.LONG, concerns = { AtlasConversionConcern.FORMAT, AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART }) Long toLong(String value); @AtlasConversionInfo(sourceType = FieldType.STRING, targetType = FieldType.SHORT, concerns = { AtlasConversionConcern.FORMAT, AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART }) Short toShort(String value); @AtlasConversionInfo(sourceType = FieldType.STRING, targetType = FieldType.STRING) String toString(String value, String sourceFormat, String targetFormat); @AtlasConversionInfo(sourceType = FieldType.STRING, targetType = FieldType.NUMBER, concerns = { AtlasConversionConcern.FORMAT }) Number toNumber(String value); @AtlasConversionInfo(sourceType = FieldType.STRING, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(String value); }### Answer: @Test public void convertToString() { String zero = "0"; String converted = converter.toString(zero, null, null); assertNotNull(converted); assertNotSame(converted, zero); assertTrue("0".equals(converted)); } @Test public void convertToStringNull() { String s = converter.toString(null, null, null); assertNull(s); }
### Question: LocalDateConverter implements AtlasConverter<LocalDate> { @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.DATE_TIME) public Date toDate(LocalDate value) { return value != null ? new Date(getStartEpochMilli(value)) : null; } @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.DATE_TIME_TZ) Calendar toCalendar(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.DATE_TIME) Date toDate(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.DOUBLE) Double toDouble(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.FLOAT) Float toFloat(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.DATE_TIME_TZ) GregorianCalendar toGregorianCalendar(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.INTEGER, concerns = AtlasConversionConcern.RANGE) Integer toInteger(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.DATE) LocalDate toLocalDate(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.TIME) LocalTime toLocalTime(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.LONG) Long toLong(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.STRING) String toString(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.NUMBER) Number toNumber(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.DATE) java.sql.Date toSqlDate(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.DATE_TIME) java.sql.Timestamp toSqlTimestamp(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(LocalDate value); }### Answer: @Test public void toDate() { Date date = converter.toDate(LocalDate.now()); assertNotNull(date); }
### Question: LocalDateConverter implements AtlasConverter<LocalDate> { @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.DATE_TIME_TZ) public ZonedDateTime toZonedDateTime(LocalDate value) { return value != null ? value.atStartOfDay(ZoneId.systemDefault()) : null; } @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.DATE_TIME_TZ) Calendar toCalendar(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.DATE_TIME) Date toDate(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.DOUBLE) Double toDouble(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.FLOAT) Float toFloat(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.DATE_TIME_TZ) GregorianCalendar toGregorianCalendar(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.INTEGER, concerns = AtlasConversionConcern.RANGE) Integer toInteger(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.DATE) LocalDate toLocalDate(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.TIME) LocalTime toLocalTime(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.LONG) Long toLong(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.STRING) String toString(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.NUMBER) Number toNumber(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.DATE) java.sql.Date toSqlDate(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.DATE_TIME) java.sql.Timestamp toSqlTimestamp(LocalDate value); @AtlasConversionInfo(sourceType = FieldType.DATE, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(LocalDate value); }### Answer: @Test public void toZonedDateTime() { ZonedDateTime zonedDateTime = converter.toZonedDateTime(LocalDate.now()); assertNotNull(zonedDateTime); assertTrue(zonedDateTime.getZone().getId().equals(ZoneId.systemDefault().getId())); } @Test public void toZonedDateTimeWithZoneId() { ZonedDateTime zonedDateTime = DateTimeHelper.toZonedDateTime(new Date(), "America/New_York"); assertNotNull(zonedDateTime); assertTrue(zonedDateTime.getZone().getId().equals("America/New_York")); }
### Question: FloatConverter implements AtlasConverter<Float> { @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.BOOLEAN, concerns = { AtlasConversionConcern.CONVENTION }) public Boolean toBoolean(Float value) { if (value == null) { return null; } if (value == 0.0) { return Boolean.FALSE; } return Boolean.TRUE; } @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.BIG_INTEGER, concerns = AtlasConversionConcern.FRACTIONAL_PART) BigInteger toBigInteger(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.BOOLEAN, concerns = { AtlasConversionConcern.CONVENTION }) Boolean toBoolean(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.BYTE, concerns = { AtlasConversionConcern.RANGE }) Byte toByte(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.DATE, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) Date toDate(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.DOUBLE) Double toDouble(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.FLOAT) Float toFloat(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.INTEGER, concerns = AtlasConversionConcern.RANGE) Integer toInteger(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.DATE, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) LocalDate toLocalDate(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.TIME, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) LocalTime toLocalTime(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.DATE_TIME, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) LocalDateTime toLocalDateTime(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.LONG, concerns = AtlasConversionConcern.RANGE) Long toLong(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.NUMBER) Number toNumber(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.STRING) String toString(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.DATE_TIME_TZ, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) ZonedDateTime toZonedDateTime(Float value); }### Answer: @Test public void convertToBoolean() { Float df = 0.0f; Float dt = 1.0f; Boolean b = converter.toBoolean(dt); assertNotNull(b); assertTrue(b); b = converter.toBoolean(df); assertNotNull(b); assertFalse(b); } @Test public void convertToBooleanNull() { Float df = null; Boolean b = converter.toBoolean(df); assertNull(b); } @Test public void convertToBooleanNegative() { Float dt = -1.0f; Boolean b = converter.toBoolean(dt); assertTrue(b); }
### Question: FloatConverter implements AtlasConverter<Float> { @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.DOUBLE) public Double toDouble(Float value) { if (value == null) { return null; } return value.doubleValue(); } @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.BIG_INTEGER, concerns = AtlasConversionConcern.FRACTIONAL_PART) BigInteger toBigInteger(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.BOOLEAN, concerns = { AtlasConversionConcern.CONVENTION }) Boolean toBoolean(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.BYTE, concerns = { AtlasConversionConcern.RANGE }) Byte toByte(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.DATE, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) Date toDate(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.DOUBLE) Double toDouble(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.FLOAT) Float toFloat(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.INTEGER, concerns = AtlasConversionConcern.RANGE) Integer toInteger(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.DATE, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) LocalDate toLocalDate(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.TIME, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) LocalTime toLocalTime(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.DATE_TIME, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) LocalDateTime toLocalDateTime(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.LONG, concerns = AtlasConversionConcern.RANGE) Long toLong(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.NUMBER) Number toNumber(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.STRING) String toString(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.DATE_TIME_TZ, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) ZonedDateTime toZonedDateTime(Float value); }### Answer: @Test public void convertToDouble() { Float df = 0.0f; Double d = converter.toDouble(df); assertNotNull(d); assertNotSame(df, d); assertEquals(0.0, d.floatValue(), 0.0); df = 1.0f; d = converter.toDouble(df); assertNotNull(d); assertNotSame(df, d); assertEquals(1.0, d.floatValue(), 0.0); } @Test public void convertToDoubleNull() { Float df = null; Double d = converter.toDouble(df); assertNull(d); }
### Question: FloatConverter implements AtlasConverter<Float> { @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.FLOAT) public Float toFloat(Float value) { if (value == null) { return null; } return value.floatValue(); } @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.BIG_INTEGER, concerns = AtlasConversionConcern.FRACTIONAL_PART) BigInteger toBigInteger(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.BOOLEAN, concerns = { AtlasConversionConcern.CONVENTION }) Boolean toBoolean(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.BYTE, concerns = { AtlasConversionConcern.RANGE }) Byte toByte(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.DATE, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) Date toDate(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.DOUBLE) Double toDouble(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.FLOAT) Float toFloat(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.INTEGER, concerns = AtlasConversionConcern.RANGE) Integer toInteger(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.DATE, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) LocalDate toLocalDate(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.TIME, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) LocalTime toLocalTime(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.DATE_TIME, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) LocalDateTime toLocalDateTime(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.LONG, concerns = AtlasConversionConcern.RANGE) Long toLong(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.NUMBER) Number toNumber(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.STRING) String toString(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.DATE_TIME_TZ, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) ZonedDateTime toZonedDateTime(Float value); }### Answer: @Test public void convertToFloat() { Float df = 0.0f; Float d = converter.toFloat(df); assertNotNull(d); assertNotSame(df, d); assertEquals(0.0, d, 0.0); } @Test public void convertToFloatNull() { Float df = null; Float d = converter.toFloat(df); assertNull(d); }
### Question: AtlasXmlModelFactory { public static XmlDocument createXmlDocument() { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.setFields(new Fields()); return xmlDocument; } static XmlDocument createXmlDocument(); static XmlField createXmlField(); static XmlField cloneField(XmlField field, boolean withActions); static FieldGroup cloneFieldGroup(FieldGroup group); static void copyField(Field from, Field to, boolean withActions); static final String URI_FORMAT; }### Answer: @Test public void testCreateXmlDocument() { XmlDocument xmlDoc = AtlasXmlModelFactory.createXmlDocument(); assertNotNull(xmlDoc); assertNotNull(xmlDoc.getFields()); assertNotNull(xmlDoc.getFields().getField()); assertEquals(new Integer(0), new Integer(xmlDoc.getFields().getField().size())); }
### Question: XmlModule extends BaseAtlasModule { @Override public Boolean isSupportedField(Field field) { if (super.isSupportedField(field)) { return true; } return field instanceof XmlField; } @Override void init(); @Override void processPreValidation(AtlasInternalSession atlasSession); @Override void processPreSourceExecution(AtlasInternalSession session); @Override void processPreTargetExecution(AtlasInternalSession session); @Override void readSourceValue(AtlasInternalSession session); @Override void populateTargetField(AtlasInternalSession session); @Override void writeTargetValue(AtlasInternalSession session); @Override void processPostSourceExecution(AtlasInternalSession session); @Override void processPostTargetExecution(AtlasInternalSession session); @Override Boolean isSupportedField(Field field); @Override Field cloneField(Field field); }### Answer: @Test public void testIsSupportedField() { assertTrue(module.isSupportedField(new XmlField())); assertFalse(module.isSupportedField(new PropertyField())); assertFalse(module.isSupportedField(new ConstantField())); assertTrue(module.isSupportedField(new SimpleField())); }
### Question: FloatConverter implements AtlasConverter<Float> { @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.STRING) public String toString(Float value) { return value != null ? String.valueOf(value) : null; } @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.BIG_INTEGER, concerns = AtlasConversionConcern.FRACTIONAL_PART) BigInteger toBigInteger(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.BOOLEAN, concerns = { AtlasConversionConcern.CONVENTION }) Boolean toBoolean(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.BYTE, concerns = { AtlasConversionConcern.RANGE }) Byte toByte(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.DATE, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) Date toDate(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.DOUBLE) Double toDouble(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.FLOAT) Float toFloat(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.INTEGER, concerns = AtlasConversionConcern.RANGE) Integer toInteger(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.DATE, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) LocalDate toLocalDate(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.TIME, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) LocalTime toLocalTime(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.DATE_TIME, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) LocalDateTime toLocalDateTime(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.LONG, concerns = AtlasConversionConcern.RANGE) Long toLong(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.NUMBER) Number toNumber(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.SHORT, concerns = AtlasConversionConcern.RANGE) Short toShort(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.STRING) String toString(Float value); @AtlasConversionInfo(sourceType = FieldType.FLOAT, targetType = FieldType.DATE_TIME_TZ, concerns = {AtlasConversionConcern.RANGE, AtlasConversionConcern.FRACTIONAL_PART}) ZonedDateTime toZonedDateTime(Float value); }### Answer: @Test public void convertToString() { Float df = 0.0f; String s = converter.toString(df); assertNotNull(s); assertTrue("0.0".equals(s)); } @Test public void convertToStringNull() { Float df = null; String s = converter.toString(df); assertNull(s); }
### Question: GregorianCalendarConverter implements AtlasConverter<GregorianCalendar> { @AtlasConversionInfo(sourceType = FieldType.DATE_TIME_TZ, targetType = FieldType.DATE_TIME) public Date toDate(GregorianCalendar calendar) { return zdtConverter.toDate(calendar.toZonedDateTime()); } @AtlasConversionInfo(sourceType = FieldType.DATE_TIME_TZ, targetType = FieldType.DATE_TIME_TZ) Calendar toCalendar(GregorianCalendar calendar); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME_TZ, targetType = FieldType.DATE_TIME) Date toDate(GregorianCalendar calendar); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME_TZ, targetType = FieldType.DATE) LocalDate toLocalDate(GregorianCalendar calendar); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME_TZ, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(GregorianCalendar calendar); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME_TZ, targetType = FieldType.TIME) LocalTime toLocalTime(GregorianCalendar calendar); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME_TZ, targetType = FieldType.DATE) java.sql.Date toSqlDate(GregorianCalendar calendar); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME_TZ, targetType = FieldType.TIME) java.sql.Time toSqlTime(GregorianCalendar calendar); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME_TZ, targetType = FieldType.DATE_TIME) java.sql.Timestamp toSqlTimestamp(GregorianCalendar calendar); @AtlasConversionInfo(sourceType = FieldType.DATE_TIME_TZ, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZoneDateTime(GregorianCalendar calendar); }### Answer: @Test public void convertFromGregorianCalendar() { Date date = converter.toDate((GregorianCalendar) GregorianCalendar.getInstance()); assertNotNull(date); }
### Question: ShortConverter implements AtlasConverter<Short> { @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.BOOLEAN, concerns = AtlasConversionConcern.CONVENTION) public Boolean toBoolean(Short value) { if (value == null) { return null; } return value == 0 ? Boolean.FALSE : Boolean.TRUE; } @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.BOOLEAN, concerns = AtlasConversionConcern.CONVENTION) Boolean toBoolean(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE_TIME) Date toDate(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DOUBLE) Double toDouble(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.FLOAT) Float toFloat(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.INTEGER) Integer toInteger(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE) LocalDate toLocalDate(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.TIME) LocalTime toLocalTime(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.LONG) Long toLong(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.NUMBER) Number toNumber(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.SHORT) Short toShort(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.STRING) String toString(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Short value); }### Answer: @Test public void convertToBoolean() { Short f = 0; Short t = 1; Boolean b = converter.toBoolean(t); assertNotNull(b); assertTrue(b); b = converter.toBoolean(f); assertNotNull(b); assertFalse(b); } @Test public void convertToBooleanNull() { Short l = null; Boolean b = converter.toBoolean(l); assertNull(b); } @Test public void convertToBooleanNegative() { Short dt = -1; Boolean b = converter.toBoolean(dt); assertTrue(b); }
### Question: ShortConverter implements AtlasConverter<Short> { @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) public Byte toByte(Short value) throws AtlasConversionException { if (value == null) { return null; } if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) { return value.byteValue(); } throw new AtlasConversionException(new AtlasUnsupportedException( String.format("Short %s is greater than Byte.MAX_VALUE or less than Byte.MIN_VALUE", value))); } @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.BOOLEAN, concerns = AtlasConversionConcern.CONVENTION) Boolean toBoolean(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE_TIME) Date toDate(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DOUBLE) Double toDouble(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.FLOAT) Float toFloat(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.INTEGER) Integer toInteger(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE) LocalDate toLocalDate(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.TIME) LocalTime toLocalTime(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.LONG) Long toLong(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.NUMBER) Number toNumber(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.SHORT) Short toShort(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.STRING) String toString(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Short value); }### Answer: @Test public void convertToByte() throws Exception { Short l = 0; Byte value = (byte) 0; assertEquals(value, converter.toByte(l)); } @Test(expected = AtlasConversionException.class) public void convertToByteOutOfRange() throws Exception { converter.toByte(Short.MAX_VALUE); } @Test public void convertToByteNull() throws Exception { assertNull(converter.toByte(null)); }
### Question: ShortConverter implements AtlasConverter<Short> { @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) public Character toCharacter(Short value) throws AtlasConversionException { if (value == null) { return null; } if (value < Character.MIN_VALUE || value > Character.MAX_VALUE) { throw new AtlasConversionException(String .format("Short %s is greater than Character.MAX_VALUE or less than Character.MIN_VALUE", value)); } return Character.valueOf((char) value.intValue()); } @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.BOOLEAN, concerns = AtlasConversionConcern.CONVENTION) Boolean toBoolean(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE_TIME) Date toDate(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DOUBLE) Double toDouble(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.FLOAT) Float toFloat(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.INTEGER) Integer toInteger(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE) LocalDate toLocalDate(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.TIME) LocalTime toLocalTime(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.LONG) Long toLong(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.NUMBER) Number toNumber(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.SHORT) Short toShort(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.STRING) String toString(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Short value); }### Answer: @Test public void convertToCharacter() throws Exception { Short shorty = new Short((short) 4); Character character = converter.toCharacter(shorty); assertNotNull(character); assertEquals(Character.valueOf((char) shorty.shortValue()), character); } @Test public void convertToCharacterNull() throws Exception { Short s = null; Character c = converter.toCharacter(s); assertNull(c); } @Test public void convertToCharacterMAX() throws Exception { Short s = Short.MAX_VALUE; Character c = converter.toCharacter(s); assertNotNull(c); assertEquals(Character.valueOf((char) s.shortValue()), c); } @Test(expected = AtlasConversionException.class) public void convertToCharacterMIN() throws Exception { Short s = Short.MIN_VALUE; converter.toCharacter(s); }
### Question: ShortConverter implements AtlasConverter<Short> { @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DOUBLE) public Double toDouble(Short value) { if (value == null) { return null; } return value.doubleValue(); } @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.BOOLEAN, concerns = AtlasConversionConcern.CONVENTION) Boolean toBoolean(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE_TIME) Date toDate(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DOUBLE) Double toDouble(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.FLOAT) Float toFloat(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.INTEGER) Integer toInteger(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE) LocalDate toLocalDate(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.TIME) LocalTime toLocalTime(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.LONG) Long toLong(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.NUMBER) Number toNumber(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.SHORT) Short toShort(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.STRING) String toString(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Short value); }### Answer: @Test public void convertToDouble() { Short s = 0; Double d = converter.toDouble(s); assertNotNull(d); assertEquals(0.0, d, 0.0); } @Test public void convertToDoubleNull() { Short s = null; Double d = converter.toDouble(s); assertNull(d); } @Test public void convertToDoubleMAX() { Short s = Short.MAX_VALUE; Double d = converter.toDouble(s); assertNotNull(d); assertEquals(Short.MAX_VALUE, s, 0.0); }
### Question: ShortConverter implements AtlasConverter<Short> { @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.FLOAT) public Float toFloat(Short value) { if (value == null) { return null; } return value.floatValue(); } @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.BOOLEAN, concerns = AtlasConversionConcern.CONVENTION) Boolean toBoolean(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE_TIME) Date toDate(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DOUBLE) Double toDouble(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.FLOAT) Float toFloat(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.INTEGER) Integer toInteger(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE) LocalDate toLocalDate(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.TIME) LocalTime toLocalTime(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.LONG) Long toLong(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.NUMBER) Number toNumber(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.SHORT) Short toShort(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.STRING) String toString(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Short value); }### Answer: @Test public void convertToFloat() { Short s = 0; Float f = converter.toFloat(s); assertNotNull(f); assertEquals(0.0f, f, 0.0); } @Test public void convertToFloatNull() { assertNull(converter.toFloat(null)); } @Test public void convertToFloatMAX() { Short s = Short.MAX_VALUE; Float f = converter.toFloat(s); assertNotNull(f); assertEquals(Short.MAX_VALUE, s, 0.0); }
### Question: ShortConverter implements AtlasConverter<Short> { @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.INTEGER) public Integer toInteger(Short value) { if (value == null) { return null; } return value.intValue(); } @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.BOOLEAN, concerns = AtlasConversionConcern.CONVENTION) Boolean toBoolean(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE_TIME) Date toDate(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DOUBLE) Double toDouble(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.FLOAT) Float toFloat(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.INTEGER) Integer toInteger(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE) LocalDate toLocalDate(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.TIME) LocalTime toLocalTime(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.LONG) Long toLong(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.NUMBER) Number toNumber(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.SHORT) Short toShort(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.STRING) String toString(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Short value); }### Answer: @Test public void convertToInteger() { Short s = 0; Integer i = converter.toInteger(s); assertNotNull(i); assertEquals(0, i, 0.0); } @Test public void convertToIntegerNull() { Short l = null; Integer i = converter.toInteger(l); assertNull(i); }
### Question: JavaModule extends BaseAtlasModule { @Override public Boolean isSupportedField(Field field) { if (super.isSupportedField(field)) { return true; } return field instanceof JavaField || field instanceof JavaEnumField; } JavaModule(); @Override void init(); @Override void destroy(); @Override void processPreValidation(AtlasInternalSession atlasSession); @Override void processPreSourceExecution(AtlasInternalSession atlasSession); @Override void processPreTargetExecution(AtlasInternalSession atlasSession); @Override void readSourceValue(AtlasInternalSession session); @Override void populateTargetField(AtlasInternalSession session); @Override void writeTargetValue(AtlasInternalSession session); @Override void processPostSourceExecution(AtlasInternalSession session); @Override void processPostTargetExecution(AtlasInternalSession session); @Override Boolean isSupportedField(Field field); @Override Field cloneField(Field field); static final String DEFAULT_LIST_CLASS; }### Answer: @Test public void testIsSupportedField() { assertTrue(module.isSupportedField(new JavaField())); assertTrue(module.isSupportedField(new JavaEnumField())); assertFalse(module.isSupportedField(new PropertyField())); assertFalse(module.isSupportedField(new ConstantField())); assertTrue(module.isSupportedField(new SimpleField())); }
### Question: ShortConverter implements AtlasConverter<Short> { @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.LONG) public Long toLong(Short value) { return value != null ? value.longValue() : null; } @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.BOOLEAN, concerns = AtlasConversionConcern.CONVENTION) Boolean toBoolean(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE_TIME) Date toDate(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DOUBLE) Double toDouble(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.FLOAT) Float toFloat(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.INTEGER) Integer toInteger(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE) LocalDate toLocalDate(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.TIME) LocalTime toLocalTime(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.LONG) Long toLong(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.NUMBER) Number toNumber(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.SHORT) Short toShort(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.STRING) String toString(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Short value); }### Answer: @Test public void convertToLong() { Short s = 1; Long l = converter.toLong(s); assertNotNull(l); assertEquals(1, l, 0.0); } @Test public void convertToLongNull() { Short s = null; Long l = converter.toLong(s); assertNull(l); } @Test public void convertToLongMAX() { Short s = Short.MAX_VALUE; Long l = converter.toLong(s); assertNotNull(l); assertEquals(32767.0, l, 0.0); } @Test public void convertToLongMIN() { Short s = Short.MIN_VALUE; Long l = converter.toLong(s); assertNotNull(l); assertEquals(-32768.0, l, 0.0); }
### Question: ShortConverter implements AtlasConverter<Short> { @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.SHORT) public Short toShort(Short value) { return value != null ? new Short(value) : null; } @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.BOOLEAN, concerns = AtlasConversionConcern.CONVENTION) Boolean toBoolean(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE_TIME) Date toDate(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DOUBLE) Double toDouble(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.FLOAT) Float toFloat(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.INTEGER) Integer toInteger(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE) LocalDate toLocalDate(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.TIME) LocalTime toLocalTime(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.LONG) Long toLong(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.NUMBER) Number toNumber(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.SHORT) Short toShort(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.STRING) String toString(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Short value); }### Answer: @Test public void convertToShort() { Short aShort = 0; Short s = converter.toShort(aShort); assertNotNull(s); assertNotSame(aShort, s); assertEquals(0, s, 0.0); } @Test public void convertToShortNull() { Short l = null; Short s = converter.toShort(l); assertNull(s); }
### Question: ShortConverter implements AtlasConverter<Short> { @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.STRING) public String toString(Short value) { return value != null ? String.valueOf(value) : null; } @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DECIMAL) BigDecimal toBigDecimal(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.BIG_INTEGER) BigInteger toBigInteger(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.BOOLEAN, concerns = AtlasConversionConcern.CONVENTION) Boolean toBoolean(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.BYTE, concerns = AtlasConversionConcern.RANGE) Byte toByte(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.CHAR, concerns = { AtlasConversionConcern.RANGE, AtlasConversionConcern.CONVENTION }) Character toCharacter(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE_TIME) Date toDate(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DOUBLE) Double toDouble(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.FLOAT) Float toFloat(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.INTEGER) Integer toInteger(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE) LocalDate toLocalDate(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.TIME) LocalTime toLocalTime(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE_TIME) LocalDateTime toLocalDateTime(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.LONG) Long toLong(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.NUMBER) Number toNumber(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.SHORT) Short toShort(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.STRING) String toString(Short value); @AtlasConversionInfo(sourceType = FieldType.SHORT, targetType = FieldType.DATE_TIME_TZ) ZonedDateTime toZonedDateTime(Short value); }### Answer: @Test public void convertToString() { Short l = 0; String s = converter.toString(l); assertNotNull(s); assertTrue("0".equals(s)); } @Test public void convertToStringNull() { Short l = null; String s = converter.toString(l); assertNull(s); }
### Question: StringPatternValidator implements AtlasValidator { @Override public boolean supports(Class<?> clazz) { return String.class.isAssignableFrom(clazz); } StringPatternValidator(ValidationScope scope, String violationMessage, String pattern); StringPatternValidator(ValidationScope scope, String violationMessage, String pattern, boolean useMatch); @Override boolean supports(Class<?> clazz); @Override void validate(Object target, List<Validation> validations, String id); @Override void validate(Object target, List<Validation> validations, String id, ValidationStatus status); }### Answer: @Test public void testSupported() { validator = new StringPatternValidator(ValidationScope.ALL, "Must match .*", ".*"); assertTrue(validator.supports(String.class)); } @Test public void testUnsupported() { validator = new StringPatternValidator(ValidationScope.DATA_SOURCE, "Must match [0-9_.]", "[0-9_.]"); assertFalse(validator.supports(Double.class)); }
### Question: StringPatternValidator implements AtlasValidator { @Override public void validate(Object target, List<Validation> validations, String id) { validate(target, validations, id, ValidationStatus.ERROR); } StringPatternValidator(ValidationScope scope, String violationMessage, String pattern); StringPatternValidator(ValidationScope scope, String violationMessage, String pattern, boolean useMatch); @Override boolean supports(Class<?> clazz); @Override void validate(Object target, List<Validation> validations, String id); @Override void validate(Object target, List<Validation> validations, String id, ValidationStatus status); }### Answer: @Test public void testValidate() { validator = new StringPatternValidator(ValidationScope.MAPPING, "Must match [^A-Za-z0-9_.]", "[^A-Za-z0-9_.]"); validator.validate("This. &* should result in an error", validations, "testValidate"); assertTrue(validationHelper.hasErrors()); validations.clear(); assertFalse(validationHelper.hasErrors()); validator.validate("This_isafineexample.whatever1223", validations, "testValidate-2"); assertFalse(validationHelper.hasErrors()); } @Test public void testValidateUsingMatch() { validator = new StringPatternValidator(ValidationScope.LOOKUP_TABLE, "Must match [0-9]+", "[0-9]+", true); validator.validate("0333", validations, "testValidateUsingMatch"); assertFalse(validationHelper.hasErrors()); validator = new StringPatternValidator(ValidationScope.PROPERTY, "Must match [0-9]", "[0-9]", true); validator.validate("This_isafineexample.whatever", validations, "testValidateUsingMatch-2"); assertTrue(validationHelper.hasErrors()); }
### Question: CompositeValidator implements AtlasValidator { @Override public boolean supports(Class<?> clazz) { for (AtlasValidator validator : validators) { if (validator.supports(clazz)) { return true; } } return false; } CompositeValidator(List<AtlasValidator> validators); CompositeValidator(AtlasValidator... validators); @Override boolean supports(Class<?> clazz); @Override void validate(Object target, List<Validation> validations, String id); @Override void validate(Object target, List<Validation> validations, String id, ValidationStatus status); }### Answer: @Test public void testSupports() { NotEmptyValidator notEmptyValidator = new NotEmptyValidator(ValidationScope.ALL, "violationMessage"); assertTrue(notEmptyValidator.supports(new HashSet<String>())); assertTrue(notEmptyValidator.supports(new ArrayList<String>())); assertTrue(notEmptyValidator.supports(new HashMap<String, String>())); assertFalse(notEmptyValidator.supports(new String[1])); assertTrue(notEmptyValidator.supports(new ArrayDeque<String>())); List<AtlasValidator> validators = new ArrayList<>(); validators.add(notEmptyValidator); CompositeValidator compositeValidator = new CompositeValidator(validators); assertFalse(compositeValidator.supports(NotEmptyValidator.class)); assertTrue(compositeValidator.supports(List.class)); }
### Question: LookupTableNameValidator implements AtlasValidator { @Override public boolean supports(Class<?> clazz) { return LookupTables.class.isAssignableFrom(clazz); } LookupTableNameValidator(String violationMessage); @Override boolean supports(Class<?> clazz); @Override void validate(Object target, List<Validation> validations, String id); @Override void validate(Object target, List<Validation> validations, String id, ValidationStatus status); }### Answer: @Test public void testSupportsLookupTables() { LookupTables lookupTables = makeLookupTables(); assertTrue(validator.supports(lookupTables.getClass())); }
### Question: LookupTableNameValidator implements AtlasValidator { @Override public void validate(Object target, List<Validation> validations, String id) { validate(target, validations, id, ValidationStatus.ERROR); } LookupTableNameValidator(String violationMessage); @Override boolean supports(Class<?> clazz); @Override void validate(Object target, List<Validation> validations, String id); @Override void validate(Object target, List<Validation> validations, String id, ValidationStatus status); }### Answer: @Test public void testValidateDuplicatedNames() { LookupTables lookupTables = makeLookupTables(); validator.validate(lookupTables, validations, null); assertTrue(validationHelper.hasErrors()); assertEquals(ValidationScope.LOOKUP_TABLE, validationHelper.getValidation().get(0).getScope()); assertNull(validationHelper.getValidation().get(0).getId()); debugErrors(validationHelper); } @Test public void testValidateNoDuplicateNames() { LookupTables lookupTables = makeLookupTables(); lookupTables.getLookupTable().remove(2); validator.validate(lookupTables, validations, null); assertFalse(validationHelper.hasErrors()); }
### Question: NotEmptyValidator implements AtlasValidator { @Override public boolean supports(Class<?> clazz) { return clazz.isAssignableFrom(List.class) || clazz.isAssignableFrom(Map.class) || clazz.isAssignableFrom(Set.class) || clazz.isAssignableFrom(Collection.class); } NotEmptyValidator(ValidationScope scope, String violationMessage); @Override boolean supports(Class<?> clazz); boolean supports(Object object); @Override void validate(Object target, List<Validation> validations, String id); @Override void validate(Object target, List<Validation> validations, String id, ValidationStatus status); }### Answer: @Test public void testSupported() { assertTrue(validator.supports(Map.class)); assertTrue(validator.supports(List.class)); assertTrue(validator.supports(Set.class)); assertTrue(validator.supports(Collection.class)); } @Test public void testUnsupported() { assertFalse(validator.supports(HashMap.class)); }
### Question: NotEmptyValidator implements AtlasValidator { @Override public void validate(Object target, List<Validation> validations, String id) { validate(target, validations, id, ValidationStatus.ERROR); } NotEmptyValidator(ValidationScope scope, String violationMessage); @Override boolean supports(Class<?> clazz); boolean supports(Object object); @Override void validate(Object target, List<Validation> validations, String id); @Override void validate(Object target, List<Validation> validations, String id, ValidationStatus status); }### Answer: @Test public void testValidate() { List<String> stuff = new ArrayList<>(); stuff.add("one"); stuff.add("two"); validator.validate(stuff, validations, "testValidate-1"); assertFalse(validationHelper.hasErrors()); validator.validate(stuff, validations, "testValidate-2", ValidationStatus.WARN); assertFalse(validationHelper.hasErrors()); } @Test public void testValidateInvalid() { List<String> stuff = new ArrayList<>(); validator.validate(stuff, validations, "testValidateInvalid"); assertTrue(validationHelper.hasErrors()); assertEquals(new Integer(1), new Integer(validationHelper.getCount())); assertEquals(ValidationScope.MAPPING, validationHelper.getValidation().get(0).getScope()); assertEquals("testValidateInvalid", validationHelper.getValidation().get(0).getId()); assertFalse(validationHelper.hasWarnings()); assertFalse(validationHelper.hasInfos()); }
### Question: StringLengthValidator implements AtlasValidator { @Override public boolean supports(Class<?> clazz) { return String.class.isAssignableFrom(clazz); } StringLengthValidator(ValidationScope scope, String violationMessage, int minLength, int maxLength); @Override boolean supports(Class<?> clazz); @Override void validate(Object target, List<Validation> validations, String id); @Override void validate(Object target, List<Validation> validations, String id, ValidationStatus status); }### Answer: @Test public void testSupported() { assertTrue(validator.supports(String.class)); } @Test public void testUnsupported() { assertFalse(validator.supports(Integer.class)); }
### Question: StringLengthValidator implements AtlasValidator { @Override public void validate(Object target, List<Validation> validations, String id) { validate(target, validations, id, ValidationStatus.ERROR); } StringLengthValidator(ValidationScope scope, String violationMessage, int minLength, int maxLength); @Override boolean supports(Class<?> clazz); @Override void validate(Object target, List<Validation> validations, String id); @Override void validate(Object target, List<Validation> validations, String id, ValidationStatus status); }### Answer: @Test public void testValidate() { String pass = "1112332"; validator.validate(pass, validations, "testValidate"); assertFalse(validationHelper.hasErrors()); } @Test public void testValidateInvalid() { String pass = ""; validator.validate(pass, validations, "testValidateInvalid"); assertTrue(validationHelper.hasErrors()); assertEquals(new Integer(1), new Integer(validationHelper.getAllValidations().size())); Validation validation = validations.get(0); assertNotNull(validation); assertEquals(ValidationScope.MAPPING, validation.getScope()); assertEquals("testValidateInvalid", validation.getId()); assertTrue("Must be of this length".equals(validation.getMessage())); }
### Question: NonNullValidator implements AtlasValidator { @Override public boolean supports(Class<?> clazz) { return true; } NonNullValidator(ValidationScope scope, String violationMessage); @Override boolean supports(Class<?> clazz); @Override void validate(Object target, List<Validation> validations, String id); @Override void validate(Object target, List<Validation> validations, String id, ValidationStatus status); }### Answer: @Test public void testSupports() { assertTrue(validator.supports(String.class)); assertTrue(validator.supports(Integer.class)); assertTrue(validator.supports(Double.class)); }
### Question: NonNullValidator implements AtlasValidator { @Override public void validate(Object target, List<Validation> validations, String id) { validate(target, validations, id, ValidationStatus.ERROR); } NonNullValidator(ValidationScope scope, String violationMessage); @Override boolean supports(Class<?> clazz); @Override void validate(Object target, List<Validation> validations, String id); @Override void validate(Object target, List<Validation> validations, String id, ValidationStatus status); }### Answer: @Test public void testValidate() { String notNull = "notNull"; validator.validate(notNull, validations, null); assertFalse(validationHelper.hasErrors()); } @Test public void testValidateInvalid() { validator.validate(null, validations, null); assertTrue(validationHelper.hasErrors()); assertEquals(new Integer(1), new Integer(validationHelper.getCount())); Validation validation = validationHelper.getAllValidations().get(0); assertNotNull(validation); assertTrue("Cannot be null".equals(validation.getMessage())); assertEquals(ValidationScope.MAPPING, validation.getScope()); assertNull(validation.getId()); String empty = ""; validationHelper.getAllValidations().clear(); validator.validate(empty, validations, "testValidateInvalid-2"); assertTrue(validationHelper.hasErrors()); assertEquals(new Integer(1), new Integer(validationHelper.getCount())); assertEquals(ValidationScope.MAPPING, validationHelper.getValidation().get(0).getScope()); assertEquals("testValidateInvalid-2", validationHelper.getValidation().get(0).getId()); }
### Question: PositiveIntegerValidator implements AtlasValidator { @Override public boolean supports(Class<?> clazz) { return Integer.class.isAssignableFrom(clazz) || String.class.isAssignableFrom(clazz); } PositiveIntegerValidator(ValidationScope scope, String violationMessage); @Override boolean supports(Class<?> clazz); @Override void validate(Object target, List<Validation> validations, String id); @Override void validate(Object target, List<Validation> validations, String id, ValidationStatus status); }### Answer: @Test public void testSupported() { assertTrue(validator.supports(Integer.class)); assertTrue(validator.supports(String.class)); } @Test public void testUnsupported() { assertFalse(validator.supports(Boolean.class)); }
### Question: PositiveIntegerValidator implements AtlasValidator { @Override public void validate(Object target, List<Validation> validations, String id) { this.validate(target, validations, id, ValidationStatus.ERROR); } PositiveIntegerValidator(ValidationScope scope, String violationMessage); @Override boolean supports(Class<?> clazz); @Override void validate(Object target, List<Validation> validations, String id); @Override void validate(Object target, List<Validation> validations, String id, ValidationStatus status); }### Answer: @Test public void testValidate() { validator.validate(0, validations, null); validator.validate(1222, validations, null); assertFalse(validationHelper.hasErrors()); } @Test public void testValidateInvalid() { validator.validate(-1, validations, "testValidateInvalid"); assertTrue(validationHelper.hasErrors()); assertEquals(new Integer(1), new Integer(validationHelper.getCount())); assertEquals("testValidateInvalid", validationHelper.getValidation().get(0).getId()); } @Test public void testValidateInvalidWarn() { validator.validate(-1, validations, "testValidateInvalidWarn", ValidationStatus.WARN); assertFalse(validationHelper.hasErrors()); assertTrue(validationHelper.hasWarnings()); assertEquals(new Integer(1), new Integer(validationHelper.getCount())); assertEquals("testValidateInvalidWarn", validationHelper.getValidation().get(0).getId()); } @Test public void testValidateInvalidInfo() { validator.validate(-1, validations, "testValidateInvalidInfo", ValidationStatus.INFO); assertFalse(validationHelper.hasErrors()); assertFalse(validationHelper.hasWarnings()); assertTrue(validationHelper.hasInfos()); assertEquals(new Integer(1), new Integer(validationHelper.getCount())); assertEquals("testValidateInvalidInfo", validationHelper.getValidation().get(0).getId()); } @Test public void testValidateWithErrorLevel() { validator.validate(0, validations, "testValidateWithErrorLevel", ValidationStatus.WARN); assertFalse(validationHelper.hasErrors()); assertFalse(validationHelper.hasWarnings()); assertFalse(validationHelper.hasInfos()); }
### Question: AtlasPath { public SegmentContext getLastSegmentParent() { if (this.segmentContexts.isEmpty() || this.segmentContexts.size() == 1) { return null; } return this.segmentContexts.get(this.segmentContexts.size() - 2); } AtlasPath(String p); protected AtlasPath(List<SegmentContext> segments); private AtlasPath(); static Field extractChildren(Field f, String path); static void setCollectionIndexRecursively(FieldGroup group, int segmentIndex, int index); AtlasPath appendField(String fieldExpression); List<SegmentContext> getSegments(boolean includeRoot); Boolean isRoot(); SegmentContext getRootSegment(); Boolean isCollectionRoot(); Boolean hasCollectionRoot(); SegmentContext getLastSegment(); SegmentContext getLastCollectionSegment(); SegmentContext getLastSegmentParent(); AtlasPath getLastSegmentParentPath(); SegmentContext getParentSegmentOf(SegmentContext sc); boolean hasCollection(); boolean isIndexedCollection(); SegmentContext setCollectionIndex(int segmentIndex, Integer collectionIndex); List<SegmentContext> getCollectionSegments(boolean includeRoot); SegmentContext setVacantCollectionIndex(Integer collectionIndex); String getSegmentPath(SegmentContext sc); @Override String toString(); String getOriginalPath(); int getCollectionSegmentCount(); static final String PATH_SEPARATOR; static final char PATH_SEPARATOR_CHAR; static final String PATH_SEPARATOR_ESCAPED; static final String PATH_ARRAY_START; static final String PATH_ARRAY_END; static final String PATH_LIST_START; static final String PATH_LIST_END; static final String PATH_MAP_START; static final String PATH_MAP_END; static final String PATH_ATTRIBUTE_PREFIX; static final String PATH_NAMESPACE_SEPARATOR; }### Answer: @Test public void testGetLastSegmentParent() { AtlasPath p = new AtlasPath("/orders/contact/firstName"); assertEquals("contact", p.getLastSegmentParent().getName()); assertTrue(new AtlasPath("orders").getLastSegmentParent().isRoot()); }
### Question: AtlasPath { public AtlasPath getLastSegmentParentPath() { if (this.segmentContexts.isEmpty() || this.segmentContexts.size() == 1) { return null; } AtlasPath parentPath = new AtlasPath(); for (int i = 0; i < this.segmentContexts.size() - 1; i++) { parentPath.appendField(this.segmentContexts.get(i).getExpression()); } return parentPath; } AtlasPath(String p); protected AtlasPath(List<SegmentContext> segments); private AtlasPath(); static Field extractChildren(Field f, String path); static void setCollectionIndexRecursively(FieldGroup group, int segmentIndex, int index); AtlasPath appendField(String fieldExpression); List<SegmentContext> getSegments(boolean includeRoot); Boolean isRoot(); SegmentContext getRootSegment(); Boolean isCollectionRoot(); Boolean hasCollectionRoot(); SegmentContext getLastSegment(); SegmentContext getLastCollectionSegment(); SegmentContext getLastSegmentParent(); AtlasPath getLastSegmentParentPath(); SegmentContext getParentSegmentOf(SegmentContext sc); boolean hasCollection(); boolean isIndexedCollection(); SegmentContext setCollectionIndex(int segmentIndex, Integer collectionIndex); List<SegmentContext> getCollectionSegments(boolean includeRoot); SegmentContext setVacantCollectionIndex(Integer collectionIndex); String getSegmentPath(SegmentContext sc); @Override String toString(); String getOriginalPath(); int getCollectionSegmentCount(); static final String PATH_SEPARATOR; static final char PATH_SEPARATOR_CHAR; static final String PATH_SEPARATOR_ESCAPED; static final String PATH_ARRAY_START; static final String PATH_ARRAY_END; static final String PATH_LIST_START; static final String PATH_LIST_END; static final String PATH_MAP_START; static final String PATH_MAP_END; static final String PATH_ATTRIBUTE_PREFIX; static final String PATH_NAMESPACE_SEPARATOR; }### Answer: @Test public void testGetLastSegmentParentPath() { AtlasPath p = new AtlasPath("/orders[]/contact/firstName"); assertEquals("/orders[]/contact", p.getLastSegmentParentPath().toString()); assertEquals("/", new AtlasPath("orders").getLastSegmentParentPath().toString()); }
### Question: AtlasPath { public boolean isIndexedCollection() { boolean hasIndexedCollection = false; for (SegmentContext sc : this.segmentContexts) { if (sc.getCollectionType() != CollectionType.NONE) { if (sc.getCollectionIndex() != null) { hasIndexedCollection = true; } } } return hasIndexedCollection; } AtlasPath(String p); protected AtlasPath(List<SegmentContext> segments); private AtlasPath(); static Field extractChildren(Field f, String path); static void setCollectionIndexRecursively(FieldGroup group, int segmentIndex, int index); AtlasPath appendField(String fieldExpression); List<SegmentContext> getSegments(boolean includeRoot); Boolean isRoot(); SegmentContext getRootSegment(); Boolean isCollectionRoot(); Boolean hasCollectionRoot(); SegmentContext getLastSegment(); SegmentContext getLastCollectionSegment(); SegmentContext getLastSegmentParent(); AtlasPath getLastSegmentParentPath(); SegmentContext getParentSegmentOf(SegmentContext sc); boolean hasCollection(); boolean isIndexedCollection(); SegmentContext setCollectionIndex(int segmentIndex, Integer collectionIndex); List<SegmentContext> getCollectionSegments(boolean includeRoot); SegmentContext setVacantCollectionIndex(Integer collectionIndex); String getSegmentPath(SegmentContext sc); @Override String toString(); String getOriginalPath(); int getCollectionSegmentCount(); static final String PATH_SEPARATOR; static final char PATH_SEPARATOR_CHAR; static final String PATH_SEPARATOR_ESCAPED; static final String PATH_ARRAY_START; static final String PATH_ARRAY_END; static final String PATH_LIST_START; static final String PATH_LIST_END; static final String PATH_MAP_START; static final String PATH_MAP_END; static final String PATH_ATTRIBUTE_PREFIX; static final String PATH_NAMESPACE_SEPARATOR; }### Answer: @Test public void testIsIndexedCollection() { AtlasPath p = null; p = new AtlasPath("order"); assertFalse(p.isIndexedCollection()); p = new AtlasPath("/order/contact/firstName"); assertFalse(p.isIndexedCollection()); p = new AtlasPath("order[]"); assertFalse(p.isIndexedCollection()); p = new AtlasPath("/orders[4]/contact/firstName"); assertTrue(p.isIndexedCollection()); p = new AtlasPath("/orders[0]/contact/firstName"); assertTrue(p.isIndexedCollection()); p = new AtlasPath("/orders[]/contact/firstName"); assertFalse(p.isIndexedCollection()); p = new AtlasPath("orders<>"); assertFalse(p.isIndexedCollection()); p = new AtlasPath("orders<6>"); assertTrue(p.isIndexedCollection()); p = new AtlasPath("/foo/orders<6>"); assertTrue(p.isIndexedCollection()); p = new AtlasPath("/foo/orders<6>/bar"); assertTrue(p.isIndexedCollection()); p = new AtlasPath("/orders<3>/contact/firstName"); assertTrue(p.isIndexedCollection()); p = new AtlasPath("/orders<0>/contact/firstName"); assertTrue(p.isIndexedCollection()); p = new AtlasPath("/orders<>/contact/firstName"); assertFalse(p.isIndexedCollection()); }
### Question: AtlasPath { public SegmentContext getLastSegment() { return this.segmentContexts.get(this.segmentContexts.size()-1); } AtlasPath(String p); protected AtlasPath(List<SegmentContext> segments); private AtlasPath(); static Field extractChildren(Field f, String path); static void setCollectionIndexRecursively(FieldGroup group, int segmentIndex, int index); AtlasPath appendField(String fieldExpression); List<SegmentContext> getSegments(boolean includeRoot); Boolean isRoot(); SegmentContext getRootSegment(); Boolean isCollectionRoot(); Boolean hasCollectionRoot(); SegmentContext getLastSegment(); SegmentContext getLastCollectionSegment(); SegmentContext getLastSegmentParent(); AtlasPath getLastSegmentParentPath(); SegmentContext getParentSegmentOf(SegmentContext sc); boolean hasCollection(); boolean isIndexedCollection(); SegmentContext setCollectionIndex(int segmentIndex, Integer collectionIndex); List<SegmentContext> getCollectionSegments(boolean includeRoot); SegmentContext setVacantCollectionIndex(Integer collectionIndex); String getSegmentPath(SegmentContext sc); @Override String toString(); String getOriginalPath(); int getCollectionSegmentCount(); static final String PATH_SEPARATOR; static final char PATH_SEPARATOR_CHAR; static final String PATH_SEPARATOR_ESCAPED; static final String PATH_ARRAY_START; static final String PATH_ARRAY_END; static final String PATH_LIST_START; static final String PATH_LIST_END; static final String PATH_MAP_START; static final String PATH_MAP_END; static final String PATH_ATTRIBUTE_PREFIX; static final String PATH_NAMESPACE_SEPARATOR; }### Answer: @Test public void testGetLastSegment() { AtlasPath p = new AtlasPath("/order/contact/firstName"); assertEquals("firstName", p.getLastSegment().getName()); assertEquals("firstName", p.getLastSegment().getExpression()); assertTrue((new AtlasPath("")).getLastSegment().isRoot()); assertNotNull(p.getOriginalPath()); }
### Question: AtlasPath { public boolean hasCollection() { for (SegmentContext sc : this.segmentContexts) { if (sc.getCollectionType() != CollectionType.NONE) { return true; } } return false; } AtlasPath(String p); protected AtlasPath(List<SegmentContext> segments); private AtlasPath(); static Field extractChildren(Field f, String path); static void setCollectionIndexRecursively(FieldGroup group, int segmentIndex, int index); AtlasPath appendField(String fieldExpression); List<SegmentContext> getSegments(boolean includeRoot); Boolean isRoot(); SegmentContext getRootSegment(); Boolean isCollectionRoot(); Boolean hasCollectionRoot(); SegmentContext getLastSegment(); SegmentContext getLastCollectionSegment(); SegmentContext getLastSegmentParent(); AtlasPath getLastSegmentParentPath(); SegmentContext getParentSegmentOf(SegmentContext sc); boolean hasCollection(); boolean isIndexedCollection(); SegmentContext setCollectionIndex(int segmentIndex, Integer collectionIndex); List<SegmentContext> getCollectionSegments(boolean includeRoot); SegmentContext setVacantCollectionIndex(Integer collectionIndex); String getSegmentPath(SegmentContext sc); @Override String toString(); String getOriginalPath(); int getCollectionSegmentCount(); static final String PATH_SEPARATOR; static final char PATH_SEPARATOR_CHAR; static final String PATH_SEPARATOR_ESCAPED; static final String PATH_ARRAY_START; static final String PATH_ARRAY_END; static final String PATH_LIST_START; static final String PATH_LIST_END; static final String PATH_MAP_START; static final String PATH_MAP_END; static final String PATH_ATTRIBUTE_PREFIX; static final String PATH_NAMESPACE_SEPARATOR; }### Answer: @Test public void testHasCollection() { AtlasPath p = new AtlasPath("/order/contact/firstName"); assertFalse(p.hasCollection()); }