Allow filtering Java test cases.
This commit is contained in:
		@@ -18,6 +18,8 @@
 | 
			
		||||
 | 
			
		||||
package com.lyndir.masterpassword;
 | 
			
		||||
 | 
			
		||||
import static com.lyndir.lhunath.opal.system.util.StringUtils.strf;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonCreator;
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonValue;
 | 
			
		||||
import com.google.common.primitives.UnsignedInteger;
 | 
			
		||||
@@ -190,6 +192,12 @@ public abstract class MPAlgorithm {
 | 
			
		||||
 | 
			
		||||
    protected abstract byte[] toID(byte[] bytes);
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String toString() {
 | 
			
		||||
        
 | 
			
		||||
        return strf( "%d, %s", version().toInt(), getClass().getSimpleName() );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The algorithm iterations.
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -25,7 +25,8 @@ import static com.lyndir.lhunath.opal.system.util.StringUtils.*;
 | 
			
		||||
import com.google.common.primitives.UnsignedInteger;
 | 
			
		||||
import com.lyndir.lhunath.opal.system.logging.Logger;
 | 
			
		||||
import com.lyndir.lhunath.opal.system.util.NNSupplier;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
import javax.xml.bind.annotation.XmlTransient;
 | 
			
		||||
@@ -41,11 +42,21 @@ public class MPTests {
 | 
			
		||||
    @SuppressWarnings("UnusedDeclaration")
 | 
			
		||||
    private static final Logger logger = Logger.get( MPTests.class );
 | 
			
		||||
 | 
			
		||||
    private final Set<String> filters = new HashSet<>();
 | 
			
		||||
 | 
			
		||||
    List<Case> cases;
 | 
			
		||||
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public List<Case> getCases() {
 | 
			
		||||
        return checkNotNull( cases );
 | 
			
		||||
        if (filters.isEmpty())
 | 
			
		||||
            return checkNotNull( cases );
 | 
			
		||||
 | 
			
		||||
        return checkNotNull( cases ).stream().filter( testCase -> {
 | 
			
		||||
            for (final String filter : filters)
 | 
			
		||||
                if (testCase.getIdentifier().startsWith( filter ))
 | 
			
		||||
                    return true;
 | 
			
		||||
            return false;
 | 
			
		||||
        } ).collect( Collectors.toList() );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Case getCase(final String identifier) {
 | 
			
		||||
@@ -65,6 +76,10 @@ public class MPTests {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean addFilters(final String... filters) {
 | 
			
		||||
        return this.filters.addAll( Arrays.asList( filters ) );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static class Case {
 | 
			
		||||
 | 
			
		||||
        String identifier;
 | 
			
		||||
 
 | 
			
		||||
@@ -39,6 +39,7 @@ public class MPMasterKeyTest {
 | 
			
		||||
            throws Exception {
 | 
			
		||||
 | 
			
		||||
        testSuite = new MPTestSuite();
 | 
			
		||||
        //testSuite.getTests().addFilters( "v0" );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
@@ -53,20 +54,20 @@ public class MPMasterKeyTest {
 | 
			
		||||
            assertEquals(
 | 
			
		||||
                    CodeUtils.encodeHex( masterKey.getKeyID( testCase.getAlgorithm() ) ),
 | 
			
		||||
                    testCase.getKeyID(),
 | 
			
		||||
                    "[testMasterKey] keyID mismatch: " + testCase );
 | 
			
		||||
                    "[testMasterKey] keyID mismatch for test case: " + testCase );
 | 
			
		||||
 | 
			
		||||
            // Test invalidation
 | 
			
		||||
            masterKey.invalidate();
 | 
			
		||||
            try {
 | 
			
		||||
                masterKey.getKeyID( testCase.getAlgorithm() );
 | 
			
		||||
                fail( "[testMasterKey] invalidate ineffective: " + testCase );
 | 
			
		||||
                fail( "[testMasterKey] invalidate ineffective for test case: " + testCase );
 | 
			
		||||
            }
 | 
			
		||||
            catch (final MPKeyUnavailableException ignored) {
 | 
			
		||||
            }
 | 
			
		||||
            assertNotEquals(
 | 
			
		||||
                    masterPassword,
 | 
			
		||||
                    testCase.getMasterPassword().toCharArray(),
 | 
			
		||||
                    "[testMasterKey] masterPassword not wiped: " + testCase );
 | 
			
		||||
                    "[testMasterKey] masterPassword not wiped for test case: " + testCase );
 | 
			
		||||
 | 
			
		||||
            return true;
 | 
			
		||||
        } );
 | 
			
		||||
@@ -87,7 +88,7 @@ public class MPMasterKeyTest {
 | 
			
		||||
                                          testCase.getKeyContext(), testCase.getResultType(),
 | 
			
		||||
                                          null ),
 | 
			
		||||
                    testCase.getResult(),
 | 
			
		||||
                    "[testSiteResult] result mismatch: " + testCase );
 | 
			
		||||
                    "[testSiteResult] result mismatch for test case: " + testCase );
 | 
			
		||||
 | 
			
		||||
            return true;
 | 
			
		||||
        } );
 | 
			
		||||
@@ -115,7 +116,7 @@ public class MPMasterKeyTest {
 | 
			
		||||
            assertEquals(
 | 
			
		||||
                    result,
 | 
			
		||||
                    password,
 | 
			
		||||
                    "[testSiteState] state mismatch: " + testCase );
 | 
			
		||||
                    "[testSiteState] state mismatch for test case: " + testCase );
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user