Java tutorial
package com.vitesify.languidmpd.streams; /* * TestMPDStream * Copyright (C) 2014 Christopher Nelson <christopher.nelson@cavein.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ import static org.junit.Assert.assertTrue; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.StringReader; import java.nio.charset.Charset; import java.util.Collections; import java.util.Set; import org.apache.commons.io.input.ReaderInputStream; import org.apache.commons.io.output.NullOutputStream; import org.junit.Test; import com.vitesify.languidmpd.streams.MPDStreamProcesser.Message; public class TestMPDStreamProcessor { @Test public void test_send_single_command() throws IOException { InputStream is = new ReaderInputStream(new StringReader("OK\nOK\nNOT OK\nOK"), Charset.forName("UTF-8")); OutputStream os = new NullOutputStream(); MPDStreamProcesser mpdsp = new MPDStreamProcesser(is, os); Set<String> s = Collections.emptySet(); assertTrue(mpdsp.send_command(Message.STATUS, s)); assertTrue(mpdsp.last_command_succeeded()); assertTrue(mpdsp.get_return_code().endsWith("NOT OK\n")); } }