@Test public void checkBusesValues() { assertTrue(BusesValidation.checkBuses("test", loadP, loadQ, genP, genQ, shuntP, shuntQ, svcP, svcQ, vscCSP, vscCSQ, lineP, lineQ, twtP, twtQ, tltP, tltQ, looseConfig, NullWriter.NULL_WRITER)); assertFalse(BusesValidation.checkBuses("test", loadP, loadQ, genP, genQ, shuntP, shuntQ, svcP, svcQ, vscCSP, vscCSQ, lineP, lineQ, twtP, twtQ, tltP, tltQ, strictConfig, NullWriter.NULL_WRITER)); assertFalse(BusesValidation.checkBuses("test", loadP, 174.4932f, genP, genQ, shuntP, shuntQ, svcP, svcQ, vscCSP, vscCSQ, lineP, lineQ, twtP, twtQ, tltP, tltQ, looseConfig, NullWriter.NULL_WRITER)); // check NaN values assertFalse(BusesValidation.checkBuses("test", Double.NaN, loadQ, genP, genQ, shuntP, shuntQ, svcP, svcQ, vscCSP, vscCSQ, lineP, lineQ, twtP, twtQ, tltP, tltQ, looseConfig, NullWriter.NULL_WRITER)); assertFalse(BusesValidation.checkBuses("test", loadP, loadQ, genP, genQ, shuntP, shuntQ, svcP, svcQ, vscCSP, vscCSQ, lineP, lineQ, twtP, Double.NaN, tltP, tltQ, looseConfig, NullWriter.NULL_WRITER)); looseConfig.setOkMissingValues(true); assertTrue(BusesValidation.checkBuses("test", Double.NaN, loadQ, genP, genQ, shuntP, shuntQ, svcP, svcQ, vscCSP, vscCSQ, lineP, lineQ, twtP, twtQ, tltP, tltQ, looseConfig, NullWriter.NULL_WRITER)); assertTrue(BusesValidation.checkBuses("test", loadP, loadQ, genP, genQ, shuntP, shuntQ, svcP, svcQ, vscCSP, vscCSQ, lineP, lineQ, twtP, Double.NaN, tltP, tltQ, looseConfig, NullWriter.NULL_WRITER)); looseConfig.setOkMissingValues(false); }
@Test public void checkShuntsValues() { // “p” is always NaN assertTrue(ShuntCompensatorsValidation.checkShunts("test", p, q, currentSectionCount, maximumSectionCount, bPerSection, v, qMax, nominalV, strictConfig, NullWriter.NULL_WRITER)); p = 1f; assertFalse(ShuntCompensatorsValidation.checkShunts("test", p, q, currentSectionCount, maximumSectionCount, bPerSection, v, qMax, nominalV, strictConfig, NullWriter.NULL_WRITER)); p = Float.NaN; // “q” = - bPerSection * currentSectionCount * v^2 assertTrue(ShuntCompensatorsValidation.checkShunts("test", p, q, currentSectionCount, maximumSectionCount, bPerSection, v, qMax, nominalV, strictConfig, NullWriter.NULL_WRITER)); q = 170.52f; assertFalse(ShuntCompensatorsValidation.checkShunts("test", p, q, currentSectionCount, maximumSectionCount, bPerSection, v, qMax, nominalV, strictConfig, NullWriter.NULL_WRITER)); assertTrue(ShuntCompensatorsValidation.checkShunts("test", p, q, currentSectionCount, maximumSectionCount, bPerSection, v, qMax, nominalV, looseConfig, NullWriter.NULL_WRITER)); q = 171.52f; assertFalse(ShuntCompensatorsValidation.checkShunts("test", p, q, currentSectionCount, maximumSectionCount, bPerSection, v, qMax, nominalV, looseConfig, NullWriter.NULL_WRITER)); q = 170.50537f; // check with NaN values assertFalse(ShuntCompensatorsValidation.checkShunts("test", p, q, currentSectionCount, maximumSectionCount, Float.NaN, v, qMax, nominalV, strictConfig, NullWriter.NULL_WRITER)); assertFalse(ShuntCompensatorsValidation.checkShunts("test", p, q, currentSectionCount, maximumSectionCount, bPerSection, Float.NaN, qMax, nominalV, strictConfig, NullWriter.NULL_WRITER)); strictConfig.setOkMissingValues(true); assertTrue(ShuntCompensatorsValidation.checkShunts("test", p, q, currentSectionCount, maximumSectionCount, Float.NaN, v, qMax, nominalV, strictConfig, NullWriter.NULL_WRITER)); assertTrue(ShuntCompensatorsValidation.checkShunts("test", p, q, currentSectionCount, maximumSectionCount, bPerSection, Float.NaN, qMax, nominalV, strictConfig, NullWriter.NULL_WRITER)); }
@Override public Object visitRule(VtlRule rule) throws VilException { net.ssehub.easy.instantiation.core.model.templateModel.ITracer tracer = TracerFactory.createTemplateLanguageTracer(); TracerFactory.registerTemplateLanguageTracer(tracer); Writer writer = new NullWriter(); // not for reuse Map<String, Object> localParam = new HashMap<String, Object>(); // by default localParam.put(PARAM_CONFIG, environment.getTopLevelConfiguration()); localParam.put(PARAM_TARGET, null); // for now TemplateLangExecution exec = new TemplateLangExecution(tracer, writer, localParam); Def def = rule.getDef(); Template template = (Template) def.getParent(); exec.getRuntimeEnvironment().switchContext(template); exec.visitModelHeader(template); Object result = def.accept(exec); TracerFactory.unregisterTemplateLanguageTracer(tracer); return result; }
/** * Creates a reference FASTA file writer. * <p> * You can specify a specific path for the index and dictionary file. If either set to {@code null} such * a file won't be generated. * </p> * * @param fastaFile the output fasta file path. * @param indexFile the path of the index file, if requested, {@code null} if none should be generated. * @param dictFile the path of the dictFile, if requested, {@code null} if nono should be generated. * @throws IllegalArgumentException if {@code fastaFile} is {@code null} or {@code basesPerLine} is 0 or negative. * @throws IOException if such exception is thrown when accessing the output path resources. */ public FastaReferenceWriter(final Path fastaFile, final int basesPerLine, final Path indexFile, final Path dictFile) throws IOException { // This code is a slight repeat of {@link #FastaReferenceWriter(OutputStream,int,OutputStream,OutputStream) // for the sake of avoiding creating output if basesPerLine is invalid. this.defaultBasePerLine = checkBasesPerLine(basesPerLine); this.fastaStream = new CountingOutputStream(Files.newOutputStream(Utils.nonNull(fastaFile))); this.indexWriter = indexFile == null ? new NullWriter() : new OutputStreamWriter(Files.newOutputStream(indexFile), CHARSET); final BufferedWriter dictWriter = new BufferedWriter(dictFile == null ? new NullWriter() : new OutputStreamWriter(Files.newOutputStream(dictFile), CHARSET)); this.dictWriter = dictWriter; this.dictCodec = new SAMSequenceDictionaryCodec(dictWriter); this.dictCodec.encodeHeaderLine(false); this.sequenceNamesAndSizes = new LinkedHashMap<>(); }
@Test public void testSuccess() throws UnsupportedEncodingException, IOException { final AppStatus appStatus = new AppStatus(); final StatusWebHandler statusWeb = new StatusWebHandler(); statusWeb.setAppStatus(appStatus); statusWeb.setApplicationName("test"); final Map<String, IPage> pages = new HashMap<String, IPage>(); final StatusPage page = new StatusPage(); pages.put(page.getId(), page); statusWeb.setPages(pages); statusWeb.init(); final HttpServletRequest servlet = mock(HttpServletRequest.class); final HttpServletRequest request = mock(HttpServletRequest.class); final HttpServletResponse response = mock(HttpServletResponse.class); final StubServletOutputStream sos = new StubServletOutputStream(); when(response.getWriter()).thenReturn(new PrintWriter(new NullWriter())); when(response.getOutputStream()).thenReturn(sos); page.doGet(statusWeb, request, response); verify(response).setStatus(200); }
private void processSourceFile(VelocityEngine engine, VelocityContext context, File sourceFile, boolean shouldWriteOutput) { final Template sourceTemplate; try { final String relativeFileName = configuration .calculateRelativeSourceFileName(sourceFile); sourceTemplate = engine.getTemplate(relativeFileName, "UTF-8"); final StringWriter sw = shouldWriteOutput ? new StringWriter() : null; final NullWriter nw = shouldWriteOutput ? null : new NullWriter(); final Writer w = shouldWriteOutput ? sw : nw; sourceTemplate.merge(context, w); if (shouldWriteOutput) { String content = sw.toString(); sw.close(); File file = new File(configuration.getTargetDirectoryName() + "/" + relativeFileName); writer.write(file, content, "UTF-8"); } else { nw.close(); } } catch (Exception e) { LOG.error("", e); } }
@Test public void checkWarnings() { schemaRule.generate(schema, "com.example", config); schemaRule.compile(compiler, new NullWriter(), new ArrayList<File>(), config); List<Diagnostic<? extends JavaFileObject>> warnings = warnings(schemaRule.getDiagnostics()); assertThat(warnings, matcher); }
@Test public void checkSvcs() { // active power should be equal to 0 assertTrue(StaticVarCompensatorsValidation.checkSVCs(svc, strictConfig, NullWriter.NULL_WRITER)); Mockito.when(svcTerminal.getP()).thenReturn(-39.8f); assertFalse(StaticVarCompensatorsValidation.checkSVCs(svc, strictConfig, NullWriter.NULL_WRITER)); // the unit is disconnected Mockito.when(svcBusView.getBus()).thenReturn(null); assertTrue(StaticVarCompensatorsValidation.checkSVCs(svc, strictConfig, NullWriter.NULL_WRITER)); }
@Test public void checkNetworkSvcs() { Network network = Mockito.mock(Network.class); Mockito.when(network.getId()).thenReturn("network"); Mockito.when(network.getStaticVarCompensatorStream()).thenAnswer(dummy -> Stream.of(svc)); assertTrue(StaticVarCompensatorsValidation.checkSVCs(network, looseConfig, NullWriter.NULL_WRITER)); }
@Test public void checkNetworkGenerators() { Network.BusView networkBusView = Mockito.mock(Network.BusView.class); Mockito.when(networkBusView.getBusStream()).thenAnswer(dummy -> Stream.of(bus)); Network network = Mockito.mock(Network.class); Mockito.when(network.getId()).thenReturn("network"); Mockito.when(network.getBusView()).thenReturn(networkBusView); assertTrue(BusesValidation.checkBuses(network, looseConfig, NullWriter.NULL_WRITER)); assertFalse(BusesValidation.checkBuses(network, strictConfig, NullWriter.NULL_WRITER)); }
@Test public void checkGenerators() { // active power should be equal to setpoint assertTrue(GeneratorsValidation.checkGenerators(generator, strictConfig, NullWriter.NULL_WRITER)); Mockito.when(genTerminal.getP()).thenReturn(-39.8f); assertFalse(GeneratorsValidation.checkGenerators(generator, strictConfig, NullWriter.NULL_WRITER)); // the unit is disconnected Mockito.when(genBusView.getBus()).thenReturn(null); assertTrue(GeneratorsValidation.checkGenerators(generator, strictConfig, NullWriter.NULL_WRITER)); }
@Test public void checkNetworkGenerators() { Bus genBus1 = Mockito.mock(Bus.class); Mockito.when(genBus1.getV()).thenReturn(v); BusView genBusView1 = Mockito.mock(BusView.class); Mockito.when(genBusView1.getBus()).thenReturn(genBus1); Terminal genTerminal1 = Mockito.mock(Terminal.class); Mockito.when(genTerminal1.getP()).thenReturn(p); Mockito.when(genTerminal1.getQ()).thenReturn(q); Mockito.when(genTerminal1.getBusView()).thenReturn(genBusView1); ReactiveLimits genReactiveLimits1 = Mockito.mock(ReactiveLimits.class); Mockito.when(genReactiveLimits1.getMinQ(Mockito.anyFloat())).thenReturn(minQ); Mockito.when(genReactiveLimits1.getMaxQ(Mockito.anyFloat())).thenReturn(maxQ); Generator generator1 = Mockito.mock(Generator.class); Mockito.when(generator1.getId()).thenReturn("gen"); Mockito.when(generator1.getTerminal()).thenReturn(genTerminal1); Mockito.when(generator1.getTargetP()).thenReturn(targetP); Mockito.when(generator1.getTargetQ()).thenReturn(targetQ); Mockito.when(generator1.getTargetV()).thenReturn(targetV); Mockito.when(generator1.getReactiveLimits()).thenReturn(genReactiveLimits1); assertTrue(GeneratorsValidation.checkGenerators(generator1, strictConfig, NullWriter.NULL_WRITER)); Network network = Mockito.mock(Network.class); Mockito.when(network.getId()).thenReturn("network"); Mockito.when(network.getGeneratorStream()).thenAnswer(dummy -> Stream.of(generator, generator1)); assertTrue(GeneratorsValidation.checkGenerators(network, looseConfig, NullWriter.NULL_WRITER)); }
@Test public void checkShunts() { // “q” = - bPerSection * currentSectionCount * v^2 assertTrue(ShuntCompensatorsValidation.checkShunts(shunt, strictConfig, NullWriter.NULL_WRITER)); Mockito.when(shuntTerminal.getQ()).thenReturn(171.52f); assertFalse(ShuntCompensatorsValidation.checkShunts(shunt, strictConfig, NullWriter.NULL_WRITER)); // if the shunt is disconnected then either “q” is not defined or “q” is 0 Mockito.when(shuntBusView.getBus()).thenReturn(null); assertFalse(ShuntCompensatorsValidation.checkShunts(shunt, strictConfig, NullWriter.NULL_WRITER)); Mockito.when(shuntTerminal.getQ()).thenReturn(Float.NaN); assertTrue(ShuntCompensatorsValidation.checkShunts(shunt, strictConfig, NullWriter.NULL_WRITER)); }
@Test public void checkNetworkShunts() { Network network = Mockito.mock(Network.class); Mockito.when(network.getId()).thenReturn("network"); Mockito.when(network.getShuntStream()).thenAnswer(dummy -> Stream.of(shunt)); assertTrue(ShuntCompensatorsValidation.checkShunts(network, strictConfig, NullWriter.NULL_WRITER)); }
@Test public void checkLineFlows() { assertTrue(FlowsValidation.checkFlows(line1, looseConfig, NullWriter.NULL_WRITER)); assertFalse(FlowsValidation.checkFlows(line1, strictConfig, NullWriter.NULL_WRITER)); Mockito.when(bus1.isInMainConnectedComponent()).thenReturn(false); Mockito.when(bus2.isInMainConnectedComponent()).thenReturn(false); assertTrue(FlowsValidation.checkFlows(line1, strictConfig, NullWriter.NULL_WRITER)); }
@Test public void checkTransformerFlows() { assertTrue(FlowsValidation.checkFlows(transformer1, looseConfig, NullWriter.NULL_WRITER)); assertFalse(FlowsValidation.checkFlows(transformer1, strictConfig, NullWriter.NULL_WRITER)); Mockito.when(bus1.isInMainConnectedComponent()).thenReturn(false); Mockito.when(bus2.isInMainConnectedComponent()).thenReturn(false); assertTrue(FlowsValidation.checkFlows(transformer1, strictConfig, NullWriter.NULL_WRITER)); }
@Test public void checkNetworkFlows() { Line line2 = Mockito.mock(Line.class); Mockito.when(line2.getId()).thenReturn("line2"); Mockito.when(line2.getTerminal1()).thenReturn(terminal1); Mockito.when(line2.getTerminal2()).thenReturn(terminal2); Mockito.when(line2.getR()).thenReturn((float) r); Mockito.when(line2.getX()).thenReturn((float) x); Mockito.when(line2.getG1()).thenReturn((float) g1); Mockito.when(line2.getG2()).thenReturn((float) g2); Mockito.when(line2.getB1()).thenReturn((float) b1); Mockito.when(line2.getB2()).thenReturn((float) b2); TwoWindingsTransformer transformer2 = Mockito.mock(TwoWindingsTransformer.class); Mockito.when(transformer2.getId()).thenReturn("transformer2"); Mockito.when(transformer2.getTerminal1()).thenReturn(terminal1); Mockito.when(transformer2.getTerminal2()).thenReturn(terminal2); Mockito.when(transformer2.getR()).thenReturn((float) (r * (1 - r / 100))); Mockito.when(transformer2.getX()).thenReturn((float) (x * (1 - x / 100))); Mockito.when(transformer2.getG()).thenReturn((float) (g1 * (1 - g1 / 100))); Mockito.when(transformer2.getB()).thenReturn((float) (b1 * 2 * (1 - b1 / 100))); Mockito.when(transformer2.getRatioTapChanger()).thenReturn(ratioTapChanger); Mockito.when(transformer2.getRatedU1()).thenReturn((float) ratedU1); Mockito.when(transformer2.getRatedU2()).thenReturn((float) ratedU2); assertTrue(FlowsValidation.checkFlows(transformer2, looseConfig, NullWriter.NULL_WRITER)); assertFalse(FlowsValidation.checkFlows(transformer2, strictConfig, NullWriter.NULL_WRITER)); Network network = Mockito.mock(Network.class); Mockito.when(network.getId()).thenReturn("network"); Mockito.when(network.getLineStream()).thenAnswer(dummy -> Stream.of(line2, line1)); Mockito.when(network.getTwoWindingsTransformerStream()).thenAnswer(dummy -> Stream.of(transformer2, transformer1)); assertTrue(FlowsValidation.checkFlows(network, looseConfig, NullWriter.NULL_WRITER)); assertFalse(FlowsValidation.checkFlows(network, strictConfig, NullWriter.NULL_WRITER)); }
/** * Test method for * {@link com.github.ansell.csv.sum.CSVSummariser#main(java.lang.String[])}. */ @Test public final void testSummariseInteger() throws Exception { StringWriter output = new StringWriter(); CSVSummariser.runSummarise(new StringReader("Test\n1"), output, NullWriter.NULL_WRITER, CSVSummariser.DEFAULT_SAMPLE_COUNT, false, false); }
/** * Test method for * {@link com.github.ansell.csv.sum.CSVSummariser#main(java.lang.String[])}. */ @Test public final void testSummariseDouble() throws Exception { StringWriter output = new StringWriter(); CSVSummariser.runSummarise(new StringReader("Test\n1.0"), output, NullWriter.NULL_WRITER, CSVSummariser.DEFAULT_SAMPLE_COUNT, false, false); }
/** * Test method for * {@link com.github.ansell.csv.sum.CSVSummariser#main(java.lang.String[])}. */ @Test public final void testSummariseAllSampleValues() throws Exception { StringWriter output = new StringWriter(); CSVSummariser.runSummarise(new StringReader("Test\n1.0"), output, NullWriter.NULL_WRITER, CSVSummariser.DEFAULT_SAMPLE_COUNT, false, false); }
/** * Test method for * {@link com.github.ansell.csv.sum.CSVSummariser#main(java.lang.String[])}. */ @Test public final void testSummariseAllSampleValuesLong() throws Exception { StringWriter output = new StringWriter(); StringBuilder input = new StringBuilder("Test\n"); IntStream.range(0, 1000).forEach(i -> input.append("N")); CSVSummariser.runSummarise(new StringReader(input.toString()), output, NullWriter.NULL_WRITER, -1, false, false); }
/** * Test method for * {@link com.github.ansell.csv.sum.CSVSummariser#main(java.lang.String[])}. */ @Test public final void testSummariseOverrideHeaders() throws Exception { StringWriter output = new StringWriter(); StringBuilder input = new StringBuilder("TestShouldNotBeSeen\nValue1"); CSVSummariser.runSummarise(new StringReader(input.toString()), output, NullWriter.NULL_WRITER, -1, false, false, Arrays.asList("TestHeader"), 1); assertTrue(output.toString().contains("TestHeader")); assertTrue(output.toString().contains("Value1")); assertFalse(output.toString().contains("TestShouldNotBeSeen")); }
/** * Test method for * {@link com.github.ansell.csv.sum.CSVSummariser#main(java.lang.String[])}. */ @Test public final void testSummariseNoSampleValuesLong() throws Exception { StringWriter output = new StringWriter(); StringBuilder input = new StringBuilder("Test\n"); IntStream.range(0, 1000).forEach(i -> input.append("N")); CSVSummariser.runSummarise(new StringReader(input.toString()), output, NullWriter.NULL_WRITER, 0, false, true); System.out.println(output.toString()); }
/** * Start the example application. * * @param args * command line arguments */ public static void main( String[] args ) { // init logging PropertyConfigurator.configure( IdxWritingExample.class.getResource( PACKAGE + "/log4j.properties" ) ); // create some CSV records List<IdxRecord> records = new ArrayList<>(); records.add( createRecord() ); records.add( createRecord() ); records.add( createRecord() ); records.add( createRecord() ); // write CSV records into a java.io.File try { write( records, File.createTempFile( "output-", ".csv" ) ); } catch (IOException ex) { LOGGER.error( "Can't create temporary file!" ); LOGGER.error( "> " + ex.getLocalizedMessage(), ex ); System.exit( 1 ); } // write CSV records into a java.io.OutputStream write( records, new NullOutputStream() ); // write CSV records into a java.io.Writer write( records, new NullWriter() ); // write CSV records into a string and send it to the console writeToConsole( records ); }
/** * Start the example application. * * @param args * command line arguments */ public static void main( String[] args ) { // init logging PropertyConfigurator.configure( Is24CsvWritingExample.class.getResource( PACKAGE + "/log4j.properties" ) ); // create some CSV records List<Is24CsvRecord> records = new ArrayList<>(); records.add( createHausKaufRecord() ); records.add( createHausKaufRecord() ); records.add( createWohnungMieteRecord() ); records.add( createWohnungMieteRecord() ); // write CSV records into a java.io.File try { write( records, File.createTempFile( "output-", ".csv" ) ); } catch (IOException ex) { LOGGER.error( "Can't create temporary file!" ); LOGGER.error( "> " + ex.getLocalizedMessage(), ex ); System.exit( 1 ); } // write CSV records into a java.io.OutputStream write( records, new NullOutputStream() ); // write CSV records into a java.io.Writer write( records, new NullWriter() ); // write CSV records into a string and send it to the console writeToConsole( records ); }
private static void forceEagerFetching(Object entity) { XStream xStream = XStreamUtils.instanciateXstreamForHibernate(); if (logger.isDebugEnabled()) { String xmlDump = xStream.toXML(entity); logger.debug("Xml dump:" + xmlDump); } else { // dump to equivalent of /dev/null xStream.toXML(entity, NullWriter.NULL_WRITER); } }
/** * Asserts that the content of the character buffer is never bigger than the newNumberOfChars plus the look-behind. * Additionally asserts that the capacity of the character buffer does not exceed twice the size of * newNumberOfChars. * * @param minimumLengthOfLookBehind * @param newNumberOfChars * @param numberOfCharactersToSkip * @param sizeOfInput * @param bufferSize * @throws Exception */ private void assertCharacterBufferDoesNotExceedRequestedLength(int minimumLengthOfLookBehind, int newNumberOfChars, int numberOfCharactersToSkip, int sizeOfInput, int bufferSize) throws Exception { // setup: create modifier and reader IdleModifier modifier = new IdleModifier(minimumLengthOfLookBehind, newNumberOfChars, numberOfCharactersToSkip); ModifyingWriter writer = new ModifyingWriter(new NullWriter(), modifier); Writer bufferedWriter = new BufferedWriter(writer, bufferSize); // read the stream into an output stream for (int index = 0; index < sizeOfInput; index++) { bufferedWriter.append('a'); } writer.flush(); writer.close(); assertTrue("max requested length of character buffer " + modifier.getFactory().getMaxRequestedNewNumberOfChars() + " should be smaller than " + newNumberOfChars + " but was not", modifier.getFactory().getMaxRequestedNewNumberOfChars() <= newNumberOfChars); assertTrue("max size of character buffer " + modifier.getMaxSizeOfCharacterBuffer() + " should be smaller than " + (minimumLengthOfLookBehind + newNumberOfChars) + " but was not", modifier.getMaxSizeOfCharacterBuffer() <= minimumLengthOfLookBehind + newNumberOfChars); // as we know that StringBuilder.ensureCapacity(int) doubles the input // size if appropriate, we test for (look-behind + numChars) * 2 assertTrue("max capacity of character buffer " + modifier.getMaxCapacityOfCharacterBuffer() + " should be smaller than " + (minimumLengthOfLookBehind + newNumberOfChars) * 2 + " but was not", modifier.getMaxCapacityOfCharacterBuffer() <= (minimumLengthOfLookBehind + newNumberOfChars) * 2); }
@Test public void testCloseUnderlyingWriter() throws Exception { // given NullWriter underlyingWriter = mock(NullWriter.class); ModifyingWriter writer = new ModifyingWriter(underlyingWriter, new IdleModifier()); // when writer.append("some text"); // then verify(underlyingWriter, never()).close(); // when writer.flush(); // then verify(underlyingWriter, never()).close(); // when writer.close(); // then verify(underlyingWriter).close(); // when writer.close(); // then // calling close() a second time must not have an effect // when try { writer.write("anything"); fail(IOException.class.getSimpleName() + " expected"); } catch (IOException e) { // then expect IOException } }
/** * Test Copying file > 2GB - see issue# IO-84 */ @Test(timeout = 1000) public void testCopy_readerToWriter_IO84_add1800() throws Exception { fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testCopy_readerToWriter_IO84_add1800"); long size = ((long)(Integer.MAX_VALUE)) + ((long)(1)); Reader reader = new NullReader(size); Writer writer = new NullWriter(); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5400,-1); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5402,null,5401,org.apache.commons.io.IOUtils.copy(reader, writer)); reader.close(); reader.close(); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5403,size); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5405,null,5404,org.apache.commons.io.IOUtils.copyLarge(reader, writer)); fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread()); }
/** * Test Copying file > 2GB - see issue# IO-84 */ public void testCopy_readerToWriter_IO84() throws Exception { fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testCopy_readerToWriter_IO84"); long size = ((long)(Integer.MAX_VALUE)) + ((long)(2)); Reader reader = new NullReader(size); Writer writer = new NullWriter(); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5400,-1); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5402,null,5401,org.apache.commons.io.IOUtils.copy(reader, writer)); reader.close(); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5403,size); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5405,null,5404,org.apache.commons.io.IOUtils.copyLarge(reader, writer)); fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread()); }
/** * Test Copying file > 2GB - see issue# IO-84 */ public void testCopy_readerToWriter_IO84_literalMutation6310() throws Exception { fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testCopy_readerToWriter_IO84_literalMutation6310"); long size = ((long)(Integer.MAX_VALUE)) + ((long)(0)); Reader reader = new NullReader(size); Writer writer = new NullWriter(); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5400,-1); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5402,null,5401,org.apache.commons.io.IOUtils.copy(reader, writer)); reader.close(); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5403,size); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5405,null,5404,org.apache.commons.io.IOUtils.copyLarge(reader, writer)); fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread()); }
/** * Test Copying file > 2GB - see issue# IO-84 */ public void testCopy_readerToWriter_IO84_literalMutation6311() throws Exception { fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testCopy_readerToWriter_IO84_literalMutation6311"); long size = ((long)(Integer.MAX_VALUE)) + ((long)(0)); Reader reader = new NullReader(size); Writer writer = new NullWriter(); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5400,-1); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5402,null,5401,org.apache.commons.io.IOUtils.copy(reader, writer)); reader.close(); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5403,size); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5405,null,5404,org.apache.commons.io.IOUtils.copyLarge(reader, writer)); fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread()); }
/** * Test Copying file > 2GB - see issue# IO-84 */ @Test(timeout = 1000) public void testCopy_readerToWriter_IO84_remove1357() throws Exception { fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testCopy_readerToWriter_IO84_remove1357"); long size = ((long)(Integer.MAX_VALUE)) + ((long)(1)); Reader reader = new NullReader(size); Writer writer = new NullWriter(); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5400,-1); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5402,null,5401,org.apache.commons.io.IOUtils.copy(reader, writer)); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5403,size); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5405,null,5404,org.apache.commons.io.IOUtils.copyLarge(reader, writer)); fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread()); }
/** * Evaluate the body of this tag, but do not write the results to any page. * @throws JspException If there is an error invoking the body. * @throws IOException If there is an error writing to the stream. */ public final void invokeBody() throws JspException, IOException { if (getJspBody() != null) { try (Writer writer = new NullWriter()) { getJspBody().invoke(writer); } } }
/** * Creates a reference FASTA file writer. * <p> * You can specify a specific output stream to each file: the main fasta output, its index and its dictionary. * </p> * * @param fastaOutput the output fasta file path. * @param indexOutput the output stream to the index file, if requested, {@code null} if none should be generated. * @param dictOutput the output stream to the dictFile, if requested, {@code null} if none should be generated. * @throws IllegalArgumentException if {@code fastaFile} is {@code null} or {@code basesPerLine} is 0 or negative. */ public FastaReferenceWriter(final OutputStream fastaOutput, final int basesPerLine, final OutputStream indexOutput, final OutputStream dictOutput) { this.defaultBasePerLine = checkBasesPerLine(basesPerLine); this.fastaStream = new CountingOutputStream(Utils.nonNull(fastaOutput)); this.indexWriter = indexOutput == null ? new NullWriter() : new OutputStreamWriter(indexOutput, CHARSET); final BufferedWriter dictWriter = new BufferedWriter(dictOutput == null ? new NullWriter() : new OutputStreamWriter(dictOutput, CHARSET)); this.dictWriter = dictWriter; this.dictCodec = new SAMSequenceDictionaryCodec(dictWriter); this.dictCodec.encodeHeaderLine(false); this.sequenceNamesAndSizes = new LinkedHashMap<>(); }
@Override public void registerSourceFiles(Collection<String> sourceFileNames) { log.info("Executing Javadoc tool..."); final String flatClasspath; if (_classpath == null) { flatClasspath = System.getProperty("java.class.path"); } else { flatClasspath = StringUtils.join(_classpath, ":"); } final PrintWriter sysoutWriter = new PrintWriter(System.out, true); final PrintWriter nullWriter = new PrintWriter(new NullWriter()); final List<String> javadocArgs = new ArrayList<String>(Arrays.asList("-classpath", flatClasspath, "-sourcepath", StringUtils.join(_sourcePaths, ":"))); if (_resourcePackages != null) { javadocArgs.add("-subpackages"); javadocArgs.add(StringUtils.join(_resourcePackages, ":")); } else { javadocArgs.addAll(sourceFileNames); } _docletId = Rest4JDoclet.generateJavadoc(_apiName, sysoutWriter, nullWriter, nullWriter, javadocArgs.toArray(new String[0])); }
@Test public void testMaintenance() throws UnsupportedEncodingException, IOException { final AppStatus appStatus = new AppStatus(); // Maintenance is on appStatus.setMaintenance(true); final StatusWebHandler statusWeb = new StatusWebHandler(); statusWeb.setAppStatus(appStatus); statusWeb.setApplicationName("test"); final Map<String, IPage> pages = new HashMap<String, IPage>(); final StatusPage page = new StatusPage(); pages.put(page.getId(), page); statusWeb.setPages(pages); statusWeb.init(); final HttpServletRequest servlet = mock(HttpServletRequest.class); final HttpServletRequest request = mock(HttpServletRequest.class); final HttpServletResponse response = mock(HttpServletResponse.class); final StubServletOutputStream sos = new StubServletOutputStream(); when(response.getWriter()).thenReturn(new PrintWriter(new NullWriter())); when(response.getOutputStream()).thenReturn(sos); page.doGet(statusWeb, request, response); verify(response).setStatus(503); }
/** * Test method for * {@link de.ppi.fuwesta.spring.mvc.util.RecursivePropertiesPersister#store(java.util.Properties, java.io.Writer, java.lang.String)} * . * * @throws Exception if something goes wrong. */ @Test public void testStorePropertiesWriterString() throws Exception { // Arrange final Properties props = new Properties(); final Writer os = new NullWriter(); final String header = "Test"; // Act testee.store(props, os, header); // Assert verify(propertiesPersister).store(props, os, header); }
@Test public void checkSvcsValues() { // active power should be equal to 0 assertTrue(StaticVarCompensatorsValidation.checkSVCs("test", p, q, v, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, strictConfig, NullWriter.NULL_WRITER)); p = -39.8f; assertFalse(StaticVarCompensatorsValidation.checkSVCs("test", p, q, v, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, strictConfig, NullWriter.NULL_WRITER)); p = -0.01f; assertTrue(StaticVarCompensatorsValidation.checkSVCs("test", p, q, v, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, strictConfig, NullWriter.NULL_WRITER)); // if regulationMode = OFF then reactive power should be equal to 0 regulationMode = RegulationMode.OFF; assertFalse(StaticVarCompensatorsValidation.checkSVCs("test", p, q, v, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, strictConfig, NullWriter.NULL_WRITER)); // if regulationMode = REACTIVE_POWER then reactive power should be equal to setpoint regulationMode = RegulationMode.REACTIVE_POWER; assertTrue(StaticVarCompensatorsValidation.checkSVCs("test", p, q, v, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, strictConfig, NullWriter.NULL_WRITER)); q = 3.7f; assertFalse(StaticVarCompensatorsValidation.checkSVCs("test", p, q, v, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, strictConfig, NullWriter.NULL_WRITER)); assertTrue(StaticVarCompensatorsValidation.checkSVCs("test", p, q, v, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, looseConfig, NullWriter.NULL_WRITER)); // check with NaN values assertFalse(StaticVarCompensatorsValidation.checkSVCs("test", p, q, v, Float.NaN, voltageSetpoint, regulationMode, bMin, bMax, strictConfig, NullWriter.NULL_WRITER)); strictConfig.setOkMissingValues(true); assertTrue(StaticVarCompensatorsValidation.checkSVCs("test", p, q, v, Float.NaN, voltageSetpoint, regulationMode, bMin, bMax, strictConfig, NullWriter.NULL_WRITER)); strictConfig.setOkMissingValues(false); // if regulationMode = VOLTAGE then either V at the connected bus is equal to voltageSetpoint regulationMode = RegulationMode.VOLTAGE; assertTrue(StaticVarCompensatorsValidation.checkSVCs("test", p, q, v, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, strictConfig, NullWriter.NULL_WRITER)); v = 400f; assertFalse(StaticVarCompensatorsValidation.checkSVCs("test", p, q, v, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, strictConfig, NullWriter.NULL_WRITER)); // check with NaN values v = 380f; assertFalse(StaticVarCompensatorsValidation.checkSVCs("test", p, q, v, reactivePowerSetpoint, voltageSetpoint, regulationMode, Float.NaN, bMax, strictConfig, NullWriter.NULL_WRITER)); assertFalse(StaticVarCompensatorsValidation.checkSVCs("test", p, q, v, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, Float.NaN, strictConfig, NullWriter.NULL_WRITER)); assertFalse(StaticVarCompensatorsValidation.checkSVCs("test", p, q, v, reactivePowerSetpoint, Float.NaN, regulationMode, bMin, bMax, strictConfig, NullWriter.NULL_WRITER)); strictConfig.setOkMissingValues(true); assertTrue(StaticVarCompensatorsValidation.checkSVCs("test", p, q, v, reactivePowerSetpoint, voltageSetpoint, regulationMode, Float.NaN, bMax, strictConfig, NullWriter.NULL_WRITER)); assertTrue(StaticVarCompensatorsValidation.checkSVCs("test", p, q, v, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, Float.NaN, strictConfig, NullWriter.NULL_WRITER)); assertTrue(StaticVarCompensatorsValidation.checkSVCs("test", p, q, v, reactivePowerSetpoint, Float.NaN, regulationMode, bMin, bMax, strictConfig, NullWriter.NULL_WRITER)); strictConfig.setOkMissingValues(false); // if regulationMode = VOLTAGE then either q is equal to bMin * V and V is lower than voltageSetpoint q = 3.6f; v = 360f; assertTrue(StaticVarCompensatorsValidation.checkSVCs("test", p, q, v, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, strictConfig, NullWriter.NULL_WRITER)); v = 340f; assertFalse(StaticVarCompensatorsValidation.checkSVCs("test", p, q, v, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, strictConfig, NullWriter.NULL_WRITER)); // if regulationMode = VOLTAGE then either q is equal to bMax * V and v is higher than voltageSetpoint q = -40f; v = 400f; assertTrue(StaticVarCompensatorsValidation.checkSVCs("test", p, q, v, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, strictConfig, NullWriter.NULL_WRITER)); v = 420f; assertFalse(StaticVarCompensatorsValidation.checkSVCs("test", p, q, v, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, strictConfig, NullWriter.NULL_WRITER)); // a validation error should be detected if there is both a voltage and a target but no p or q v = 380f; p = Float.NaN; q = Float.NaN; assertFalse(StaticVarCompensatorsValidation.checkSVCs("test", p, q, v, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, strictConfig, NullWriter.NULL_WRITER)); reactivePowerSetpoint = 0f; assertTrue(StaticVarCompensatorsValidation.checkSVCs("test", p, q, v, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, strictConfig, NullWriter.NULL_WRITER)); }