TranslationSession implements TranslationSource { public <T> T getTranslation( Object source, Class<T> destinationClass ) { return getTranslation( source, DefaultObjectTargetFactory.class, destinationClass ); } TranslationSession();  TranslationSession( TranslatorFactory translatorFactory );  TranslationSession( TranslatorFactory translatorFactory, Map<String, Object> variables ); T getTranslation( Object source, Class<T> destinationClass ); T getTranslation( Object source, Class<? extends TranslationTargetFactory> factory, Class<T> destinationClass ); @Override void update( Object source, Object destination ); TranslationTargetFactory getTranslationTargetFactory( Class<? extends TranslationTargetFactory> factoryType ); @Override List<T> getEachTranslation( List<?> sources, Class<T> destinationClass ); @Override Set<T> getEachTranslation( Set<?> sources, Class<T> destinationClass ); @Override Collection<T> getEachTranslation( Collection<?> sources, Class<T> destinationClass );  }
@Test public void testGetTranslationDoesntTranslateIfFoundInCache() { Mockito.when( cache.getTranslation( "One", Integer.class ) ).thenReturn( Integer.valueOf( 1 ) ); session.getTranslation( "One", Integer.class ); Mockito.verify( cache ).getTranslation( "One", Integer.class ); Mockito.verifyZeroInteractions( translatorFactory ); }
@Test public void testGetTranslationReturnsCachedValue() { Integer translation = Integer.valueOf( 1 ); Mockito.when( cache.getTranslation( "One", Integer.class ) ).thenReturn( translation ); Integer result = session.getTranslation( "One", Integer.class ); Assert.assertSame( translation, result ); }