Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id D067C200BB1 for ; Wed, 19 Oct 2016 17:12:02 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id CF144160ADE; Wed, 19 Oct 2016 15:12:02 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 229E5160AEA for ; Wed, 19 Oct 2016 17:12:01 +0200 (CEST) Received: (qmail 46722 invoked by uid 500); 19 Oct 2016 15:12:01 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 46589 invoked by uid 99); 19 Oct 2016 15:12:01 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Oct 2016 15:12:01 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id EF891E35E8; Wed, 19 Oct 2016 15:12:00 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: erans@apache.org To: commits@commons.apache.org Date: Wed, 19 Oct 2016 15:12:01 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [2/2] commons-rng git commit: Unit tests. archived-at: Wed, 19 Oct 2016 15:12:03 -0000 Unit tests. Project: http://git-wip-us.apache.org/repos/asf/commons-rng/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-rng/commit/31392320 Tree: http://git-wip-us.apache.org/repos/asf/commons-rng/tree/31392320 Diff: http://git-wip-us.apache.org/repos/asf/commons-rng/diff/31392320 Branch: refs/heads/master Commit: 313923203cbd7a365dd03547f63cbd1cbe134efb Parents: a2ece1b Author: Gilles Authored: Wed Oct 19 16:57:42 2016 +0200 Committer: Gilles Committed: Wed Oct 19 16:57:42 2016 +0200 ---------------------------------------------------------------------- .../rng/ProvidersCommonParametricTest.java | 5 ++ .../commons/rng/internal/BaseProviderTest.java | 57 ++++++++++++++++++++ 2 files changed, 62 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-rng/blob/31392320/src/test/java/org/apache/commons/rng/ProvidersCommonParametricTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/rng/ProvidersCommonParametricTest.java b/src/test/java/org/apache/commons/rng/ProvidersCommonParametricTest.java index b997e34..c759600 100644 --- a/src/test/java/org/apache/commons/rng/ProvidersCommonParametricTest.java +++ b/src/test/java/org/apache/commons/rng/ProvidersCommonParametricTest.java @@ -407,6 +407,11 @@ public class ProvidersCommonParametricTest { ((RestorableUniformRandomProvider) generator).restoreState(state); } + @Test(expected=IllegalArgumentException.class) + public void testRestoreForeignState() { + ((RestorableUniformRandomProvider) generator).restoreState(new RandomProviderState() {}); + } + ///// Support methods below. http://git-wip-us.apache.org/repos/asf/commons-rng/blob/31392320/src/test/java/org/apache/commons/rng/internal/BaseProviderTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/rng/internal/BaseProviderTest.java b/src/test/java/org/apache/commons/rng/internal/BaseProviderTest.java new file mode 100644 index 0000000..a1e05c9 --- /dev/null +++ b/src/test/java/org/apache/commons/rng/internal/BaseProviderTest.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +package org.apache.commons.rng.internal; + +import org.junit.Test; + +import org.apache.commons.rng.RestorableUniformRandomProvider; +import org.apache.commons.rng.RandomSource; + +/** + * Tests for {@link BaseProvider}. + * + * This class should only contain unit tests that cover code paths not + * exercised elsewhere. Those code paths are most probably only taken + * in case of a wrong implementation (and would therefore fail other + * tests too). + */ +public class BaseProviderTest { + @Test(expected=UnsupportedOperationException.class) + public void testMissingGetStateInternal() { + final RestorableUniformRandomProvider rng = new DummyGenerator(); + rng.saveState(); + } + + @Test(expected=UnsupportedOperationException.class) + public void testMissingSetStateInternal() { + final RestorableUniformRandomProvider rng = new DummyGenerator(); + rng.restoreState(new RandomSource.State(new byte[1])); + } +} + +/** + * Dummy class for checking the behaviour of an incomplete implementation. + */ +class DummyGenerator extends org.apache.commons.rng.internal.source32.IntProvider { + /** {@inheritDoc} */ + @Override + public int next() { + return 4; // https://www.xkcd.com/221/ + } + + // Missing overrides of "setStateInternal" and "getStateInternal". +}