@@ -0,0 +1,3307 @@
+/*%0A * Yet Another UserAgent Analyzer%0A * Copyright (C) 2013-2018 Niels Basjes%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage nl.basjes.parse.useragent;%0A%0Aimport nl.basjes.parse.useragent.debug.UserAgentAnalyzerTester;%0Aimport org.junit.BeforeClass;%0Aimport org.junit.Test;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport java.io.ByteArrayInputStream;%0Aimport java.io.ByteArrayOutputStream;%0Aimport java.io.IOException;%0Aimport java.io.ObjectInput;%0Aimport java.io.ObjectInputStream;%0Aimport java.io.ObjectOutput;%0Aimport java.io.ObjectOutputStream;%0A%0Aimport static org.junit.Assert.assertTrue;%0A%0Apublic class TestSerializationFast %7B%0A%0A    private static final Logger LOG = LoggerFactory.getLogger(TestSerializationFast.class);%0A%0A    protected static UserAgentAnalyzerTester uaa;%0A%0A    @BeforeClass%0A    public static void serializeAndDeserializeUAA() throws IOException, ClassNotFoundException %7B%0A        LOG.info(%22==============================================================%22);%0A        LOG.info(%22Create%22);%0A        LOG.info(%22--------------------------------------------------------------%22);%0A        uaa = new UserAgentAnalyzerTester();%0A        uaa.setShowMatcherStats(false);%0A        uaa.delayInitialization();%0A        uaa.initialize();%0A%0A        LOG.info(%22--------------------------------------------------------------%22);%0A        LOG.info(%22Serialize%22);%0A        byte%5B%5D bytes;%0A        try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) %7B%0A            ObjectOutput out = new ObjectOutputStream(bos);%0A            out.writeObject(uaa);%0A            out.flush();%0A            bytes = bos.toByteArray();%0A        %7D%0A%0A        uaa = null;%0A%0A        LOG.info(%22The UserAgentAnalyzer was serialized into %7B%7D bytes%22, bytes.length);%0A        LOG.info(%22--------------------------------------------------------------%22);%0A        LOG.info(%22Deserialize%22);%0A        ByteArrayInputStream bis = new ByteArrayInputStream(bytes);%0A        ObjectInput in = null;%0A%0A        try %7B%0A            in = new ObjectInputStream(bis);%0A            Object o = in.readObject();%0A            if (!(o instanceof UserAgentAnalyzerTester)) %7B%0A                throw new IOException(%22This shouldn't happen...%22);%0A            %7D%0A            uaa = (UserAgentAnalyzerTester) o;%0A        %7D finally %7B%0A            if (in != null) %7B%0A                in.close();%0A            %7D%0A        %7D%0A        LOG.info(%22Done%22);%0A        LOG.info(%22==============================================================%22);%0A    %7D%0A%0A    @Test%0A    public void validateAllPredefinedBrowsers() %7B%0A        LOG.info(%22==============================================================%22);%0A        LOG.info(%22Validating when getting all fields%22);%0A        LOG.info(%22--------------------------------------------------------------%22);%0A        assertTrue(uaa.runTests(false, true));%0A    %7D%0A%0A%7D%0A

Test serialization with delayed init