/*
 * Copyright 2014, 2015 Thomas Harning Jr. <harningt@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import com.google.common.io.BaseEncoding;
import org.junit.Test;
import us.eharning.atomun.mnemonic.MnemonicAlgorithm;
import us.eharning.atomun.mnemonic.MnemonicBuilder;
import us.eharning.atomun.mnemonic.MnemonicDecoder;
import us.eharning.atomun.mnemonic.MnemonicUnit;

/**
 * Sample wrapped as a test that will generate a mnemonic and derive a
 * seed from each of these.
 */
public class MnemonicSample {
    @Test
    public void generateSamples() {
        for (MnemonicAlgorithm algorithm: MnemonicAlgorithm.values()) {
            /* Obtain a builder for the selected algorithm. */
            MnemonicBuilder builder = MnemonicBuilder.newBuilder(algorithm);

            /* Set the entropy length at 128-bits -> 16 bytes. */
            builder.setEntropyLength(128 / 8);

            /* Generate a mnemonic with the remaining parameters as the default. */
            String mnemonic = builder.build();

            /* Decode the mnemonic into a stateful unit to operate on. */
            MnemonicUnit unit = MnemonicDecoder.decodeMnemonic(algorithm, mnemonic);

            /* Extract a seed out of the mnemonic unit. */
            byte[] seed = unit.getSeed();

            System.out.println(algorithm);
            System.out.println("\t" + mnemonic);
            System.out.println("\t" + BaseEncoding.base16().encode(seed));
        }
    }
}

@@ -1532,24 +1532,138 @@
 r.build();%0A%0A
+            System.out.println(algorithm);%0A            System.out.println(%22%5Ct%22 + mnemonic);%0A            try %7B%0A    
             
@@ -1728,32 +1728,36 @@
  */%0A            
+   
+ 
 MnemonicUnit uni
@@ -1826,16 +1826,20 @@
         
+    
 /* Extra
@@ -1873,24 +1873,28 @@
 ic unit. */%0A
+    
             
@@ -1928,32 +1928,36 @@
 );%0A%0A            
+    
 System.out.print
@@ -1963,143 +1963,183 @@
 tln(
-algorithm);%0A            System.out.println(%22%5Ct%22 + mnemonic);%0A            System.out.println(%22%5Ct%22 + BaseEncoding.base16().encode(seed));
+%22%5Ct%22 + BaseEncoding.base16().encode(seed));%0A            %7D catch (UnsupportedOperationException e) %7B%0A                System.out.println(%22%5CtSeed handling failed%22);%0A            %7D
 %0A   

fix the sample test to workaround partial mnemonic implementation where encoding exists, but perhaps not decoding