@Test(expected = IllegalArgumentException.class) public void noCommands() { EncryptionServiceImpl service = new EncryptionServiceImpl(); service.init(); }
@PostConstruct public void init() { if ( inputCommands == null || inputCommands.size() == 0 ) { throw new IllegalArgumentException( String.format( "You must provide %s implementations for this service to function properly", EncryptionCommand.class ) ); } commands = new HashMap<>(); for ( EncryptionCommand command : inputCommands ) { String name = command.getName(); Assert.notNull( name, "Encryption command name cannot be null" ); EncryptionCommand existing = commands.get( name ); if ( existing != null ) { throw new IllegalArgumentException( String.format( "Both class %s and %s implement command '%s'. This is a wiring bug, " + "and not allowed. Each instance must define it's own type", command.getClass().getName(), existing.getClass().getName(), name ) ); } commands.put( name, command ); } defaultCommand = commands.get( defaultCommandName ); Assert.notNull( defaultCommand, "Encryption command for type " + defaultCommandName + " must be present" ); }
EncryptionServiceImpl implements EncryptionService { @PostConstruct public void init() { if ( inputCommands == null || inputCommands.size() == 0 ) { throw new IllegalArgumentException( String.format( "You must provide %s implementations for this service to function properly", EncryptionCommand.class ) ); } commands = new HashMap<>(); for ( EncryptionCommand command : inputCommands ) { String name = command.getName(); Assert.notNull( name, "Encryption command name cannot be null" ); EncryptionCommand existing = commands.get( name ); if ( existing != null ) { throw new IllegalArgumentException( String.format( "Both class %s and %s implement command '%s'. This is a wiring bug, " + "and not allowed. Each instance must define it's own type", command.getClass().getName(), existing.getClass().getName(), name ) ); } commands.put( name, command ); } defaultCommand = commands.get( defaultCommandName ); Assert.notNull( defaultCommand, "Encryption command for type " + defaultCommandName + " must be present" ); } }
EncryptionServiceImpl implements EncryptionService { @PostConstruct public void init() { if ( inputCommands == null || inputCommands.size() == 0 ) { throw new IllegalArgumentException( String.format( "You must provide %s implementations for this service to function properly", EncryptionCommand.class ) ); } commands = new HashMap<>(); for ( EncryptionCommand command : inputCommands ) { String name = command.getName(); Assert.notNull( name, "Encryption command name cannot be null" ); EncryptionCommand existing = commands.get( name ); if ( existing != null ) { throw new IllegalArgumentException( String.format( "Both class %s and %s implement command '%s'. This is a wiring bug, " + "and not allowed. Each instance must define it's own type", command.getClass().getName(), existing.getClass().getName(), name ) ); } commands.put( name, command ); } defaultCommand = commands.get( defaultCommandName ); Assert.notNull( defaultCommand, "Encryption command for type " + defaultCommandName + " must be present" ); }  }
EncryptionServiceImpl implements EncryptionService { @PostConstruct public void init() { if ( inputCommands == null || inputCommands.size() == 0 ) { throw new IllegalArgumentException( String.format( "You must provide %s implementations for this service to function properly", EncryptionCommand.class ) ); } commands = new HashMap<>(); for ( EncryptionCommand command : inputCommands ) { String name = command.getName(); Assert.notNull( name, "Encryption command name cannot be null" ); EncryptionCommand existing = commands.get( name ); if ( existing != null ) { throw new IllegalArgumentException( String.format( "Both class %s and %s implement command '%s'. This is a wiring bug, " + "and not allowed. Each instance must define it's own type", command.getClass().getName(), existing.getClass().getName(), name ) ); } commands.put( name, command ); } defaultCommand = commands.get( defaultCommandName ); Assert.notNull( defaultCommand, "Encryption command for type " + defaultCommandName + " must be present" ); }  @Override boolean verify( String inputSecret, CredentialsInfo creds, UUID userId, UUID applicationId ); @Autowired void setCommands( List<EncryptionCommand> inputCommands ); @PostConstruct void init(); void setDefaultCommandName( String defaultCommandName ); @Override CredentialsInfo plainTextCredentials( String secret, UUID userId, UUID applicationId ); @Override CredentialsInfo defaultEncryptedCredentials( String input, UUID userId, UUID applicationId ); @Override EncryptionCommand getCommand( String name ); @Override EncryptionCommand getDefaultCommand(); }
EncryptionServiceImpl implements EncryptionService { @PostConstruct public void init() { if ( inputCommands == null || inputCommands.size() == 0 ) { throw new IllegalArgumentException( String.format( "You must provide %s implementations for this service to function properly", EncryptionCommand.class ) ); } commands = new HashMap<>(); for ( EncryptionCommand command : inputCommands ) { String name = command.getName(); Assert.notNull( name, "Encryption command name cannot be null" ); EncryptionCommand existing = commands.get( name ); if ( existing != null ) { throw new IllegalArgumentException( String.format( "Both class %s and %s implement command '%s'. This is a wiring bug, " + "and not allowed. Each instance must define it's own type", command.getClass().getName(), existing.getClass().getName(), name ) ); } commands.put( name, command ); } defaultCommand = commands.get( defaultCommandName ); Assert.notNull( defaultCommand, "Encryption command for type " + defaultCommandName + " must be present" ); }  @Override boolean verify( String inputSecret, CredentialsInfo creds, UUID userId, UUID applicationId ); @Autowired void setCommands( List<EncryptionCommand> inputCommands ); @PostConstruct void init(); void setDefaultCommandName( String defaultCommandName ); @Override CredentialsInfo plainTextCredentials( String secret, UUID userId, UUID applicationId ); @Override CredentialsInfo defaultEncryptedCredentials( String input, UUID userId, UUID applicationId ); @Override EncryptionCommand getCommand( String name ); @Override EncryptionCommand getDefaultCommand();  }