You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by fs...@apache.org on 2017/07/23 13:58:21 UTC
svn commit: r1802725 - in /jmeter/trunk:
src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java
test/src/org/apache/jmeter/threads/TestUnmodifiableJMeterVariables.java
Author: fschumacher
Date: Sun Jul 23 13:58:21 2017
New Revision: 1802725
URL: http://svn.apache.org/viewvc?rev=1802725&view=rev
Log:
Tests for UnmodifiableJMeterVariables
Added:
jmeter/trunk/test/src/org/apache/jmeter/threads/TestUnmodifiableJMeterVariables.java (with props)
Modified:
jmeter/trunk/src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java
Modified: jmeter/trunk/src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java?rev=1802725&r1=1802724&r2=1802725&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java Sun Jul 23 13:58:21 2017
@@ -46,6 +46,7 @@ class UnmodifiableJMeterVariables extend
* @return
* @see org.apache.jmeter.threads.JMeterVariables#getThreadName()
*/
+ @Override
public String getThreadName() {
return variables.getThreadName();
}
@@ -53,6 +54,7 @@ class UnmodifiableJMeterVariables extend
* @return
* @see org.apache.jmeter.threads.JMeterVariables#getIteration()
*/
+ @Override
public int getIteration() {
return variables.getIteration();
}
@@ -60,6 +62,7 @@ class UnmodifiableJMeterVariables extend
*
* @see org.apache.jmeter.threads.JMeterVariables#incIteration()
*/
+ @Override
public void incIteration() {
throw new UnsupportedOperationException();
}
@@ -68,6 +71,7 @@ class UnmodifiableJMeterVariables extend
* @return
* @see org.apache.jmeter.threads.JMeterVariables#remove(java.lang.String)
*/
+ @Override
public Object remove(String key) {
throw new UnsupportedOperationException();
}
@@ -76,6 +80,7 @@ class UnmodifiableJMeterVariables extend
* @param value
* @see org.apache.jmeter.threads.JMeterVariables#put(java.lang.String, java.lang.String)
*/
+ @Override
public void put(String key, String value) {
throw new UnsupportedOperationException();
}
@@ -84,6 +89,7 @@ class UnmodifiableJMeterVariables extend
* @param value
* @see org.apache.jmeter.threads.JMeterVariables#putObject(java.lang.String, java.lang.Object)
*/
+ @Override
public void putObject(String key, Object value) {
throw new UnsupportedOperationException();
}
@@ -91,6 +97,7 @@ class UnmodifiableJMeterVariables extend
* @param vars
* @see org.apache.jmeter.threads.JMeterVariables#putAll(java.util.Map)
*/
+ @Override
public void putAll(Map<String, ?> vars) {
throw new UnsupportedOperationException();
}
@@ -98,6 +105,7 @@ class UnmodifiableJMeterVariables extend
* @param vars
* @see org.apache.jmeter.threads.JMeterVariables#putAll(org.apache.jmeter.threads.JMeterVariables)
*/
+ @Override
public void putAll(JMeterVariables vars) {
throw new UnsupportedOperationException();
}
@@ -106,6 +114,7 @@ class UnmodifiableJMeterVariables extend
* @return
* @see org.apache.jmeter.threads.JMeterVariables#get(java.lang.String)
*/
+ @Override
public String get(String key) {
return variables.get(key);
}
@@ -122,6 +131,7 @@ class UnmodifiableJMeterVariables extend
* @return
* @see org.apache.jmeter.threads.JMeterVariables#getObject(java.lang.String)
*/
+ @Override
public Object getObject(String key) {
return variables.getObject(key);
}
@@ -129,6 +139,7 @@ class UnmodifiableJMeterVariables extend
* @return
* @see org.apache.jmeter.threads.JMeterVariables#getIterator()
*/
+ @Override
public Iterator<Entry<String, Object>> getIterator() {
return variables.getIterator();
}
@@ -136,6 +147,7 @@ class UnmodifiableJMeterVariables extend
* @return
* @see org.apache.jmeter.threads.JMeterVariables#entrySet()
*/
+ @Override
public Set<Entry<String, Object>> entrySet() {
return variables.entrySet();
}
Added: jmeter/trunk/test/src/org/apache/jmeter/threads/TestUnmodifiableJMeterVariables.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/threads/TestUnmodifiableJMeterVariables.java?rev=1802725&view=auto
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/threads/TestUnmodifiableJMeterVariables.java (added)
+++ jmeter/trunk/test/src/org/apache/jmeter/threads/TestUnmodifiableJMeterVariables.java Sun Jul 23 13:58:21 2017
@@ -0,0 +1,135 @@
+/*
+ * 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.jmeter.threads;
+
+import static org.junit.Assert.assertThat;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.hamcrest.CoreMatchers;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestUnmodifiableJMeterVariables {
+
+ private static final String MY_OBJECT_KEY = "my.objectKey";
+ private static final String MY_KEY = "my.key";
+ private JMeterVariables vars;
+ private UnmodifiableJMeterVariables unmodifiables;
+
+ @Before
+ public void setUp() {
+ vars = new JMeterVariables();
+ vars.put(MY_KEY, "something to test for");
+ vars.putObject(MY_OBJECT_KEY, new Object());
+ unmodifiables = new UnmodifiableJMeterVariables(vars);
+ }
+
+ @Test
+ public void testGetThreadName() {
+ assertThat(unmodifiables.getThreadName(), CoreMatchers.is(vars.getThreadName()));
+ }
+
+ @Test
+ public void testGetIteration() {
+ assertThat(unmodifiables.getIteration(), CoreMatchers.is(vars.getIteration()));
+ }
+
+ @Test(expected=UnsupportedOperationException.class)
+ public void testIncIteration() {
+ unmodifiables.incIteration();
+ }
+
+ @Test(expected=UnsupportedOperationException.class)
+ public void testRemove() {
+ unmodifiables.remove("some.key");
+ }
+
+ @Test(expected=UnsupportedOperationException.class)
+ public void testPut() {
+ unmodifiables.put("some.key", "anything");
+ }
+
+ @Test(expected=UnsupportedOperationException.class)
+ public void testPutObject() {
+ unmodifiables.putObject("some.key", new Object());
+ }
+
+ @Test(expected=UnsupportedOperationException.class)
+ public void testPutAllMapOfStringQ() {
+ unmodifiables.putAll(Collections.emptyMap());;
+ }
+
+ @Test(expected=UnsupportedOperationException.class)
+ public void testPutAllJMeterVariables() {
+ unmodifiables.putAll(vars);
+ }
+
+ @Test
+ public void testGet() {
+ assertThat(unmodifiables.get(MY_KEY), CoreMatchers.is(vars.get(MY_KEY)));
+ }
+
+ @Test
+ public void testGetObject() {
+ assertThat(unmodifiables.getObject(MY_OBJECT_KEY), CoreMatchers.is(vars.getObject(MY_OBJECT_KEY)));
+ }
+
+ @Test(expected=UnsupportedOperationException.class)
+ public void testGetIteratorIsUnmodifable() {
+ Iterator<Entry<String, Object>> iterator = unmodifiables.getIterator();
+ assertThat(iterator.hasNext(), CoreMatchers.is(true));
+ iterator.next();
+ iterator.remove();
+ }
+
+ @Test
+ public void testGetIterator() {
+ assertThat(iteratorToMap(unmodifiables.getIterator()), CoreMatchers.is(iteratorToMap(vars.getIterator())));
+ }
+
+ private <K,V> Map<K, V>iteratorToMap(Iterator<Entry<K, V>> it) {
+ Map<K,V> result = new HashMap<>();
+ while (it.hasNext()) {
+ Entry<K, V> entry = it.next();
+ result.put(entry.getKey(), entry.getValue());
+ }
+ return result;
+ }
+
+ @Test
+ public void testEntrySet() {
+ assertThat(unmodifiables.entrySet(), CoreMatchers.is(vars.entrySet()));
+ }
+
+ @Test
+ public void testEqualsObject() {
+ assertThat(unmodifiables, CoreMatchers.is(vars));
+ }
+
+ @Test
+ public void testHashCode() {
+ assertThat(unmodifiables.hashCode(), CoreMatchers.is(vars.hashCode()));
+ }
+
+}
Propchange: jmeter/trunk/test/src/org/apache/jmeter/threads/TestUnmodifiableJMeterVariables.java
------------------------------------------------------------------------------
svn:eol-style = native