public static Set<X509Certificate> filterValid( X509Certificate... certificates )
    {
        final Set<X509Certificate> results = new HashSet<>();

        if (certificates != null)
        {
            for ( X509Certificate certificate : certificates )
            {
                if ( certificate == null )
                {
                    continue;
                }

                try
                {
                    certificate.checkValidity();
                }
                catch ( CertificateExpiredException | CertificateNotYetValidException e )
                {
                    // Not yet or no longer valid. Don't include in result.
                    continue;
                }

                results.add( certificate );
            }
        }

        return results;
    }
@Test
    public void testFilterValidEmpty() throws Exception
    {
        // Setup fixture.
        final Collection<X509Certificate> input = new ArrayList<>();

        // Execute system under test.
        final Collection<X509Certificate> result = CertificateUtils.filterValid( input );

        // Verify results.
        assertTrue( result.isEmpty() );
    }