Pipe extends Observable { public synchronized Liquid putIn(Liquid liquid) { if (liquid.getAmount() > getMaxInput()) { throw new OverfullLiquidContainerException("To much liquid inserted into the pipe", getMaxInput(), liquid.getAmount()); } queue.addLast(liquid); setChanged(); if (queue.size() <= length) { notifyObservers(); return new Liquid(0, SimulationConstants.MIN_TEMPERATURE, new Color(0)); } else { Liquid ret = queue.removeFirst(); notifyObservers(); return ret; } } Pipe(float crosssection, int length, byte defaultThreshold); synchronized Liquid putIn(Liquid liquid); synchronized void setValveThreshold(byte threshold); byte getValveThreshold(); float getMaxInput(); synchronized void reset(); boolean isLiquidEntering();  }
@Test(expected = NullPointerException.class) public void testNull() { pipe.putIn(null); }
@Test public void testPutIn() { Liquid empty = new Liquid(0, SimulationConstants.MIN_TEMPERATURE, new Color(0)); Liquid l1 = new Liquid(pipe.getMaxInput() / 2, SimulationConstants.MIN_TEMPERATURE, new Color(0)); Liquid l2 = new Liquid(pipe.getMaxInput(), SimulationConstants.MAX_TEMPERATURE, new Color(2)); assertEquals(empty, pipe.putIn(l1)); assertEquals(empty, pipe.putIn(l2)); assertEquals(empty, pipe.putIn(l1)); assertEquals(empty, pipe.putIn(l1)); assertEquals(empty, pipe.putIn(l2)); assertEquals(l1, pipe.putIn(l2)); assertEquals(l2, pipe.putIn(l2)); assertEquals(l1, pipe.putIn(l2)); assertEquals(l1, pipe.putIn(l2)); }