Java tutorial
/* * This file is part of ChangePurse. * * Copyright (c) 2014 Germn Fuentes Capella * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ package bit.changepurse.wdk.bip; import static bit.changepurse.wdk.util.CheckedExceptionMethods.newURI; import static bit.changepurse.wdk.util.CheckedExceptionMethods.readTextFile; import java.net.URL; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONObject; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; @RunWith(value = Parameterized.class) public class TestBip39EN extends TestBip39 { private static final String TEST_VECTORS = "bip39_test_vectors.json"; private static final String TEST_PASSPHRASE = "TREZOR"; public TestBip39EN(String anInitialSeed, String aMnemonic, String anExpectedSeed, String passphrase, Bip39Dict dict) { super(anInitialSeed, aMnemonic, anExpectedSeed, passphrase, dict); } public static String readTestVectors() { URL resource = TestBip39EN.class.getResource(TEST_VECTORS); Path path = Paths.get(newURI(resource)); return readTextFile(path); } @Parameters public static List<Object[]> data() { JSONObject json = new JSONObject(readTestVectors()); JSONArray englishContent = json.getJSONArray("english"); List<Object[]> tests = new ArrayList<Object[]>(); for (int i = 0; i < englishContent.length(); i++) { JSONArray test = englishContent.getJSONArray(i); tests.add(new Object[] { test.getString(0), test.getString(1), test.getString(2), TEST_PASSPHRASE, Bip39Dict.EN }); } return tests; } }