This is an automated email from the ASF dual-hosted git repository. jtulach pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-netbeans-html4j.git
commit 4da1644d2d8262506cf9a94157d49b2d7690ec49 Author: Jaroslav Tulach <[email protected]> AuthorDate: Thu Feb 14 18:30:36 2019 +0100 Testing behavior of MapObjs support --- .../main/java/org/netbeans/html/ko4j/MapObjs.java | 35 +++++---- .../java/org/netbeans/html/ko4j/MapObjsTest.java | 84 ++++++++++++++++++++++ 2 files changed, 106 insertions(+), 13 deletions(-) diff --git a/ko4j/src/main/java/org/netbeans/html/ko4j/MapObjs.java b/ko4j/src/main/java/org/netbeans/html/ko4j/MapObjs.java index 672710a..1f3a998 100644 --- a/ko4j/src/main/java/org/netbeans/html/ko4j/MapObjs.java +++ b/ko4j/src/main/java/org/netbeans/html/ko4j/MapObjs.java @@ -24,8 +24,17 @@ import net.java.html.json.Models; import org.netbeans.html.boot.spi.Fn; final class MapObjs { - private static final Object UNINITIALIZED = new Object(); - private static Object onlyPresenter = UNINITIALIZED; + private static Object onlyPresenter; + private static boolean usePresenter; + + static { + reset(); + } + + static void reset() { + onlyPresenter = null; + usePresenter = true; + } private final List<Object> all; @@ -38,21 +47,21 @@ final class MapObjs { if (now instanceof MapObjs) { return ((MapObjs)now).put(key, js); } else { - if (onlyPresenter == UNINITIALIZED) { - onlyPresenter = key; - return js; - } else if (onlyPresenter == key) { - return js; - } else { + if (usePresenter) { if (onlyPresenter == null) { - assert now == null; - return new MapObjs(key, js); + onlyPresenter = key; + return js; + } else if (onlyPresenter == key) { + return js; } else { - final MapObjs map = new MapObjs(onlyPresenter, now, key, js); - onlyPresenter = null; - return map; + usePresenter = false; } } + if (now == null) { + return new MapObjs(key, js); + } else { + return new MapObjs(onlyPresenter, now, key, js); + } } } diff --git a/ko4j/src/test/java/org/netbeans/html/ko4j/MapObjsTest.java b/ko4j/src/test/java/org/netbeans/html/ko4j/MapObjsTest.java new file mode 100644 index 0000000..43c5c18 --- /dev/null +++ b/ko4j/src/test/java/org/netbeans/html/ko4j/MapObjsTest.java @@ -0,0 +1,84 @@ +/** + * 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.netbeans.html.ko4j; + +import java.io.Reader; +import java.net.URL; +import org.netbeans.html.boot.spi.Fn; +import static org.testng.Assert.*; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +public class MapObjsTest { + + private Pres p1; + private Pres p2; + + public MapObjsTest() { + } + + @BeforeMethod + public void setUpClass() throws Exception { + MapObjs.reset(); + p1 = new Pres(); + p2 = new Pres(); + } + + @Test + public void testValuesForP1P2() { + Value v1 = new Value(); + Value v2 = new Value(); + + v1.put(p1, "p1"); + v2.put(p1, "p1"); + v1.put(p2, "p2"); + + assertEquals(v1.get(p1), "p1"); + assertEquals(v2.get(p1), "p1"); + assertEquals(v1.get(p2), "p2"); + assertEquals(v2.get(p2), null); + } + + private static final class Value { + private Object now; + + void put(Fn.Presenter p, Object v) { + now = MapObjs.put(now, p, v); + } + + Object get(Fn.Presenter p) { + return MapObjs.get(now, p); + } + } + + private static final class Pres implements Fn.Presenter { + @Override + public Fn defineFn(String code, String... names) { + return null; + } + + @Override + public void displayPage(URL page, Runnable onPageLoad) { + } + + @Override + public void loadScript(Reader code) throws Exception { + } + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
