Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/DMDirc/Parser
Browse files Browse the repository at this point in the history
  • Loading branch information
greboid committed Jul 31, 2016
2 parents 299589a + c29e9b9 commit b951ed4
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 5 deletions.
6 changes: 4 additions & 2 deletions irc/src/main/java/com/dmdirc/parser/irc/IRCParser.java
Expand Up @@ -59,8 +59,9 @@
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
Expand Down Expand Up @@ -1114,7 +1115,8 @@ protected void processLine(final ReadLine line) {
if (line.getTags().containsKey("tsirc date")) {
try {
final long ts = Long.parseLong(line.getTags().get("tsirc date")) - tsdiff;
lineTS = LocalDateTime.ofEpochSecond(ts / 1000L, (int) (ts % 1000L), ZoneOffset.UTC);
lineTS = LocalDateTime.ofInstant(Instant.ofEpochSecond(ts / 1000L, (int) (ts % 1000L)),
ZoneId.systemDefault());
} catch (final NumberFormatException nfe) { /* Do nothing. */ }
} else if (line.getTags().containsKey("time")) {
try {
Expand Down
@@ -0,0 +1,76 @@
/*
* Copyright (c) 2006-2016 DMDirc Developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package com.dmdirc.parser.irc.outputqueue;

import com.dmdirc.parser.common.QueuePriority;
import org.junit.Before;
import org.junit.Test;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;

import static org.junit.Assert.assertEquals;

public class PriorityOutputQueueTest {

private BufferedReader reader;
private BufferedOutputStream outputStream;
private PriorityOutputQueue outputQueue;

@Before
public void setup() throws IOException {
PipedInputStream pipeInput = new PipedInputStream();
reader = new BufferedReader(new InputStreamReader(pipeInput));
outputStream = new BufferedOutputStream(new PipedOutputStream(pipeInput));
outputQueue = new PriorityOutputQueue();
}

@Test(expected = IllegalStateException.class)
public void testThrowsIfOutputStreamNotSet() {
outputQueue.sendLine("testing", QueuePriority.IMMEDIATE);
}

@Test
public void testSendsLinesToOutput() throws IOException {
outputQueue.setOutputStream(outputStream);
outputQueue.sendLine("test 123");
outputQueue.sendLine("456...");
assertEquals("test 123", reader.readLine());
assertEquals("456...", reader.readLine());
}

@Test
public void testDiscarding() throws IOException {
outputQueue.setOutputStream(outputStream);
outputQueue.setDiscarding(true);
outputQueue.sendLine("test 123");
outputQueue.setDiscarding(false);
outputQueue.sendLine("456...");
assertEquals("456...", reader.readLine());
}

}
Expand Up @@ -26,9 +26,7 @@
import com.dmdirc.parser.irc.IRCClientInfo;
import com.dmdirc.parser.irc.IRCParser;
import com.dmdirc.parser.irc.ProcessingManager;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
Expand All @@ -49,7 +47,6 @@
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
@Ignore
public class Process001Test {

@Mock private IRCParser parser;
Expand Down

0 comments on commit b951ed4

Please sign in to comment.